xmake.lua 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. package("tbb")
  2. set_homepage("https://software.intel.com/en-us/tbb/")
  3. set_description("Threading Building Blocks (TBB) lets you easily write parallel C++ programs that take full advantage of multicore performance, that are portable, composable and have future-proof scalability.")
  4. set_license("Apache-2.0")
  5. add_urls("https://github.com/oneapi-src/oneTBB.git")
  6. if is_plat("windows") then
  7. add_urls("https://github.com/oneapi-src/oneTBB/$(version)", {version = function (version)
  8. if version:ge("2021.0") then
  9. return "archive/refs/tags/v" .. version .. ".tar.gz"
  10. else
  11. return "releases/download/v" .. version .. "/tbb-" .. version .. "-win.zip"
  12. end
  13. end})
  14. add_versions("2020.3", "cda37eed5209746a79c88a658f8c1bf3782f58bd9f9f6ba0da3a16624a9bfaa1")
  15. add_versions("2021.2.0", "cee20b0a71d977416f3e3b4ec643ee4f38cedeb2a9ff015303431dd9d8d79854")
  16. add_versions("2021.3.0", "8f616561603695bbb83871875d2c6051ea28f8187dbe59299961369904d1d49e")
  17. add_versions("2021.4.0", "021796c7845e155e616f5ecda16daa606ebb4c6f90b996e5c08aebab7a8d3de3")
  18. add_versions("2021.5.0", "e5b57537c741400cf6134b428fc1689a649d7d38d9bb9c1b6d64f092ea28178a")
  19. add_versions("2021.7.0", "2cae2a80cda7d45dc7c072e4295c675fff5ad8316691f26f40539f7e7e54c0cc")
  20. add_versions("2021.10.0", "487023a955e5a3cc6d3a0d5f89179f9b6c0ae7222613a7185b0227ba0c83700b")
  21. add_versions("2021.11.0", "782ce0cab62df9ea125cdea253a50534862b563f1d85d4cda7ad4e77550ac363")
  22. add_versions("2021.12.0", "c7bb7aa69c254d91b8f0041a71c5bcc3936acb64408a1719aec0b2b7639dd84f")
  23. add_versions("2021.13.0", "3ad5dd08954b39d113dc5b3f8a8dc6dc1fd5250032b7c491eb07aed5c94133e1")
  24. add_versions("2022.0.0", "e8e89c9c345415b17b30a2db3095ba9d47647611662073f7fbf54ad48b7f3c2a")
  25. else
  26. add_urls("https://github.com/oneapi-src/oneTBB/archive/refs/tags/v$(version).tar.gz")
  27. add_versions("2020.3", "ebc4f6aa47972daed1f7bf71d100ae5bf6931c2e3144cf299c8cc7d041dca2f3")
  28. add_versions("2021.2.0", "cee20b0a71d977416f3e3b4ec643ee4f38cedeb2a9ff015303431dd9d8d79854")
  29. add_versions("2021.3.0", "8f616561603695bbb83871875d2c6051ea28f8187dbe59299961369904d1d49e")
  30. add_versions("2021.4.0", "021796c7845e155e616f5ecda16daa606ebb4c6f90b996e5c08aebab7a8d3de3")
  31. add_versions("2021.5.0", "e5b57537c741400cf6134b428fc1689a649d7d38d9bb9c1b6d64f092ea28178a")
  32. add_versions("2021.7.0", "2cae2a80cda7d45dc7c072e4295c675fff5ad8316691f26f40539f7e7e54c0cc")
  33. add_versions("2021.10.0", "487023a955e5a3cc6d3a0d5f89179f9b6c0ae7222613a7185b0227ba0c83700b")
  34. add_versions("2021.11.0", "782ce0cab62df9ea125cdea253a50534862b563f1d85d4cda7ad4e77550ac363")
  35. add_versions("2021.12.0", "c7bb7aa69c254d91b8f0041a71c5bcc3936acb64408a1719aec0b2b7639dd84f")
  36. add_versions("2021.13.0", "3ad5dd08954b39d113dc5b3f8a8dc6dc1fd5250032b7c491eb07aed5c94133e1")
  37. add_versions("2022.0.0", "e8e89c9c345415b17b30a2db3095ba9d47647611662073f7fbf54ad48b7f3c2a")
  38. add_patches("2020.3", "patches/2020.3/gcc13.patch", "419557beb877a72fa394c886fbb674c1b0c300fee7f2ec4e2de39ceeeb6b95fd")
  39. add_patches("2021.2.0", "patches/2021.2.0/gcc11.patch", "181511cf4878460cb48ac0531d3ce8d1c57626d698e9001a0951c728fab176fb")
  40. add_patches("2021.5.0", "patches/2021.5.0/i386.patch", "1a1c11724839cf98b1b8f4d415c0283ec7719c330b11503c578739eb02889ec0")
  41. add_patches("2022.0.0", "patches/2022.0.0/fix-mingw-compilation.patch", "917999038883152acd2e8b59edbc67081d4c9cb6a15113ce28d38274fe8fb0d9")
  42. if is_plat("macosx") then
  43. add_configs("compiler", {description = "Compiler used to compile tbb." , default = "clang", type = "string", values = {"clang", "gcc", "icc", "cl", "icl", "[others]"}})
  44. else
  45. add_configs("compiler", {description = "Compiler used to compile tbb." , default = "gcc", type = "string", values = {"gcc", "clang", "icc", "cl", "icl", "[others]"}})
  46. end
  47. end
  48. add_configs("shared", {description = "Build shared library.", default = true, type = "boolean", readonly = true})
  49. on_fetch("fetch")
  50. if on_check then
  51. on_check("macosx", function (package)
  52. if package:is_arch("arm64") then
  53. assert(package:version():ge("2021.0"), "package(tbb/arm64 <2021.0) unsupported version on macosx")
  54. end
  55. end)
  56. end
  57. on_load(function (package)
  58. if package:has_tool("cxx", "cl", "clang_cl") then
  59. package:add("defines", "__TBB_NO_IMPLICIT_LINKAGE")
  60. end
  61. if package:is_debug() then
  62. package:add("links", "tbb_debug", "tbbmalloc_debug", "tbbmalloc_proxy_debug")
  63. else
  64. package:add("links", "tbb", "tbbmalloc", "tbbmalloc_proxy")
  65. end
  66. if package:gitref() or package:version():ge("2021.0") then
  67. package:add("deps", "cmake")
  68. end
  69. end)
  70. on_install("macosx", "linux", "mingw@windows", "mingw@msys", "android", function (package)
  71. if package:gitref() or package:version():ge("2021.0") then
  72. if package:version():le("2021.4") and package:is_plat("mingw") then
  73. raise("mingw build is not supported in this version")
  74. end
  75. local configs = {"-DTBB_TEST=OFF", "-DTBB_STRICT=OFF"}
  76. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"))
  77. if package:is_plat("mingw") then
  78. io.replace("cmake/compilers/Clang.cmake", "-Wl,-z,relro,-z,now,-z,noexecstack", "", {plain = true})
  79. io.replace("cmake/compilers/GNU.cmake", "-Wl,-z,relro,-z,now,-z,noexecstack", "", {plain = true})
  80. table.insert(configs, "-DCMAKE_SYSTEM_PROCESSOR=" .. (package:is_arch("x86_64") and "AMD64" or "i686"))
  81. end
  82. local exflags
  83. if package:is_plat("android") then
  84. import("core.tool.toolchain")
  85. local ndk = toolchain.load("ndk", {plat = package:plat(), arch = package:arch()})
  86. local ndkver = ndk:config("ndkver")
  87. if ndkver == 26 or ndkver == 27 then
  88. exflags = {"-Wl,--undefined-version"}
  89. end
  90. end
  91. import("package.tools.cmake").install(package, configs, {shflags = exflags, ldflags = exflags})
  92. if package:is_plat("mingw") then
  93. local ext = package:config("shared") and ".dll.a" or ".a"
  94. local libfiles = os.files(path.join(package:installdir("lib"), "libtbb*" .. ext))
  95. for _, libfile in ipairs(libfiles) do
  96. if libfile:match(".+libtbb%d+" .. ext) then
  97. os.cp(libfile, path.join(package:installdir("lib"), "libtbb" .. ext))
  98. break
  99. end
  100. end
  101. end
  102. else
  103. local configs = {"-j4", "tbb_build_prefix=build_dir"}
  104. local cfg = package:debug() and "debug" or "release"
  105. table.insert(configs, "cfg=" .. cfg)
  106. table.insert(configs, "arch=" .. (package:is_arch("x86_64") and "intel64" or "ia32"))
  107. table.insert(configs, "compiler=" .. (package:config("compiler")))
  108. if package:is_plat("mingw") then
  109. os.vrunv("mingw32-make", configs)
  110. else
  111. os.vrunv("make", configs)
  112. end
  113. os.cp("include", package:installdir())
  114. os.rm("build/build_dir_" .. cfg .. "/*.d")
  115. os.rm("build/build_dir_" .. cfg .. "/*.o")
  116. os.cp("build/build_dir_" .. cfg .. "/**", package:installdir("lib"))
  117. if package:is_plat("mingw") then
  118. package:addenv("PATH", "lib")
  119. end
  120. end
  121. end)
  122. on_install("windows", function (package)
  123. if package:gitref() or package:version():ge("2021.0") then
  124. local configs = {"-DTBB_TEST=OFF", "-DTBB_STRICT=OFF"}
  125. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"))
  126. import("package.tools.cmake").install(package, configs)
  127. else
  128. local incdir = "tbb/include"
  129. local libdir = "tbb/lib/"
  130. local bindir = "tbb/bin/"
  131. os.cp(incdir, package:installdir())
  132. local prefix = ""
  133. if package:is_arch("x64", "x86_64") then
  134. prefix = "intel64/vc14"
  135. else
  136. prefix = "ia32/vc14"
  137. end
  138. if package:config("debug") then
  139. os.cp(libdir .. prefix .. "/*_debug.*", package:installdir("lib"))
  140. os.cp(bindir .. prefix .. "/*_debug.*", package:installdir("bin"))
  141. else
  142. os.cp(libdir .. prefix .. "/**|*_debug.*", package:installdir("lib"))
  143. os.cp(bindir .. prefix .. "/**|*_debug.*", package:installdir("bin"))
  144. end
  145. end
  146. package:addenv("PATH", "bin")
  147. end)
  148. on_test(function (package)
  149. assert(package:check_cxxsnippets({test = [[
  150. void test() {
  151. using std::size_t;
  152. constexpr size_t N = 10;
  153. int X[N], Y[N], Z[N];
  154. for (int i = 0; i < N; ++i)
  155. X[i] = i, Y[i] = 2*i;
  156. tbb::parallel_for(tbb::blocked_range<size_t>(0, N), [&](const tbb::blocked_range<size_t> &rg) {
  157. for (size_t i = rg.begin(); i != rg.end(); ++i)
  158. Z[i] = X[i] + Y[i];
  159. });
  160. }
  161. ]]}, {configs = {languages = "c++14"},
  162. includes = {"tbb/parallel_for.h", "tbb/blocked_range.h"}}))
  163. end)