2
0

xmake.lua 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. package("boost")
  2. set_homepage("https://www.boost.org/")
  3. set_description("Collection of portable C++ source libraries.")
  4. set_license("BSL-1.0")
  5. add_urls("https://boostorg.jfrog.io/artifactory/main/release/$(version).tar.bz2", {version = function (version)
  6. return version .. "/source/boost_" .. (version:gsub("%.", "_"))
  7. end})
  8. add_urls("https://github.com/xmake-mirror/boost/releases/download/boost-$(version).tar.bz2", {version = function (version)
  9. return version .. "/boost_" .. (version:gsub("%.", "_"))
  10. end})
  11. add_versions("1.79.0", "475d589d51a7f8b3ba2ba4eda022b170e562ca3b760ee922c146b6c65856ef39")
  12. add_versions("1.78.0", "8681f175d4bdb26c52222665793eef08490d7758529330f98d3b29dd0735bccc")
  13. add_versions("1.77.0", "fc9f85fc030e233142908241af7a846e60630aa7388de9a5fafb1f3a26840854")
  14. add_versions("1.76.0", "f0397ba6e982c4450f27bf32a2a83292aba035b827a5623a14636ea583318c41")
  15. add_versions("1.75.0", "953db31e016db7bb207f11432bef7df100516eeb746843fa0486a222e3fd49cb")
  16. add_versions("1.74.0", "83bfc1507731a0906e387fc28b7ef5417d591429e51e788417fe9ff025e116b1")
  17. add_versions("1.73.0", "4eb3b8d442b426dc35346235c8733b5ae35ba431690e38c6a8263dce9fcbb402")
  18. add_versions("1.72.0", "59c9b274bc451cf91a9ba1dd2c7fdcaf5d60b1b3aa83f2c9fa143417cc660722")
  19. add_versions("1.70.0", "430ae8354789de4fd19ee52f3b1f739e1fba576f0aded0897c3c2bc00fb38778")
  20. if is_plat("mingw") and is_subhost("msys") then
  21. add_extsources("pacman::boost")
  22. elseif is_plat("linux") then
  23. add_extsources("pacman::boost", "apt::libboost-all-dev")
  24. elseif is_plat("macosx") then
  25. add_extsources("brew::boost")
  26. end
  27. add_patches("1.75.0", path.join(os.scriptdir(), "patches", "1.75.0", "warning.patch"), "43ff97d338c78b5c3596877eed1adc39d59a000cf651d0bcc678cf6cd6d4ae2e")
  28. if is_plat("linux") then
  29. add_deps("bzip2", "zlib")
  30. add_syslinks("pthread", "dl")
  31. end
  32. local libnames = {"fiber",
  33. "coroutine",
  34. "context",
  35. "thread",
  36. "regex",
  37. "system",
  38. "container",
  39. "exception",
  40. "timer",
  41. "atomic",
  42. "graph",
  43. "serialization",
  44. "random",
  45. "wave",
  46. "date_time",
  47. "locale",
  48. "iostreams",
  49. "program_options",
  50. "test",
  51. "chrono",
  52. "contract",
  53. "graph_parallel",
  54. "json",
  55. "log",
  56. "filesystem",
  57. "math",
  58. "mpi",
  59. "nowide",
  60. "python",
  61. "stacktrace",
  62. "type_erasure"}
  63. add_configs("all", { description = "Enable all library modules support.", default = false, type = "boolean"})
  64. add_configs("multi", { description = "Enable multi-thread support.", default = true, type = "boolean"})
  65. for _, libname in ipairs(libnames) do
  66. add_configs(libname, { description = "Enable " .. libname .. " library.", default = (libname == "filesystem"), type = "boolean"})
  67. end
  68. on_load(function (package)
  69. function get_linkname(package, libname)
  70. local linkname
  71. if package:is_plat("windows") then
  72. linkname = (package:config("shared") and "boost_" or "libboost_") .. libname
  73. else
  74. linkname = "boost_" .. libname
  75. end
  76. if package:config("multi") then
  77. linkname = linkname .. "-mt"
  78. end
  79. if package:is_plat("windows") then
  80. local vs_runtime = package:config("vs_runtime")
  81. if package:config("shared") then
  82. if package:debug() then
  83. linkname = linkname .. "-gd"
  84. end
  85. elseif vs_runtime == "MT" then
  86. linkname = linkname .. "-s"
  87. elseif vs_runtime == "MTd" then
  88. linkname = linkname .. "-sgd"
  89. elseif vs_runtime == "MDd" then
  90. linkname = linkname .. "-gd"
  91. end
  92. end
  93. return linkname
  94. end
  95. -- we need the fixed link order
  96. local sublibs = {log = {"log_setup", "log"}}
  97. for _, libname in ipairs(libnames) do
  98. local libs = sublibs[libname]
  99. if libs then
  100. for _, lib in ipairs(libs) do
  101. package:add("links", get_linkname(package, lib))
  102. end
  103. else
  104. package:add("links", get_linkname(package, libname))
  105. end
  106. end
  107. -- disable auto-link all libs
  108. if package:is_plat("windows") then
  109. package:add("defines", "BOOST_ALL_NO_LIB")
  110. end
  111. end)
  112. on_install("macosx", "linux", "windows", "bsd", "mingw", "cross", function (package)
  113. -- force boost to compile with the desired compiler
  114. local file = io.open("user-config.jam", "a")
  115. if file then
  116. if package:is_plat("macosx") then
  117. -- we uses ld/clang++ for link stdc++ for shared libraries
  118. file:print("using darwin : : %s ;", package:build_getenv("ld"))
  119. elseif package:is_plat("windows") then
  120. file:print("using msvc : : \"%s\" ;", (package:build_getenv("cxx"):gsub("\\", "\\\\")))
  121. else
  122. file:print("using gcc : : %s ;", package:build_getenv("cxx"):gsub("\\", "/"))
  123. end
  124. file:close()
  125. end
  126. local bootstrap_argv =
  127. {
  128. "--prefix=" .. package:installdir(),
  129. "--libdir=" .. package:installdir("lib"),
  130. "--without-icu"
  131. }
  132. if is_host("windows") then
  133. import("core.tool.toolchain")
  134. local runenvs = toolchain.load("msvc"):runenvs()
  135. os.vrunv("bootstrap.bat", bootstrap_argv, {envs = runenvs})
  136. else
  137. os.vrunv("./bootstrap.sh", bootstrap_argv)
  138. end
  139. os.vrun("./b2 headers")
  140. local argv =
  141. {
  142. "--prefix=" .. package:installdir(),
  143. "--libdir=" .. package:installdir("lib"),
  144. "-d2",
  145. "-j4",
  146. "--hash",
  147. "--layout=tagged-1.66", -- prevent -x64 suffix in case cmake can't find it
  148. "--user-config=user-config.jam",
  149. "-sNO_LZMA=1",
  150. "-sNO_ZSTD=1",
  151. "install",
  152. "threading=" .. (package:config("multi") and "multi" or "single"),
  153. "debug-symbols=" .. (package:debug() and "on" or "off"),
  154. "link=" .. (package:config("shared") and "shared" or "static")
  155. }
  156. if package:is_arch(".+64.*") then
  157. table.insert(argv, "address-model=64")
  158. else
  159. table.insert(argv, "address-model=32")
  160. end
  161. if package:is_plat("windows") then
  162. local vs_runtime = package:config("vs_runtime")
  163. if package:config("shared") then
  164. table.insert(argv, "runtime-link=shared")
  165. elseif vs_runtime and vs_runtime:startswith("MT") then
  166. table.insert(argv, "runtime-link=static")
  167. else
  168. table.insert(argv, "runtime-link=shared")
  169. end
  170. table.insert(argv, "cxxflags=-std:c++14")
  171. else
  172. table.insert(argv, "cxxflags=-std=c++14")
  173. if package:config("pic") ~= false then
  174. table.insert(argv, "cxxflags=-fPIC")
  175. end
  176. end
  177. for _, libname in ipairs(libnames) do
  178. if package:config("all") or package:config(libname) then
  179. table.insert(argv, "--with-" .. libname)
  180. end
  181. end
  182. os.vrunv("./b2", argv)
  183. end)
  184. on_test(function (package)
  185. assert(package:check_cxxsnippets({test = [[
  186. #include <boost/algorithm/string.hpp>
  187. #include <string>
  188. #include <vector>
  189. static void test() {
  190. std::string str("a,b");
  191. std::vector<std::string> vec;
  192. boost::algorithm::split(vec, str, boost::algorithm::is_any_of(","));
  193. }
  194. ]]}, {configs = {languages = "c++14"}}))
  195. if package:config("date_time") then
  196. assert(package:check_cxxsnippets({test = [[
  197. #include <boost/date_time/gregorian/gregorian.hpp>
  198. static void test() {
  199. boost::gregorian::date d(2010, 1, 30);
  200. }
  201. ]]}, {configs = {languages = "c++14"}}))
  202. end
  203. end)