xmake.lua 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. package("ace")
  2. set_homepage("https://www.dre.vanderbilt.edu/~schmidt/ACE.html")
  3. set_description("ACE (ADAPTIVE Communication Environment) is a C++ framework for implementing distributed and networked applications.")
  4. set_license("DOC")
  5. add_urls("https://github.com/DOCGroup/ACE_TAO/releases/download/$(version).tar.gz", {version = function (version)
  6. return "ACE%2BTAO-" .. version:gsub("%.", "_") .. "/ACE-" .. version
  7. end})
  8. add_versions("8.0.3", "d8fcd1f5fab609ab11ed86abdbd61e6d00d5305830fa6e57c17ce395af5e86dc")
  9. if not is_plat("windows") then
  10. add_configs("ssl", {description = "Build with OpenSSL support.", default = true, type = "boolean"})
  11. end
  12. on_load(function (package)
  13. package:add("defines", "ACE_HAS_CPP17")
  14. if package:is_plat("windows") then
  15. package:add("syslinks", "iphlpapi", "user32", "advapi32")
  16. package:add("defines", "WIN32")
  17. else
  18. if not package:is_plat("android") then
  19. package:add("deps", "autotools")
  20. end
  21. if package:is_plat("linux", "bsd") then
  22. package:add("syslinks", "pthread")
  23. end
  24. end
  25. if not package:is_plat("windows") and package:config("ssl") then
  26. package:add("deps", "openssl")
  27. end
  28. if not package:config("shared") then
  29. package:add("defines", "ACE_AS_STATIC_LIBS")
  30. end
  31. end)
  32. on_install("linux", "macosx", "bsd", "iphoneos", "android", function(package)
  33. import("package.tools.make")
  34. local envs = make.buildenvs(package)
  35. if package:is_plat("linux") then
  36. io.writefile("ace/config.h", [[#include "ace/config-linux.h"]])
  37. io.writefile("include/makeinclude/platform_macros.GNU", [[include $(ACE_ROOT)/include/makeinclude/platform_linux_common.GNU]])
  38. elseif package:is_plat("macosx") then
  39. io.writefile("ace/config.h", [[#include "ace/config-macosx.h"]])
  40. io.writefile("include/makeinclude/platform_macros.GNU", [[include $(ACE_ROOT)/include/makeinclude/platform_macosx.GNU]])
  41. elseif package:is_plat("bsd") then
  42. io.writefile("ace/config.h", [[#include "ace/config-freebsd.h"]])
  43. io.writefile("include/makeinclude/platform_macros.GNU", [[include $(ACE_ROOT)/include/makeinclude/platform_freebsd.GNU]])
  44. elseif package:is_plat("iphoneos") then
  45. io.writefile("ace/config.h", [[#include "ace/config-macosx-iOS.h"]])
  46. io.writefile("include/makeinclude/platform_macros.GNU", [[include $(ACE_ROOT)/include/makeinclude/platform_macosx_iOS.GNU]])
  47. envs.IPHONE_TARGET = "HARDWARE"
  48. io.replace("include/makeinclude/platform_macosx_iOS.GNU", "CCFLAGS += -DACE_HAS_IOS", "CCFLAGS += -DACE_HAS_IOS -std=c++17", {plain = true})
  49. else
  50. import("core.tool.toolchain")
  51. io.writefile("ace/config.h", [[#include "ace/config-android.h"]])
  52. io.writefile("include/makeinclude/platform_macros.GNU", [[include $(ACE_ROOT)/include/makeinclude/platform_android.GNU]])
  53. local ndk = toolchain.load("ndk", {plat = package:plat(), arch = package:arch()})
  54. local ndk_sdkver = ndk:config("ndk_sdkver")
  55. local ndk_dir = ndk:config("ndk")
  56. envs.android_abi = package:arch()
  57. envs.android_ndk = path.unix(ndk_dir)
  58. envs.android_api = ndk_sdkver
  59. envs.ARFLAGS = [[rc]]
  60. io.replace("include/makeinclude/platform_android.GNU", "OCCFLAGS ?= -O3", "OCCFLAGS ?= -O3\nCCFLAGS += -std=c++17", {plain = true})
  61. end
  62. os.cp("ace/**.h", package:installdir("include/ace"), {rootdir = "ace"})
  63. os.cp("ace/**.inl", package:installdir("include/ace"), {rootdir = "ace"})
  64. os.cp("ace/**.cpp", package:installdir("include/ace"), {rootdir = "ace"})
  65. os.cp("ace/**.tpp", package:installdir("include/ace"), {rootdir = "ace"})
  66. os.cp("ace/**.ipp", package:installdir("include/ace"), {rootdir = "ace"})
  67. os.cp("ace/**.hpp", package:installdir("include/ace"), {rootdir = "ace"})
  68. envs.ACE_ROOT = os.curdir()
  69. local configs = {
  70. "debug=" .. (package:is_debug() and "1" or "0"),
  71. "shared_libs=" .. (package:config("shared") and "1" or "0"),
  72. "static_libs=" .. (package:config("shared") and "0" or "1"),
  73. "ssl=" .. (package:config("ssl") and "1" or "0"),
  74. "threads=1"
  75. }
  76. if package:config("ssl") then
  77. envs.SSL_ROOT = package:dep("openssl"):installdir()
  78. envs.SSL_INCDIR = package:dep("openssl"):installdir("include")
  79. envs.SSL_LIBDIR = package:dep("openssl"):installdir("lib")
  80. end
  81. os.cd("ace")
  82. make.build(package, configs, {envs = envs})
  83. os.trycp("**.dylib", package:installdir("lib"))
  84. os.trycp("**.so", package:installdir("lib"))
  85. os.trycp("**.a", package:installdir("lib"))
  86. end)
  87. on_install("windows", function(package)
  88. import("package.tools.msbuild")
  89. io.writefile("ace/config.h", [[#include "ace/config-win32.h"]])
  90. os.cp("ace/**.h", package:installdir("include/ace"), {rootdir = "ace"})
  91. os.cp("ace/**.inl", package:installdir("include/ace"), {rootdir = "ace"})
  92. os.cp("ace/**.cpp", package:installdir("include/ace"), {rootdir = "ace"})
  93. os.cp("ace/**.tpp", package:installdir("include/ace"), {rootdir = "ace"})
  94. os.cp("ace/**.ipp", package:installdir("include/ace"), {rootdir = "ace"})
  95. os.cp("ace/**.hpp", package:installdir("include/ace"), {rootdir = "ace"})
  96. os.cd("ace")
  97. for _, vcxproj in ipairs({"ACE_vs2022.vcxproj",
  98. "Compression/ACE_Compression_vs2022.vcxproj",
  99. "Compression/rle/ACE_RLECompression_vs2022.vcxproj",
  100. "ETCL/ACE_ETCL_vs2022.vcxproj",
  101. "ETCL/ACE_ETCL_Parser_vs2022.vcxproj",
  102. "QoS/QoS_vs2022.vcxproj",
  103. "Monitor_Control/Monitor_Control_vs2022.vcxproj"}) do
  104. if package:has_runtime("MT", "MTd") then
  105. -- Allow MT, MTd
  106. io.replace(vcxproj, "<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>", "<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>", {plain = true})
  107. io.replace(vcxproj, "<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>", "<RuntimeLibrary>MultiThreaded</RuntimeLibrary>", {plain = true})
  108. end
  109. if not package:config("shared") then
  110. io.replace(vcxproj, "DynamicLibrary", "StaticLibrary", {plain = true})
  111. io.replace(vcxproj, "ACE_BUILD_DLL", "ACE_AS_STATIC_LIBS", {plain = true})
  112. io.replace(vcxproj, "ACE_[%w_]+_BUILD_DLL", "ACE_AS_STATIC_LIBS", {plain = false})
  113. io.replace(vcxproj, "[%w_]+_[%w_]+_BUILD_DLL", "ACE_AS_STATIC_LIBS", {plain = false})
  114. end
  115. -- Allow use another Win SDK
  116. io.replace(vcxproj, "<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>", "", {plain = true})
  117. -- Disable LTCG
  118. io.replace(vcxproj, "<WholeProgramOptimization>true</WholeProgramOptimization>", "", {plain = true})
  119. end
  120. local configs = { "ACE_vs2022.sln" }
  121. local arch = package:is_arch("x64") and "x64" or "Win32"
  122. if package:is_arch("arm64") then
  123. arch = "ARM64"
  124. end
  125. local mode = package:is_debug() and "Debug" or "Release"
  126. table.insert(configs, "/p:Configuration=" .. mode)
  127. table.insert(configs, "/p:Platform=" .. arch)
  128. -- Wrap vstool so it would build for another vstools
  129. local msvc = import("core.tool.toolchain").load("msvc")
  130. local vs = msvc:config("vs")
  131. local vstool
  132. if vs == "2015" then vstool = "v140"
  133. elseif vs == "2017" then vstool = "v141"
  134. elseif vs == "2019" then vstool = "v142"
  135. elseif vs == "2022" then vstool = "v143"
  136. end
  137. table.insert(configs, "/p:PlatformToolset=" .. vstool)
  138. msbuild.build(package, configs)
  139. os.cd("..")
  140. os.cp("**.lib", package:installdir("lib"))
  141. if package:config("shared") then
  142. os.cp("**.dll", package:installdir("bin"))
  143. end
  144. end)
  145. on_test(function (package)
  146. if package:is_plat("windows") then
  147. assert(package:check_cxxsnippets({test = [[
  148. #define WIN32_LEAN_AND_MEAN
  149. #include <windows.h>
  150. #include <ace/ACE.h>
  151. void test() {
  152. auto c_name = ACE::compiler_name();
  153. }
  154. ]]
  155. }, {configs = {languages = "c++17"}}))
  156. else
  157. assert(package:check_cxxsnippets({test = [[
  158. #include <ace/ACE.h>
  159. void test() {
  160. auto c_name = ACE::compiler_name();
  161. }
  162. ]]
  163. }, {configs = {languages = "c++17"}}))
  164. end
  165. end)