xmake.lua 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. package("boost")
  2. set_homepage("https://www.boost.org/")
  3. set_description("Collection of portable C++ source libraries.")
  4. add_urls("https://dl.bintray.com/boostorg/release/$(version).tar.bz2", {version = function (version)
  5. return version .. "/source/boost_" .. (version:gsub("%.", "_"))
  6. end})
  7. add_urls("https://github.com/xmake-mirror/boost/releases/download/boost-$(version).tar.bz2", {version = function (version)
  8. return version .. "/boost_" .. (version:gsub("%.", "_"))
  9. end})
  10. add_versions("1.73.0", "4eb3b8d442b426dc35346235c8733b5ae35ba431690e38c6a8263dce9fcbb402")
  11. add_versions("1.72.0", "59c9b274bc451cf91a9ba1dd2c7fdcaf5d60b1b3aa83f2c9fa143417cc660722")
  12. add_versions("1.70.0", "430ae8354789de4fd19ee52f3b1f739e1fba576f0aded0897c3c2bc00fb38778")
  13. if is_plat("linux") then
  14. add_deps("bzip2", "zlib")
  15. elseif is_plat("windows") then
  16. add_cxflags("/EHsc")
  17. end
  18. local libnames = {"filesystem",
  19. "fiber",
  20. "coroutine",
  21. "context",
  22. "thread",
  23. "regex",
  24. "system",
  25. "container",
  26. "exception",
  27. "timer",
  28. "atomic",
  29. "graph",
  30. "serialization",
  31. "random",
  32. "wave",
  33. "date_time",
  34. "locale",
  35. "iostreams"}
  36. add_configs("multi", { description = "Enable multi-thread support.", default = true, type = "boolean"})
  37. for _, libname in ipairs(libnames) do
  38. add_configs(libname, { description = "Enable " .. libname .. " library.", default = (libname == "filesystem"), type = "boolean"})
  39. end
  40. on_load("windows", function (package)
  41. local vs_runtime = package:config("vs_runtime")
  42. for _, libname in ipairs(libnames) do
  43. local linkname = "boost_" .. libname
  44. if package:config("multi") then
  45. linkname = linkname .. "-mt"
  46. end
  47. if package:config("shared") then
  48. if package:debug() then
  49. linkname = linkname .. "-gd"
  50. end
  51. elseif vs_runtime == "MT" then
  52. linkname = linkname .. "-s"
  53. elseif vs_runtime == "MTd" then
  54. linkname = linkname .. "-sgd"
  55. elseif vs_runtime == "MDd" then
  56. linkname = linkname .. "-gd"
  57. end
  58. package:add("links", linkname)
  59. end
  60. end)
  61. on_install("macosx", "linux", "windows", function (package)
  62. -- force boost to compile with the desired compiler
  63. local file = io.open("user-config.jam", "a")
  64. if file then
  65. if is_plat("macosx") then
  66. -- we uses ld/clang++ for link stdc++ for shared libraries
  67. file:print("using darwin : : %s ;", package:build_getenv("ld"))
  68. elseif is_plat("windows") then
  69. file:print("using msvc : : %s ;", os.args(package:build_getenv("cxx")))
  70. else
  71. file:print("using gcc : : %s ;", package:build_getenv("cxx"))
  72. end
  73. file:close()
  74. end
  75. local bootstrap_argv =
  76. {
  77. "--prefix=" .. package:installdir(),
  78. "--libdir=" .. package:installdir("lib"),
  79. "--without-icu"
  80. }
  81. if is_host("windows") then
  82. os.vrunv("bootstrap.bat", bootstrap_argv)
  83. else
  84. os.vrunv("./bootstrap.sh", bootstrap_argv)
  85. end
  86. os.vrun("./b2 headers")
  87. local argv =
  88. {
  89. "--prefix=" .. package:installdir(),
  90. "--libdir=" .. package:installdir("lib"),
  91. "-d2",
  92. "-j4",
  93. "--hash",
  94. "--layout=tagged-1.66",
  95. "--user-config=user-config.jam",
  96. "--no-cmake-config",
  97. "-sNO_LZMA=1",
  98. "-sNO_ZSTD=1",
  99. "install",
  100. "threading=" .. (package:config("multi") and "multi" or "single"),
  101. "debug-symbols=" .. (package:debug() and "on" or "off"),
  102. "link=" .. (package:config("shared") and "shared" or "static")
  103. }
  104. if package:is_arch("x64", "x86_64") then
  105. table.insert(argv, "address-model=64")
  106. else
  107. table.insert(argv, "address-model=32")
  108. end
  109. if package:is_plat("windows") then
  110. local vs_runtime = package:config("vs_runtime")
  111. if package:config("shared") then
  112. table.insert(argv, "runtime-link=shared")
  113. elseif vs_runtime and vs_runtime:startswith("MT") then
  114. table.insert(argv, "runtime-link=static")
  115. else
  116. table.insert(argv, "runtime-link=shared")
  117. end
  118. table.insert(argv, "cxxflags=-std:c++14")
  119. else
  120. table.insert(argv, "cxxflags=-std=c++14")
  121. if package:build_getenv("cxx"):find("clang", 1, true) then
  122. table.insert(argv, "cxxflags=-stdlib=libc++")
  123. table.insert(argv, "linkflags=-stdlib=libc++")
  124. end
  125. end
  126. for _, libname in ipairs(libnames) do
  127. if package:config(libname) then
  128. table.insert(argv, "--with-" .. libname)
  129. end
  130. end
  131. os.vrunv("./b2", argv)
  132. end)
  133. on_test(function (package)
  134. assert(package:check_cxxsnippets({test = [[
  135. #include <boost/algorithm/string.hpp>
  136. #include <string>
  137. #include <vector>
  138. #include <assert.h>
  139. using namespace boost::algorithm;
  140. using namespace std;
  141. static void test() {
  142. string str("a,b");
  143. vector<string> strVec;
  144. split(strVec, str, is_any_of(","));
  145. assert(strVec.size()==2);
  146. assert(strVec[0]=="a");
  147. assert(strVec[1]=="b");
  148. }
  149. ]]}, {configs = {languages = "c++14"}}))
  150. end)