xmake.lua 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. package("acl-dev")
  2. set_homepage("https://acl-dev.cn")
  3. set_description("C/C++ server and network library, including coroutine, redis client, http/https/websocket, mqtt, mysql/postgresql/sqlite client with C/C++ for Linux, Android, iOS, MacOS, Windows.")
  4. set_license("LGPL-3.0")
  5. add_urls("https://github.com/acl-dev/acl/archive/refs/tags/$(version).tar.gz",
  6. "https://github.com/acl-dev/acl.git")
  7. add_versions("v3.6.2", "888fd9b8fb19db4f8e7760a12a28f37f24ba0a2952bb0409b8380413a4b6506b")
  8. add_versions("v3.6.3", "4c1fe78cc3dbf2843aab440ca638464d1d1e490e81e904115b8f96a88a3b44de")
  9. add_patches(">=3.6.2", "patches/v3.6.2/build_install_only_static_or_shared.diff", "179136ceec3a54c9d8a60d92bc67d691271ffcf8214160224b0b9339a26cd0a1")
  10. add_patches(">=3.6.2", "patches/v3.6.2/export_unix.diff", "13376d9374de1b97ec25f709205f927a7157852075c2583e57615b617c45c62d")
  11. add_patches(">=3.6.2", "patches/v3.6.2/fix_android_install_path.diff", "19917bd1852af4ddecc27ef402ecf9806b89ec78d91e62c806ba00fc05f41e94")
  12. add_patches(">=3.6.2", "patches/v3.6.2/debundle_zlib.diff", "43043fb8fe84ef8f37a6a637e0447a849d38155e6d6ca20a9512c38023077a04")
  13. if is_plat("windows") then
  14. add_configs("vs", {description = "Use Visual Studio buildsystem (.sln/.vcxproj)", default = true, type = "boolean"})
  15. end
  16. add_includedirs("include", "include/acl-lib")
  17. add_deps("cmake")
  18. if not is_plat("windows") then
  19. add_links("protocol", "acl_cpp", "fiber_cpp", "fiber", "acl")
  20. end
  21. if not is_plat("windows") then
  22. add_deps("zlib")
  23. end
  24. if is_plat("iphoneos", "macosx", "bsd") then
  25. add_deps("libiconv")
  26. end
  27. if is_plat("windows") then
  28. add_syslinks("ws2_32", "iphlpapi", "kernel32", "user32", "gdi32")
  29. elseif is_plat("linux", "bsd", "cross") then
  30. add_syslinks("pthread", "dl")
  31. end
  32. on_load(function (package)
  33. if package:is_plat("iphoneos", "macosx", "bsd") then
  34. package:add("patches", ">=3.6.2", "patches/v3.6.2/debundle_iconv.diff", "03db2a366167c865eb6bcd73d06b5d87fa3ed87307aa86bc2d0de9528dd29e10")
  35. end
  36. if package:is_plat("android") then
  37. package:add("defines", "ANDROID")
  38. elseif package:is_plat("macosx") then
  39. package:add("defines", "MACOSX")
  40. elseif package:is_plat("linux", "cross") then
  41. package:add("defines", "LINUX2")
  42. elseif package:is_plat("bsd") then
  43. package:add("defines", "FREEBSD")
  44. end
  45. end)
  46. on_install("windows", "android", "iphoneos", "macosx", "linux", "cross", "bsd", function (package)
  47. if package:is_plat("windows") and package:config("vs") then
  48. import("package.tools.msbuild")
  49. for _, vcxproj in ipairs(os.files("**.vcxproj")) do
  50. -- Switch vs_runtime MD / MDd -> MT / MTd
  51. if package:has_runtime("MT", "MTd") then
  52. io.replace(vcxproj, "MultiThreadedDebugDLL", "MultiThreadedDebug", {plain = true})
  53. io.replace(vcxproj, "MultiThreadedDLL", "MultiThreaded", {plain = true})
  54. io.replace(vcxproj, "<IgnoreSpecificDefaultLibraries>libcmt;libc</IgnoreSpecificDefaultLibraries>", "", {plain = true})
  55. io.replace(vcxproj, "<IgnoreSpecificDefaultLibraries>libcmtd;libcmt;libc</IgnoreSpecificDefaultLibraries>", "", {plain = true})
  56. end
  57. -- Disble LTCG
  58. io.replace(vcxproj, "<WholeProgramOptimization>true</WholeProgramOptimization>", "<WholeProgramOptimization>false</WholeProgramOptimization>", {plain = true})
  59. end
  60. os.cp("lib_fiber/c/include/fiber/**", package:installdir("include/acl-lib/fiber"))
  61. os.cp("lib_protocol/include/**", package:installdir("include/acl-lib/protocol"))
  62. os.cp("lib_acl_cpp/include/acl_cpp/**", package:installdir("include/acl-lib/acl_cpp"))
  63. os.cp("lib_acl/include/**", package:installdir("include/acl-lib/acl"))
  64. os.cp("lib_fiber/cpp/include/fiber/**", package:installdir("include/acl-lib/fiber_cpp"))
  65. local arch = package:is_arch("x64") and "x64" or "Win32"
  66. if package:is_arch("arm64") then
  67. arch = "ARM64"
  68. end
  69. local mode = package:is_debug() and "Debug" or "Release"
  70. if package:config("shared") then
  71. mode = package:is_debug() and "DebugDll" or "ReleaseDll"
  72. end
  73. local configs = {"acl_cpp_vc2022.sln", "/t:lib_acl;libfiber;lib_protocol;lib_acl_cpp;libfiber_cpp"}
  74. table.insert(configs, "/p:Configuration=" .. mode)
  75. table.insert(configs, "/p:Platform=" .. arch)
  76. msbuild.build(package, configs)
  77. os.cp("**.lib", package:installdir("lib"))
  78. if package:config("shared") then
  79. for _, dll in ipairs(os.files("**.dll")) do
  80. if not dll:lower():find("71.dll") and not dll:lower():find("vld.dll") then
  81. os.cp(dll, package:installdir("bin"))
  82. end
  83. end
  84. end
  85. else
  86. -- Fix windows .pch file
  87. io.replace("lib_acl_cpp/CMakeLists.txt", [["-Ycacl_stdafx.hpp"]], [[]], {plain = true})
  88. io.replace("lib_acl_cpp/CMakeLists.txt", [[add_library(acl_cpp_static STATIC ${lib_src})]],
  89. "add_library(acl_cpp_static STATIC ${lib_src})\ntarget_precompile_headers(acl_cpp_static PRIVATE src/acl_stdafx.hpp)", {plain = true})
  90. io.replace("lib_acl_cpp/CMakeLists.txt", [[add_library(acl_cpp_shared SHARED ${lib_src})]],
  91. "add_library(acl_cpp_shared SHARED ${lib_src})\ntarget_precompile_headers(acl_cpp_shared PRIVATE src/acl_stdafx.hpp)", {plain = true})
  92. if package:is_plat("windows") then
  93. -- Do not build .gas on windows
  94. io.replace("lib_fiber/c/CMakeLists.txt", [[list(APPEND lib_src ${src}/fiber/boost/make_gas.S]], [[]], {plain = true})
  95. io.replace("lib_fiber/c/CMakeLists.txt", [[${src}/fiber/boost/jump_gas.S)]], [[]], {plain = true})
  96. else
  97. io.replace("CMakeLists.txt", "project(acl)", "project(acl)\nfind_package(ZLIB)", {plain = true})
  98. end
  99. if package:is_plat("iphoneos", "macosx", "bsd") then
  100. if package:is_plat("bsd") then
  101. -- FreeBSD enforce fallback to system iconv
  102. io.replace("lib_acl_cpp/CMakeLists.txt", [[elseif(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")]],
  103. [[elseif(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
  104. add_definitions("-DUSE_SYS_ICONV")]], {plain = true})
  105. end
  106. io.replace("CMakeLists.txt", "project(acl)", "project(acl)\nfind_package(Iconv)", {plain = true})
  107. end
  108. for _, file in ipairs(os.files("**.txt")) do
  109. -- Disable -Wstrict-prototypes -Werror -Qunused-arguments
  110. io.replace(file, [["-Wstrict-prototypes"]], "", {plain = true})
  111. io.replace(file, [["-Werror"]], "", {plain = true})
  112. io.replace(file, [[-Qunused-arguments]], [[]], {plain = true})
  113. -- Do not enforce LTO
  114. io.replace(file, [[add_definitions("-flto")]], [[]], {plain = true})
  115. io.replace(file, [[-flto]], [[]], {plain = true})
  116. if package:is_plat("windows") then
  117. -- Cleanup ZLIB after patch for Windows OS
  118. io.replace(file, [[ZLIB::ZLIB]], [[]], {plain = true})
  119. end
  120. end
  121. local configs = {"-DCMAKE_POLICY_DEFAULT_CMP0057=NEW"}
  122. if package:is_plat("iphoneos") then
  123. table.insert(configs, "-DCMAKE_SYSTEM_NAME=Darwin")
  124. end
  125. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "DEBUG" or "RELEASE"))
  126. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  127. table.insert(configs, "-DACL_BUILD_SHARED=" .. (package:config("shared") and "YES" or "NO"))
  128. import("package.tools.cmake").install(package, configs)
  129. if package:is_plat("windows") then
  130. if package:config("shared") then
  131. os.vcp(path.join(package:buildir(), "*/shared/**.lib"), package:installdir("lib"))
  132. os.vcp(path.join(package:buildir(), "*/shared/**.dll"), package:installdir("bin"))
  133. else
  134. os.vcp(path.join(package:buildir(), "*/static/**.lib"), package:installdir("lib"))
  135. end
  136. end
  137. end
  138. end)
  139. on_test(function (package)
  140. assert(package:has_cfuncs("acl_fiber_recv", {includes = "fiber/lib_fiber.h"}))
  141. assert(package:check_cxxsnippets({test = [[
  142. void test() {
  143. const char* redis_addr = "127.0.0.1:7000";
  144. int max_conns = 100;
  145. acl::redis_client_cluster cluster;
  146. cluster.set(redis_addr, max_conns);
  147. }
  148. ]]}, {includes = "acl_cpp/lib_acl.hpp"}))
  149. end)