xmake.lua 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  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://github.com/boostorg/boost/releases/download/boost-$(version)/boost-$(version)-b2-nodocs.tar.gz")
  6. add_urls("https://github.com/boostorg/boost/releases/download/boost-$(version)/boost-$(version).tar.gz")
  7. add_urls("https://github.com/xmake-mirror/boost/releases/download/boost-$(version).tar.bz2", {alias = "mirror", version = function (version)
  8. return version .. "/boost_" .. (version:gsub("%.", "_"))
  9. end})
  10. add_versions("1.85.0", "f4a7d3f81b8a0f65067b769ea84135fd7b72896f4f59c7f405086c8c0dc61434")
  11. add_versions("1.84.0", "4d27e9efed0f6f152dc28db6430b9d3dfb40c0345da7342eaa5a987dde57bd95")
  12. add_versions("1.83.0", "0c6049764e80aa32754acd7d4f179fd5551d8172a83b71532ae093e7384e98da")
  13. add_versions("1.82.0", "b62bd839ea6c28265af9a1f68393eda37fab3611425d3b28882d8e424535ec9d")
  14. add_versions("1.81.0", "121da556b718fd7bd700b5f2e734f8004f1cfa78b7d30145471c526ba75a151c")
  15. add_versions("mirror:1.80.0", "1e19565d82e43bc59209a168f5ac899d3ba471d55c7610c677d4ccf2c9c500c0")
  16. add_versions("mirror:1.79.0", "475d589d51a7f8b3ba2ba4eda022b170e562ca3b760ee922c146b6c65856ef39")
  17. add_versions("mirror:1.78.0", "8681f175d4bdb26c52222665793eef08490d7758529330f98d3b29dd0735bccc")
  18. add_versions("mirror:1.77.0", "fc9f85fc030e233142908241af7a846e60630aa7388de9a5fafb1f3a26840854")
  19. add_versions("mirror:1.76.0", "f0397ba6e982c4450f27bf32a2a83292aba035b827a5623a14636ea583318c41")
  20. add_versions("mirror:1.75.0", "953db31e016db7bb207f11432bef7df100516eeb746843fa0486a222e3fd49cb")
  21. add_versions("mirror:1.74.0", "83bfc1507731a0906e387fc28b7ef5417d591429e51e788417fe9ff025e116b1")
  22. add_versions("mirror:1.73.0", "4eb3b8d442b426dc35346235c8733b5ae35ba431690e38c6a8263dce9fcbb402")
  23. add_versions("mirror:1.72.0", "59c9b274bc451cf91a9ba1dd2c7fdcaf5d60b1b3aa83f2c9fa143417cc660722")
  24. add_versions("mirror:1.70.0", "430ae8354789de4fd19ee52f3b1f739e1fba576f0aded0897c3c2bc00fb38778")
  25. if is_plat("mingw") and is_subhost("msys") then
  26. add_extsources("pacman::boost")
  27. elseif is_plat("linux") then
  28. add_extsources("pacman::boost", "apt::libboost-all-dev")
  29. elseif is_plat("macosx") then
  30. add_extsources("brew::boost")
  31. end
  32. add_patches("1.75.0", path.join(os.scriptdir(), "patches", "1.75.0", "warning.patch"), "43ff97d338c78b5c3596877eed1adc39d59a000cf651d0bcc678cf6cd6d4ae2e")
  33. if is_plat("linux") then
  34. add_deps("bzip2", "zlib")
  35. add_syslinks("pthread", "dl")
  36. end
  37. add_configs("pyver", {description = "python version x.y, etc. 3.10", default = "3.10"})
  38. local libnames = {"fiber",
  39. "coroutine",
  40. "context",
  41. "regex",
  42. "system",
  43. "container",
  44. "exception",
  45. "timer",
  46. "atomic",
  47. "graph",
  48. "serialization",
  49. "random",
  50. "wave",
  51. "date_time",
  52. "locale",
  53. "iostreams",
  54. "program_options",
  55. "test",
  56. "chrono",
  57. "contract",
  58. "graph_parallel",
  59. "json",
  60. "log",
  61. "thread",
  62. "filesystem",
  63. "math",
  64. "mpi",
  65. "nowide",
  66. "python",
  67. "stacktrace",
  68. "type_erasure"}
  69. add_configs("all", { description = "Enable all library modules support.", default = false, type = "boolean"})
  70. add_configs("multi", { description = "Enable multi-thread support.", default = true, type = "boolean"})
  71. for _, libname in ipairs(libnames) do
  72. add_configs(libname, { description = "Enable " .. libname .. " library.", default = (libname == "filesystem"), type = "boolean"})
  73. end
  74. on_load(function (package)
  75. function get_linkname(package, libname)
  76. local linkname
  77. if package:is_plat("windows") then
  78. linkname = (package:config("shared") and "boost_" or "libboost_") .. libname
  79. else
  80. linkname = "boost_" .. libname
  81. end
  82. if libname == "python" or libname == "numpy" then
  83. linkname = linkname .. package:config("pyver"):gsub("%p+", "")
  84. end
  85. if package:config("multi") then
  86. linkname = linkname .. "-mt"
  87. end
  88. if package:is_plat("windows") then
  89. local vs_runtime = package:config("vs_runtime")
  90. if package:config("shared") then
  91. if package:debug() then
  92. linkname = linkname .. "-gd"
  93. end
  94. elseif vs_runtime == "MT" then
  95. linkname = linkname .. "-s"
  96. elseif vs_runtime == "MTd" then
  97. linkname = linkname .. "-sgd"
  98. elseif vs_runtime == "MDd" then
  99. linkname = linkname .. "-gd"
  100. end
  101. else
  102. if package:debug() then
  103. linkname = linkname .. "-d"
  104. end
  105. end
  106. return linkname
  107. end
  108. -- we need the fixed link order
  109. local sublibs = {log = {"log_setup", "log"},
  110. python = {"python", "numpy"},
  111. stacktrace = {"stacktrace_backtrace", "stacktrace_basic"}}
  112. for _, libname in ipairs(libnames) do
  113. local libs = sublibs[libname]
  114. if libs then
  115. for _, lib in ipairs(libs) do
  116. package:add("links", get_linkname(package, lib))
  117. end
  118. else
  119. package:add("links", get_linkname(package, libname))
  120. end
  121. end
  122. -- disable auto-link all libs
  123. if package:is_plat("windows") then
  124. package:add("defines", "BOOST_ALL_NO_LIB")
  125. end
  126. if package:config("python") then
  127. if not package:config("shared") then
  128. package:add("defines", "BOOST_PYTHON_STATIC_LIB")
  129. end
  130. package:add("deps", "python " .. package:config("pyver") .. ".x", {configs = {headeronly = true}})
  131. end
  132. end)
  133. on_install("macosx", "linux", "windows", "bsd", "mingw", "cross", function (package)
  134. import("core.base.option")
  135. function get_compiler(package, toolchain)
  136. local cxx = package:build_getenv("cxx")
  137. if package:is_plat("macosx") then
  138. -- we uses ld/clang++ for link stdc++ for shared libraries
  139. -- and we need `xcrun -sdk macosx clang++` to make b2 to get `-isysroot` automatically
  140. local cc = package:build_getenv("ld")
  141. if cc and cc:find("clang", 1, true) and cc:find("Xcode", 1, true) then
  142. cc = "xcrun -sdk macosx clang++"
  143. end
  144. return format("using darwin : : %s ;", cc)
  145. elseif package:is_plat("windows") then
  146. local vs_toolset = toolchain:config("vs_toolset")
  147. local msvc_ver = ""
  148. local win_toolset = "msvc"
  149. if toolchain:name() == "clang-cl" then
  150. win_toolset = "clang-win"
  151. cxx = cxx:gsub("(clang%-cl)$", "%1.exe", 1)
  152. msvc_ver = ""
  153. elseif vs_toolset then
  154. local i = vs_toolset:find("%.")
  155. msvc_ver = i and vs_toolset:sub(1, i + 1)
  156. end
  157. -- Specifying a version will disable b2 from forcing tools
  158. -- from the latest installed msvc version.
  159. return format("using %s : %s : \"%s\" ;", win_toolset, msvc_ver, cxx:gsub("\\", "\\\\"))
  160. else
  161. cxx = cxx:gsub("gcc$", "g++")
  162. cxx = cxx:gsub("gcc%-", "g++-")
  163. cxx = cxx:gsub("clang$", "clang++")
  164. cxx = cxx:gsub("clang%-", "clang++-")
  165. if cxx and cxx:find("clang", 1, true) then
  166. return format("using clang : : \"%s\" ;", cxx:gsub("\\", "/"))
  167. else
  168. return format("using gcc : : \"%s\" ;", cxx:gsub("\\", "/"))
  169. end
  170. end
  171. end
  172. -- get host toolchain
  173. import("core.tool.toolchain")
  174. local host_toolchain
  175. if package:is_plat("windows") then
  176. host_toolchain = toolchain.load("msvc", {plat = "windows", arch = os.arch()})
  177. if not host_toolchain:check() then
  178. host_toolchain = toolchain.load("clang-cl", {plat = "windows", arch = os.arch()})
  179. end
  180. assert(host_toolchain:check(), "host msvc or clang-cl not found!")
  181. end
  182. -- force boost to compile with the desired compiler
  183. local file = io.open("user-config.jam", "w")
  184. if file then
  185. file:write(get_compiler(package, host_toolchain))
  186. file:close()
  187. end
  188. local bootstrap_argv =
  189. {
  190. "--prefix=" .. package:installdir(),
  191. "--libdir=" .. package:installdir("lib"),
  192. "--without-icu"
  193. }
  194. if package:has_tool("cxx", "clang", "clangxx") then
  195. table.insert(bootstrap_argv, "--with-toolset=clang")
  196. end
  197. if package:is_plat("windows") then
  198. -- for bootstrap.bat, all other arguments are useless
  199. bootstrap_argv = { "msvc" }
  200. os.vrunv("bootstrap.bat", bootstrap_argv, {envs = host_toolchain:runenvs()})
  201. elseif package:is_plat("mingw") and is_host("windows") then
  202. bootstrap_argv = { "gcc" }
  203. os.vrunv("bootstrap.bat", bootstrap_argv)
  204. -- todo looking for better solution to fix the confict between user-config.jam and project-config.jam
  205. io.replace("project-config.jam", "using[^\n]+", "")
  206. else
  207. os.vrunv("./bootstrap.sh", bootstrap_argv)
  208. end
  209. -- get build toolchain
  210. local build_toolchain
  211. local build_toolset
  212. local runenvs
  213. if package:is_plat("windows") then
  214. if package:has_tool("cxx", "clang_cl") then
  215. build_toolset = "clang-win"
  216. build_toolchain = package:toolchain("clang-cl")
  217. elseif package:has_tool("cxx", "cl") then
  218. build_toolset = "msvc"
  219. build_toolchain = package:toolchain("msvc")
  220. end
  221. if build_toolchain then
  222. runenvs = build_toolchain:runenvs()
  223. end
  224. end
  225. local file = io.open("user-config.jam", "w")
  226. if file then
  227. file:write(get_compiler(package, build_toolchain))
  228. file:close()
  229. end
  230. os.vrun("./b2 headers")
  231. local njobs = option.get("jobs") or tostring(os.default_njob())
  232. local argv =
  233. {
  234. "--prefix=" .. package:installdir(),
  235. "--libdir=" .. package:installdir("lib"),
  236. "-d2",
  237. "-j" .. njobs,
  238. "--hash",
  239. "-q", -- quit on first error
  240. "--layout=tagged-1.66", -- prevent -x64 suffix in case cmake can't find it
  241. "--user-config=user-config.jam",
  242. "-sNO_LZMA=1",
  243. "-sNO_ZSTD=1",
  244. "install",
  245. "threading=" .. (package:config("multi") and "multi" or "single"),
  246. "debug-symbols=" .. (package:debug() and "on" or "off"),
  247. "link=" .. (package:config("shared") and "shared" or "static"),
  248. "variant=" .. (package:is_debug() and "debug" or "release"),
  249. "runtime-debugging=" .. (package:is_debug() and "on" or "off")
  250. }
  251. if package:config("lto") then
  252. table.insert(argv, "lto=on")
  253. end
  254. if package:is_arch("aarch64", "arm+.*") then
  255. table.insert(argv, "architecture=arm")
  256. end
  257. if package:is_arch(".+64.*") then
  258. table.insert(argv, "address-model=64")
  259. else
  260. table.insert(argv, "address-model=32")
  261. end
  262. local cxxflags
  263. local linkflags
  264. if package:is_plat("windows") then
  265. local vs_runtime = package:config("vs_runtime")
  266. if package:config("shared") then
  267. table.insert(argv, "runtime-link=shared")
  268. elseif vs_runtime and vs_runtime:startswith("MT") then
  269. table.insert(argv, "runtime-link=static")
  270. else
  271. table.insert(argv, "runtime-link=shared")
  272. end
  273. table.insert(argv, "toolset=" .. build_toolset)
  274. cxxflags = "-std:c++14"
  275. elseif package:is_plat("mingw") then
  276. table.insert(argv, "toolset=gcc")
  277. elseif package:is_plat("macosx") then
  278. table.insert(argv, "toolset=darwin")
  279. -- fix macosx arm64 build issue https://github.com/microsoft/vcpkg/pull/18529
  280. cxxflags = "-std=c++14 -arch " .. package:arch()
  281. local xcode = package:toolchain("xcode") or import("core.tool.toolchain").load("xcode", {plat = package:plat(), arch = package:arch()})
  282. if xcode:check() then
  283. local xcode_dir = xcode:config("xcode")
  284. local xcode_sdkver = xcode:config("xcode_sdkver")
  285. local target_minver = xcode:config("target_minver")
  286. if xcode_dir and xcode_sdkver then
  287. local xcode_sdkdir = xcode_dir .. "/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX" .. xcode_sdkver .. ".sdk"
  288. cxxflags = cxxflags .. " -isysroot " .. xcode_sdkdir
  289. end
  290. if target_minver then
  291. cxxflags = cxxflags .. " -mmacosx-version-min=" .. target_minver
  292. end
  293. end
  294. else
  295. cxxflags = "-std=c++14"
  296. if package:config("pic") ~= false then
  297. cxxflags = cxxflags .. " -fPIC"
  298. end
  299. end
  300. if package.has_runtime and package:has_runtime("c++_shared", "c++_static") then
  301. cxxflags = (cxxflags or "") .. " -stdlib=libc++"
  302. linkflags = (linkflags or "") .. " -stdlib=libc++"
  303. if package:has_runtime("c++_static") then
  304. linkflags = linkflags .. " -static-libstdc++"
  305. end
  306. end
  307. if cxxflags then
  308. table.insert(argv, "cxxflags=" .. cxxflags)
  309. end
  310. if linkflags then
  311. table.insert(argv, "linkflags=" .. linkflags)
  312. end
  313. for _, libname in ipairs(libnames) do
  314. if package:config("all") or package:config(libname) then
  315. table.insert(argv, "--with-" .. libname)
  316. end
  317. end
  318. if package:is_plat("linux") then
  319. table.insert(argv, "pch=off")
  320. end
  321. local ok = os.execv("./b2", argv, {envs = runenvs, try = true, stdout = "boost-log.txt"})
  322. if ok ~= 0 then
  323. raise("boost build failed, please check log in " .. path.join(os.curdir(), "boost-log.txt"))
  324. end
  325. end)
  326. on_test(function (package)
  327. assert(package:check_cxxsnippets({test = [[
  328. #include <boost/algorithm/string.hpp>
  329. #include <string>
  330. #include <vector>
  331. static void test() {
  332. std::string str("a,b");
  333. std::vector<std::string> vec;
  334. boost::algorithm::split(vec, str, boost::algorithm::is_any_of(","));
  335. }
  336. ]]}, {configs = {languages = "c++14"}}))
  337. if package:config("date_time") then
  338. assert(package:check_cxxsnippets({test = [[
  339. #include <boost/date_time/gregorian/gregorian.hpp>
  340. static void test() {
  341. boost::gregorian::date d(2010, 1, 30);
  342. }
  343. ]]}, {configs = {languages = "c++14"}}))
  344. end
  345. end)