xmake.lua 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. package("kokyu")
  2. set_homepage("https://www.dre.vanderbilt.edu/~schmidt/ACE.html")
  3. set_description("Kokyu - portable middleware scheduling framework designed to provide flexible scheduling/dispatching services within the context of higher-level middleware.")
  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 is_plat("linux", "bsd") then
  10. add_deps("ace", {configs = {shared = true}})
  11. else
  12. add_deps("ace")
  13. end
  14. on_load(function (package)
  15. package:add("defines", "ACE_HAS_CPP17")
  16. if package:is_plat("windows") then
  17. package:add("syslinks", "iphlpapi")
  18. end
  19. if package:config("shared") then
  20. package:add("defines", "KOKYU_HAS_DLL", "KOKYU_BUILD_DLL")
  21. else
  22. package:add("defines", "ACE_AS_STATIC_LIBS")
  23. end
  24. end)
  25. on_install("linux", "macosx", "iphoneos", function(package)
  26. import("package.tools.make")
  27. local envs = make.buildenvs(package)
  28. if package:is_plat("linux") then
  29. io.writefile("ace/config.h", [[#include "ace/config-linux.h"]])
  30. io.writefile("include/makeinclude/platform_macros.GNU", [[include $(ACE_ROOT)/include/makeinclude/platform_linux_common.GNU]])
  31. elseif package:is_plat("macosx") then
  32. io.writefile("ace/config.h", [[#include "ace/config-macosx.h"]])
  33. io.writefile("include/makeinclude/platform_macros.GNU", [[include $(ACE_ROOT)/include/makeinclude/platform_macosx.GNU]])
  34. elseif package:is_plat("iphoneos") then
  35. io.writefile("ace/config.h", [[#include "ace/config-macosx-iOS.h"]])
  36. io.writefile("include/makeinclude/platform_macros.GNU", [[include $(ACE_ROOT)/include/makeinclude/platform_macosx_iOS.GNU]])
  37. envs.IPHONE_TARGET = "HARDWARE"
  38. io.replace("include/makeinclude/platform_macosx_iOS.GNU", "CCFLAGS += -DACE_HAS_IOS", "CCFLAGS += -DACE_HAS_IOS -std=c++17", {plain = true})
  39. end
  40. os.rm("Kokyu/tests")
  41. os.cp("Kokyu/**.h", package:installdir("include/Kokyu"), {rootdir = "Kokyu"})
  42. os.cp("Kokyu/**.cpp", package:installdir("include/Kokyu"), {rootdir = "Kokyu"})
  43. os.cp("Kokyu/**.inl", package:installdir("include/Kokyu"), {rootdir = "Kokyu"})
  44. envs.LIBCHECK = "1"
  45. envs.ACE_ROOT = path.unix(os.curdir())
  46. envs.INSTALL_PREFIX = package:installdir()
  47. local ace_libdir
  48. local lib_paths = {}
  49. local packagedep = package:dep("ace")
  50. if packagedep then
  51. local fetchinfo = packagedep:fetch()
  52. if fetchinfo then
  53. for _, linkdir in ipairs(fetchinfo.linkdirs) do
  54. table.insert(lib_paths, linkdir)
  55. end
  56. end
  57. end
  58. ace_libdir = table.concat(lib_paths, " -L")
  59. ace_libdir = "-L" .. ace_libdir
  60. envs.debug = (package:is_debug() and "1" or "0")
  61. envs.shared_libs = (package:config("shared") and "1" or "0")
  62. envs.static_libs = (package:config("shared") and "0" or "1")
  63. os.cd("Kokyu")
  64. io.replace("GNUmakefile.Kokyu", [[-L../lib]], ace_libdir, {plain = true})
  65. io.replace("GNUmakefile", "Kokyu %$%(%@%).-FIFO %$%(%@%)", "Kokyu $(@)", {plain = false})
  66. make.build(package, {"Kokyu"}, {envs = envs})
  67. os.trycp("**.dylib", package:installdir("lib"))
  68. os.trycp("**.so", package:installdir("lib"))
  69. os.trycp("**.a", package:installdir("lib"))
  70. end)
  71. on_install("windows", function(package)
  72. import("package.tools.msbuild")
  73. local include_paths = {}
  74. local lib_paths = {}
  75. -- Fetch *ace* dependency
  76. local packagedep = package:dep("ace")
  77. if packagedep then
  78. local fetchinfo = packagedep:fetch()
  79. if fetchinfo then
  80. for _, includedir in ipairs(fetchinfo.includedirs or fetchinfo.sysincludedirs) do
  81. table.insert(include_paths, includedir)
  82. end
  83. for _, linkdir in ipairs(fetchinfo.linkdirs) do
  84. table.insert(lib_paths, linkdir)
  85. end
  86. end
  87. end
  88. os.rm("Kokyu/tests")
  89. os.cp("Kokyu/**.h", package:installdir("include/Kokyu"), {rootdir = "Kokyu"})
  90. os.cp("Kokyu/**.cpp", package:installdir("include/Kokyu"), {rootdir = "Kokyu"})
  91. os.cp("Kokyu/**.inl", package:installdir("include/Kokyu"), {rootdir = "Kokyu"})
  92. os.cd("Kokyu")
  93. for _, vcxproj in ipairs({"Kokyu_vs2022.vcxproj"}) do
  94. io.replace(vcxproj,
  95. "<AdditionalIncludeDirectories>.-</AdditionalIncludeDirectories>",
  96. "<AdditionalIncludeDirectories>" .. table.concat(include_paths, ";") .. "</AdditionalIncludeDirectories>", {plain = false})
  97. io.replace(vcxproj,
  98. "<AdditionalLibraryDirectories>.-</AdditionalLibraryDirectories>",
  99. "<AdditionalLibraryDirectories>" .. table.concat(lib_paths, ";") .. "</AdditionalLibraryDirectories>", {plain = false})
  100. if package:has_runtime("MT", "MTd") then
  101. -- Allow MT, MTd
  102. io.replace(vcxproj, "<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>", "<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>", {plain = true})
  103. io.replace(vcxproj, "<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>", "<RuntimeLibrary>MultiThreaded</RuntimeLibrary>", {plain = true})
  104. end
  105. if not package:config("shared") then
  106. io.replace(vcxproj, "DynamicLibrary", "StaticLibrary", {plain = true})
  107. io.replace(vcxproj, "KOKYU_BUILD_DLL", "ACE_AS_STATIC_LIBS", {plain = true})
  108. end
  109. if package:config("shared") then
  110. io.replace(vcxproj, "KOKYU_BUILD_DLL", "ACE_BUILD_DLL;KOKYU_BUILD_DLL", {plain = true})
  111. end
  112. -- Allow use another Win SDK
  113. io.replace(vcxproj, "<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>", "", {plain = true})
  114. -- Disable LTCG
  115. io.replace(vcxproj, "<WholeProgramOptimization>true</WholeProgramOptimization>", "", {plain = true})
  116. end
  117. local configs = { "Kokyu_vs2022.sln", "/t:Kokyu" }
  118. local arch = package:is_arch("x64") and "x64" or "Win32"
  119. if package:is_arch("arm64") then
  120. arch = "ARM64"
  121. end
  122. local mode = package:is_debug() and "Debug" or "Release"
  123. table.insert(configs, "/p:Configuration=" .. mode)
  124. table.insert(configs, "/p:Platform=" .. arch)
  125. -- Wrap vstool so it would build for another vstools
  126. local msvc = import("core.tool.toolchain").load("msvc")
  127. local vs = msvc:config("vs")
  128. local vstool
  129. if vs == "2015" then vstool = "v140"
  130. elseif vs == "2017" then vstool = "v141"
  131. elseif vs == "2019" then vstool = "v142"
  132. elseif vs == "2022" then vstool = "v143"
  133. end
  134. table.insert(configs, "/p:PlatformToolset=" .. vstool)
  135. msbuild.build(package, configs)
  136. os.cd("..")
  137. os.cp("**.lib", package:installdir("lib"))
  138. if package:config("shared") then
  139. os.cp("**.dll", package:installdir("bin"))
  140. end
  141. end)
  142. on_test(function (package)
  143. local usage_test = [[
  144. #include <Kokyu/Kokyu.h>
  145. namespace Kokyu {
  146. class MyDispatcher : public Dispatcher_Impl {
  147. public:
  148. MyDispatcher() = default;
  149. private:
  150. int init_i(const Dispatcher_Attributes& attr) override {
  151. return 0;
  152. }
  153. int activate_i() override {
  154. return 0;
  155. }
  156. int dispatch_i(const Dispatch_Command* cmd,
  157. const QoSDescriptor& qos) override {
  158. return 0;
  159. }
  160. int shutdown_i() override {
  161. return 0;
  162. }
  163. };
  164. }
  165. void test() {
  166. Kokyu::MyDispatcher dispatcher;
  167. Kokyu::Dispatcher_Attributes attr;
  168. auto result = dispatcher.init(attr);
  169. }
  170. ]]
  171. if package:is_plat("windows") then
  172. usage_test = [[
  173. #define WIN32_LEAN_AND_MEAN
  174. #include <windows.h>
  175. ]] .. usage_test
  176. end
  177. assert(package:check_cxxsnippets({test = usage_test}, {configs = {languages = "c++17"}}))
  178. end)