xmake.lua 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. if is_plat("windows") then
  5. add_urls("https://github.com/oneapi-src/oneTBB/$(version)", {version = function (version)
  6. if version:ge("2021.0") then
  7. return "archive/v" .. version .. ".tar.gz"
  8. else
  9. return "releases/download/v" .. version .. "/tbb-" .. version .. "-win.zip"
  10. end
  11. end})
  12. add_versions("2020.3", "cda37eed5209746a79c88a658f8c1bf3782f58bd9f9f6ba0da3a16624a9bfaa1")
  13. add_versions("2021.2.0", "cee20b0a71d977416f3e3b4ec643ee4f38cedeb2a9ff015303431dd9d8d79854")
  14. add_versions("2021.3.0", "8f616561603695bbb83871875d2c6051ea28f8187dbe59299961369904d1d49e")
  15. add_versions("2021.4.0", "021796c7845e155e616f5ecda16daa606ebb4c6f90b996e5c08aebab7a8d3de3")
  16. add_versions("2021.5.0", "e5b57537c741400cf6134b428fc1689a649d7d38d9bb9c1b6d64f092ea28178a")
  17. else
  18. add_urls("https://github.com/oneapi-src/oneTBB/archive/v$(version).tar.gz")
  19. add_versions("2020.3", "ebc4f6aa47972daed1f7bf71d100ae5bf6931c2e3144cf299c8cc7d041dca2f3")
  20. add_versions("2021.2.0", "cee20b0a71d977416f3e3b4ec643ee4f38cedeb2a9ff015303431dd9d8d79854")
  21. add_versions("2021.3.0", "8f616561603695bbb83871875d2c6051ea28f8187dbe59299961369904d1d49e")
  22. add_versions("2021.4.0", "021796c7845e155e616f5ecda16daa606ebb4c6f90b996e5c08aebab7a8d3de3")
  23. add_versions("2021.5.0", "e5b57537c741400cf6134b428fc1689a649d7d38d9bb9c1b6d64f092ea28178a")
  24. add_patches("2021.2.0", path.join(os.scriptdir(), "patches", "2021.2.0", "gcc11.patch"), "181511cf4878460cb48ac0531d3ce8d1c57626d698e9001a0951c728fab176fb")
  25. add_patches("2021.5.0", path.join(os.scriptdir(), "patches", "2021.5.0", "i386.patch"), "1a1c11724839cf98b1b8f4d415c0283ec7719c330b11503c578739eb02889ec0")
  26. if is_plat("macosx") then
  27. add_configs("compiler", {description = "Compiler used to compile tbb." , default = "clang", type = "string", values = {"clang", "gcc", "icc", "cl", "icl", "[others]"}})
  28. else
  29. add_configs("compiler", {description = "Compiler used to compile tbb." , default = "gcc", type = "string", values = {"gcc", "clang", "icc", "cl", "icl", "[others]"}})
  30. end
  31. end
  32. add_configs("shared", {description = "Build shared library.", default = true, type = "boolean", readonly = true})
  33. on_fetch("fetch")
  34. add_links("tbb", "tbbmalloc", "tbbmalloc_proxy")
  35. on_load(function (package)
  36. if package:version():ge("2021.0") then
  37. package:add("deps", "cmake")
  38. end
  39. end)
  40. on_install("macosx", "linux", "mingw@windows", "mingw@msys", "android", function (package)
  41. if package:version():ge("2021.0") then
  42. if package:version():le("2021.4") and package:is_plat("mingw") then
  43. raise("mingw build is not supported in this version")
  44. end
  45. local configs = {"-DTBB_TEST=OFF", "-DTBB_STRICT=OFF"}
  46. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"))
  47. import("package.tools.cmake").install(package, configs)
  48. else
  49. local configs = {"-j4", "tbb_build_prefix=build_dir"}
  50. local cfg = package:debug() and "debug" or "release"
  51. table.insert(configs, "cfg=" .. cfg)
  52. table.insert(configs, "arch=" .. (package:is_arch("x86_64") and "intel64" or "ia32"))
  53. table.insert(configs, "compiler=" .. (package:config("compiler")))
  54. if package:is_plat("mingw") then
  55. os.vrunv("mingw32-make", configs)
  56. else
  57. os.vrunv("make", configs)
  58. end
  59. os.cp("include", package:installdir())
  60. os.rm("build/build_dir_" .. cfg .. "/*.d")
  61. os.rm("build/build_dir_" .. cfg .. "/*.o")
  62. os.cp("build/build_dir_" .. cfg .. "/**", package:installdir("lib"))
  63. if package:is_plat("mingw") then
  64. package:addenv("PATH", "lib")
  65. end
  66. end
  67. end)
  68. on_install("windows", function (package)
  69. if package:version():ge("2021.0") then
  70. local configs = {"-DTBB_TEST=OFF", "-DTBB_STRICT=OFF"}
  71. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"))
  72. import("package.tools.cmake").install(package, configs)
  73. else
  74. local incdir = "tbb/include"
  75. local libdir = "tbb/lib/"
  76. local bindir = "tbb/bin/"
  77. os.cp(incdir, package:installdir())
  78. local prefix = ""
  79. if package:is_arch("x64", "x86_64") then
  80. prefix = "intel64/vc14"
  81. else
  82. prefix = "ia32/vc14"
  83. end
  84. if package:config("debug") then
  85. os.cp(libdir .. prefix .. "/*_debug.*", package:installdir("lib"))
  86. os.cp(bindir .. prefix .. "/*_debug.*", package:installdir("bin"))
  87. else
  88. os.cp(libdir .. prefix .. "/**|*_debug.*", package:installdir("lib"))
  89. os.cp(bindir .. prefix .. "/**|*_debug.*", package:installdir("bin"))
  90. end
  91. end
  92. package:addenv("PATH", "bin")
  93. end)
  94. on_test(function (package)
  95. assert(package:check_cxxsnippets({test = [[
  96. void test() {
  97. using std::size_t;
  98. constexpr size_t N = 10;
  99. int X[N], Y[N], Z[N];
  100. for (int i = 0; i < N; ++i)
  101. X[i] = i, Y[i] = 2*i;
  102. tbb::parallel_for(tbb::blocked_range<size_t>(0, N), [&](const tbb::blocked_range<size_t> &rg) {
  103. for (size_t i = rg.begin(); i != rg.end(); ++i)
  104. Z[i] = X[i] + Y[i];
  105. });
  106. }
  107. ]]}, {configs = {languages = "c++14"},
  108. includes = {"tbb/parallel_for.h", "tbb/blocked_range.h"}}))
  109. end)