install.lua 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. import("core.base.hashset")
  2. import("core.base.option")
  3. function _mangle_link_string(package)
  4. local link = "boost_"
  5. if package:is_plat("windows") and not package:config("shared") then
  6. link = "lib" .. link
  7. end
  8. return link
  9. end
  10. -- Only get package dep version in on_install
  11. function _add_links(package)
  12. local prefix = _mangle_link_string(package)
  13. local sub_libs_map = {
  14. test = {"prg_exec_monitor", "unit_test_framework"},
  15. serialization = {"wserialization", "serialization"},
  16. fiber = {"fiber", "fiber_numa"},
  17. log = {"log", "log_setup"},
  18. stacktrace = {
  19. "stacktrace_noop",
  20. "stacktrace_backtrace",
  21. "stacktrace_addr2line",
  22. "stacktrace_basic",
  23. "stacktrace_windbg",
  24. "stacktrace_windbg_cached",
  25. },
  26. }
  27. if package:config("python") then
  28. local py_ver = assert(package:dep("python"):version(), "Can't get python version")
  29. py_ver = py_ver:major() .. py_ver:minor()
  30. -- TODO: detect numpy
  31. sub_libs_map["python"] = {
  32. "python" .. py_ver,
  33. "numpy" .. py_ver,
  34. }
  35. end
  36. libs.for_each(function (libname)
  37. if not package:config(libname) then
  38. return
  39. end
  40. local sub_libs = sub_libs_map[libname]
  41. if sub_libs then
  42. for _, sub_libname in ipairs(sub_libs) do
  43. package:add("links", prefix .. sub_libname)
  44. end
  45. if libname == "test" then
  46. -- always static
  47. package:add("links", "libboost_test_exec_monitor")
  48. end
  49. else
  50. package:add("links", prefix .. libname)
  51. end
  52. end)
  53. end
  54. function _check_links(package)
  55. local lib_files = {}
  56. local links = hashset.from(table.wrap(package:get("links")))
  57. for _, libfile in ipairs(os.files(package:installdir("lib/*"))) do
  58. local link = path.basename(libfile)
  59. if not links:remove(link) then
  60. table.insert(lib_files, path.filename(libfile))
  61. end
  62. end
  63. links = links:to_array()
  64. if #links ~= 0 then
  65. -- TODO: Remove header only "link" or unsupported platform link
  66. wprint("Missing library files\n" .. table.concat(links, "\n"))
  67. end
  68. if #lib_files ~= 0 then
  69. wprint("Missing links\n" .. table.concat(lib_files, "\n"))
  70. end
  71. end
  72. function _add_iostreams_configs(package, configs)
  73. local iostreams_deps = {"zlib", "bzip2", "lzma", "zstd"}
  74. for _, dep in ipairs(iostreams_deps) do
  75. local config = format("-DBOOST_IOSTREAMS_ENABLE_%s=%s", dep:upper(), (package:config(dep) and "ON" or "OFF"))
  76. table.insert(configs, config)
  77. end
  78. end
  79. function _add_libs_configs(package, configs)
  80. if not package:config("all") then
  81. local header_only_buildable
  82. if package:is_headeronly() then
  83. header_only_buildable = hashset.from(libs.get_header_only_buildable())
  84. end
  85. local exclude_libs = {}
  86. libs.for_each(function (libname)
  87. if header_only_buildable and header_only_buildable:has(libname) then
  88. -- continue
  89. else
  90. if not package:config(libname) then
  91. table.insert(exclude_libs, libname)
  92. end
  93. end
  94. end)
  95. table.insert(configs, "-DBOOST_EXCLUDE_LIBRARIES=" .. table.concat(exclude_libs, ";"))
  96. end
  97. table.insert(configs, "-DBOOST_ENABLE_PYTHON=" .. (package:config("python") and "ON" or "OFF"))
  98. table.insert(configs, "-DBOOST_ENABLE_MPI=" .. (package:config("mpi") and "ON" or "OFF"))
  99. if package:config("locale") then
  100. table.insert(configs, "-DCMAKE_CXX_STANDARD=17")
  101. end
  102. _add_iostreams_configs(package, configs)
  103. local openssl = package:dep("openssl")
  104. if openssl and not openssl:is_system() then
  105. table.insert(configs, "-DOPENSSL_ROOT_DIR=" .. openssl:installdir())
  106. end
  107. end
  108. function _add_opt(package, opt)
  109. opt.cxflags = {}
  110. local lzma = package:dep("xz")
  111. if lzma and not lzma:config("shared") then
  112. table.insert(opt.cxflags, "-DLZMA_API_STATIC")
  113. end
  114. if package:has_tool("cxx", "cl") then
  115. table.insert(opt.cxflags, "/EHsc")
  116. end
  117. end
  118. function main(package)
  119. import("libs", {rootdir = package:scriptdir()})
  120. local configs = {"-DBOOST_INSTALL_LAYOUT=system"}
  121. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
  122. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  123. if package:is_plat("windows") then
  124. table.insert(configs, "-DCMAKE_COMPILE_PDB_OUTPUT_DIRECTORY=''")
  125. end
  126. _add_libs_configs(package, configs)
  127. if option.get("verbose") then
  128. table.insert(configs, "-DBoost_DEBUG=ON")
  129. end
  130. local opt = {}
  131. _add_opt(package, opt)
  132. import("package.tools.cmake").install(package, configs, opt)
  133. _add_links(package)
  134. if option.get("verbose") then
  135. _check_links(package)
  136. end
  137. end