xmake.lua 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. package("aui")
  2. set_homepage("https://github.com/aui-framework/aui")
  3. set_description("Declarative UI toolkit for modern C++20")
  4. set_license("MPL-2.0")
  5. add_urls("https://github.com/aui-framework/aui/archive/refs/tags/$(version).tar.gz",
  6. "https://github.com/aui-framework/aui.git")
  7. add_versions("v7.1.2", "a4cf965c50d75e20a319c9c8b231ad9c13c25a06ad303e1eb65d1ff141b1f85c")
  8. add_patches("v7.1.2", "patches/v7.1.2/debundle-audio.diff", "a51f9b89b0ec4895b6d1f10c1259e0c620c8a0480817598de977210c0ad78e46")
  9. add_patches("v7.1.2", "patches/v7.1.2/debundle-build.diff", "391d389da336dc24ddb37432ad85bcf9de3b956742157628e741a500733151cd")
  10. add_patches("v7.1.2", "patches/v7.1.2/debundle-core.diff", "2ab1e7181d07b64bb059b8b7fdff69c295df84043560ecb337516c649ac28bbe")
  11. add_patches("v7.1.2", "patches/v7.1.2/debundle-crypt.diff", "58045d168a8c7f2658554e0a3010579ec53b54e2c51f524a4fb61e5e4d6fc0a7")
  12. add_patches("v7.1.2", "patches/v7.1.2/debundle-curl.diff", "937280a828ce0bc30a590606e7d65de55c9421d0650897c2d775e3731405a4b0")
  13. add_patches("v7.1.2", "patches/v7.1.2/debundle-image.diff", "44bb7e78eab9629c92ef953ec1e0aca9e80712fe2488d6ffa804924d418ebf05")
  14. add_patches("v7.1.2", "patches/v7.1.2/debundle-json-network.diff", "6d7d8da64cf85212e14757f7d24ac5ac6501dfd0ff3a4fcbe973c7c58c4f213c")
  15. add_patches("v7.1.2", "patches/v7.1.2/debundle-main.diff", "c1cac9dfbae14baaddb68837055a7a858c08786750a16cbbfe955a1f18e5878d")
  16. add_patches("v7.1.2", "patches/v7.1.2/debundle-sqlite.diff", "1728a4b9afc473acc81b16c544239e6f70a147c0623d894d59dd124e27c94311")
  17. add_patches("v7.1.2", "patches/v7.1.2/debundle-toolbox.diff", "1ec1abf993eb7e583d32602e1ae8ee4d3358d156e9fac185c0d19ed85660bd3b")
  18. add_patches("v7.1.2", "patches/v7.1.2/debundle-uitests.diff", "b7ad0900fbe2d8b50698f3439fe2fe6c182c925e94d72420ebb5104ba0f2f633")
  19. add_patches("v7.1.2", "patches/v7.1.2/debundle-views.diff", "d889bbbd1808f12937219e5ca40b835cb972e6d764d021e4ec5444132a68a8a3")
  20. add_patches("v7.1.2", "patches/v7.1.2/fix-backport-lunasvg.diff", "daf24391b88e44bdb801b2c1ba36a695f95384d8157ccb23cfc635d5f30bea4a")
  21. add_patches("v7.1.2", "patches/v7.1.2/fix-msvc-pretty-function.diff", "268f66f42594f0188fe50d33f5783e66f66024087097ebfdfef60c9768e151fd")
  22. add_patches("v7.1.2", "patches/v7.1.2/fix-osx-enforce-cpp-template.diff", "599e1e9ec9beec581258db67af8c9fe9dd2351eb169a538890c65422b5052659")
  23. add_patches("v7.1.2", "patches/v7.1.2/fixup-network.diff", "888c1ed0e96f21bd842de72f8f9fe933261c5f76c99be55cf8e83f424bd1f79e")
  24. add_patches("v7.1.2", "patches/v7.1.2/fix-glm.diff", "9b0f2e3000ea2cea92d3e3641a9db74274bc746e13ddacf6ffeddebb229e1c6d")
  25. add_deps("cmake")
  26. if is_subhost("windows") then
  27. add_deps("pkgconf")
  28. else
  29. add_deps("pkg-config")
  30. end
  31. add_deps("zlib")
  32. add_links(
  33. "aui.uitests",
  34. "aui.audio",
  35. "aui.json",
  36. "aui.views",
  37. "aui.xml",
  38. "aui.image",
  39. "aui.curl",
  40. "aui.crypt",
  41. "aui.network",
  42. "aui.core"
  43. )
  44. on_check(function (package)
  45. if package:is_cross() then
  46. raise("package(aui): does not support cross-compilation now.")
  47. end
  48. end)
  49. -- aui.audio
  50. on_component("audio", function (package, component)
  51. package:add("includedirs", "aui.audio/include")
  52. component:add("links", "aui.audio")
  53. package:add("deps", "libopus", "soxr")
  54. if package:is_plat("linux") then
  55. package:add("deps", "pulseaudio")
  56. elseif package:is_plat("android") then
  57. package:add("deps", "oboe")
  58. elseif package:is_plat("windows", "mingw") then
  59. component:add("syslinks", "winmm", "dsound", "dxguid")
  60. elseif package:is_plat("macosx", "iphoneos") then
  61. component:add("frameworks", "CoreAudio", "AVFoundation", "AudioToolbox")
  62. if package:is_plat("macosx") then
  63. component:add("frameworks", "AppKit", "Cocoa", "CoreData", "Foundation", "QuartzCore")
  64. end
  65. end
  66. end)
  67. -- aui.core
  68. on_component("core", function (package, component)
  69. package:add("includedirs", "aui.core/include")
  70. component:add("links", "aui.core")
  71. package:add("deps", "fmt 9.1.0", "range-v3", "glm")
  72. if package:is_plat("linux") then
  73. package:add("deps", "libbacktrace")
  74. component:add("syslinks", "pthread", "dl")
  75. elseif package:is_plat("windows", "mingw") then
  76. component:add("syslinks", "dbghelp", "shell32", "shlwapi", "kernel32", "psapi")
  77. elseif package:is_plat("android") then
  78. component:add("syslinks", "log")
  79. end
  80. end)
  81. -- aui.crypt
  82. on_component("crypt", function (package, component)
  83. package:add("includedirs", "aui.crypt/include")
  84. component:add("links", "aui.crypt")
  85. package:add("deps", "openssl3")
  86. if package:is_plat("windows", "mingw") then
  87. component:add("syslinks", "wsock32", "ws2_32")
  88. end
  89. end)
  90. -- aui.curl
  91. on_component("curl", function (package, component)
  92. package:add("includedirs", "aui.curl/include")
  93. component:add("links", "aui.curl")
  94. package:add("deps", "libcurl")
  95. end)
  96. -- aui.image
  97. on_component("image", function (package, component)
  98. package:add("includedirs", "aui.image/include")
  99. component:add("links", "aui.image")
  100. package:add("deps", "lunasvg", "libwebp")
  101. end)
  102. -- aui.json
  103. on_component("json", function (package, component)
  104. package:add("includedirs", "aui.json/include")
  105. component:add("links", "aui.json")
  106. end)
  107. -- aui.network
  108. on_component("network", function (package, component)
  109. package:add("includedirs", "aui.network/include")
  110. component:add("links", "aui.network")
  111. if package:is_plat("windows", "mingw") then
  112. component:add("syslinks", "wsock32", "ws2_32", "iphlpapi")
  113. end
  114. end)
  115. -- aui.toolbox
  116. on_component("toolbox", function (package, component)
  117. package:add("includedirs", "aui.toolbox/include")
  118. end)
  119. -- aui.uitests
  120. on_component("uitests", function (package, component)
  121. package:add("includedirs", "aui.uitests/include")
  122. component:add("links", "aui.uitests")
  123. package:add("deps", "gtest", "benchmark")
  124. end)
  125. -- aui.views
  126. on_component("views", function (package, component)
  127. package:add("includedirs", "aui.views/include")
  128. component:add("links", "aui.views")
  129. package:add("deps", "freetype")
  130. if package:is_plat("windows", "mingw", "linux", "macosx") then
  131. package:add("deps", "glew")
  132. end
  133. if package:is_plat("linux") then
  134. package:add("deps", "libx11", "dbus", "gtk3", "fontconfig")
  135. end
  136. if package:is_plat("windows", "mingw") then
  137. component:add("syslinks", "dwmapi", "winmm", "shlwapi", "gdi32", "ole32", "opengl32")
  138. if package:is_plat("mingw") then
  139. component:add("syslinks", "uuid")
  140. end
  141. elseif package:is_plat("android") then
  142. component:add("syslinks", "EGL", "GLESv2", "GLESv3")
  143. elseif package:is_plat("iphoneos") then
  144. component:add("frameworks", "OpenGLES")
  145. elseif package:is_plat("macosx") then
  146. component:add("frameworks", "AppKit", "Cocoa", "CoreData", "Foundation", "QuartzCore", "UniformTypeIdentifiers", "OpenGL")
  147. end
  148. end)
  149. -- aui.xml
  150. on_component("xml", function (package, component)
  151. package:add("includedirs", "aui.xml/include")
  152. component:add("links", "aui.xml")
  153. end)
  154. on_load(function (package)
  155. package:add("components", "audio", "core", "crypt", "curl", "image", "json", "network", "toolbox", "uitests", "views", "xml")
  156. if not package:config("shared") then
  157. package:add("defines", "AUI_STATIC")
  158. end
  159. package:add("defines", "AUI_DEBUG=" .. (package:is_debug() and "1" or "0"))
  160. package:add("defines",
  161. "API_AUI_AUDIO=AUI_IMPORT",
  162. "API_AUI_CORE=AUI_IMPORT",
  163. "API_AUI_CRYPT=AUI_IMPORT",
  164. "API_AUI_CURL=AUI_IMPORT",
  165. "API_AUI_DATA=AUI_IMPORT",
  166. "API_AUI_IMAGE=AUI_IMPORT",
  167. "API_AUI_JSON=AUI_IMPORT",
  168. "API_AUI_NETWORK=AUI_IMPORT",
  169. "API_AUI_UITESTS=AUI_IMPORT",
  170. "API_AUI_UPDATER=AUI_IMPORT",
  171. "API_AUI_VIEWS=AUI_IMPORT",
  172. "API_AUI_XML=AUI_IMPORT"
  173. )
  174. ----------------------------------------------------------------
  175. -- helper
  176. ----------------------------------------------------------------
  177. function add_flags(pkg, flags, names)
  178. local defs = {}
  179. for _, name in ipairs(names) do
  180. local val = flags[name] or 0
  181. defs[#defs+1] = string.format("%s=%d", name, val)
  182. end
  183. pkg:add("defines", table.unpack(defs))
  184. end
  185. ----------------------------------------------------------------
  186. -- platform
  187. ----------------------------------------------------------------
  188. local platform_names = {
  189. "AUI_PLATFORM_WIN",
  190. "AUI_PLATFORM_LINUX",
  191. "AUI_PLATFORM_APPLE",
  192. "AUI_PLATFORM_MACOS",
  193. "AUI_PLATFORM_IOS",
  194. "AUI_PLATFORM_ANDROID",
  195. "AUI_PLATFORM_UNIX",
  196. "AUI_PLATFORM_EMSCRIPTEN"
  197. }
  198. local platform_map = {
  199. windows = { AUI_PLATFORM_WIN = 1 },
  200. linux = { AUI_PLATFORM_LINUX = 1, AUI_PLATFORM_UNIX = 1 },
  201. macosx = { AUI_PLATFORM_APPLE = 1, AUI_PLATFORM_MACOS = 1, AUI_PLATFORM_UNIX = 1 },
  202. android = { AUI_PLATFORM_ANDROID = 1, AUI_PLATFORM_UNIX = 1 },
  203. iphoneos = { AUI_PLATFORM_APPLE = 1, AUI_PLATFORM_IOS = 1, AUI_PLATFORM_UNIX = 1 },
  204. wasm = { AUI_PLATFORM_EMSCRIPTEN = 1 },
  205. }
  206. for key, flags in pairs(platform_map) do
  207. local plats = (key == "windows") and {"windows", "mingw"} or {key}
  208. if package:is_plat(table.unpack(plats)) then
  209. add_flags(package, flags, platform_names)
  210. break
  211. end
  212. end
  213. ----------------------------------------------------------------
  214. -- compiler
  215. ----------------------------------------------------------------
  216. local compiler_names = {
  217. "AUI_COMPILER_CLANG",
  218. "AUI_COMPILER_GCC",
  219. "AUI_COMPILER_MSVC",
  220. }
  221. local compiler_map = {
  222. clang = { tools = {"clang", "clangxx", "clang++"}, flags = { AUI_COMPILER_CLANG = 1 } },
  223. gcc = { tools = {"gcc", "gxx", "g++" }, flags = { AUI_COMPILER_GCC = 1 } },
  224. msvc = { tools = {"cl", "clang-cl" }, flags = { AUI_COMPILER_MSVC = 1 } },
  225. }
  226. for _, info in pairs(compiler_map) do
  227. if package:has_tool("cxx", table.unpack(info.tools)) then
  228. add_flags(package, info.flags, compiler_names)
  229. break
  230. end
  231. end
  232. ----------------------------------------------------------------
  233. -- architecture
  234. ----------------------------------------------------------------
  235. local arch_names = {
  236. "AUI_ARCH_X86",
  237. "AUI_ARCH_X86_64",
  238. "AUI_ARCH_ARM_64",
  239. "AUI_ARCH_ARM_V7"
  240. }
  241. local ptrsize = package:check_sizeof("void*")
  242. local arch_flags
  243. if package:is_arch("arm.*") then
  244. arch_flags = (ptrsize == "4")
  245. and {AUI_ARCH_ARM_V7 = 1}
  246. or {AUI_ARCH_ARM_64 = 1}
  247. else
  248. arch_flags = (ptrsize == "4")
  249. and {AUI_ARCH_X86 = 1}
  250. or {AUI_ARCH_X86_64 = 1}
  251. end
  252. add_flags(package, arch_flags, arch_names)
  253. package:add("defines", "GLM_ENABLE_EXPERIMENTAL=1")
  254. end)
  255. on_install("windows", "macosx", "linux", function (package)
  256. local configs = {
  257. "-DAUI_INSTALL_RUNTIME_DEPENDENCIES=OFF",
  258. "-DAUIB_NO_PRECOMPILED=TRUE",
  259. "-DAUIB_DISABLE=ON",
  260. }
  261. local opt = {}
  262. if package:is_plat("windows", "mingw") then
  263. if package:has_tool("cxx", "cl", "clang_cl") then
  264. opt.cxflags = {"/EHsc"}
  265. end
  266. if package:targetarch():startswith("arm") then
  267. io.replace("cmake/aui.build.cmake", [[if (CMAKE_GENERATOR_PLATFORM MATCHES "(arm64)|(ARM64)" OR CMAKE_SYSTEM_PROCESSOR MATCHES "(aarch64|arm64)")]], [[if (1)]], {plain = true})
  268. end
  269. end
  270. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
  271. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  272. import("package.tools.cmake").install(package, configs, opt)
  273. end)
  274. on_test(function (package)
  275. assert(package:check_cxxsnippets({test = [[
  276. #include <AUI/Platform/AWindow.h>
  277. #include <AUI/Util/UIBuildingHelpers.h>
  278. #include <AUI/View/ALabel.h>
  279. #include <AUI/View/AButton.h>
  280. #include <AUI/Platform/APlatform.h>
  281. #include <AUI/Platform/Entry.h>
  282. using namespace declarative;
  283. class MainWindow: public AWindow {
  284. public:
  285. MainWindow();
  286. };
  287. MainWindow::MainWindow(): AWindow("Project template app", 300_dp, 200_dp) {
  288. setContents(
  289. Centered{
  290. Vertical{
  291. Centered { Label { "Hello world from AUI!" } },
  292. _new<AButton>("Visit GitHub repo").connect(&AView::clicked, this, [] {
  293. APlatform::openUrl("https://github.com/aui-framework/aui");
  294. }),
  295. _new<AButton>("Visit docs").connect(&AView::clicked, this, [] {
  296. APlatform::openUrl("https://aui-framework.github.io/");
  297. }),
  298. _new<AButton>("Submit an issue").connect(&AView::clicked, this, [] {
  299. APlatform::openUrl("https://github.com/aui-framework/aui/issues/new");
  300. }),
  301. }
  302. }
  303. );
  304. }
  305. void test() {
  306. _new<MainWindow>()->show();
  307. }
  308. ]]}, {configs = {languages = "c++20"}}))
  309. end)