install.lua 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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 = libs.get_sub_libs(package)
  14. libs.for_each(function (libname)
  15. if not package:config(libname) then
  16. return
  17. end
  18. local sub_libs = sub_libs_map[libname]
  19. if sub_libs then
  20. for _, sub_libname in ipairs(sub_libs) do
  21. package:add("links", prefix .. sub_libname)
  22. end
  23. if libname == "test" then
  24. -- always static
  25. package:add("links", "libboost_test_exec_monitor")
  26. end
  27. else
  28. package:add("links", prefix .. libname)
  29. end
  30. end)
  31. end
  32. function _check_links(package)
  33. local lib_files = {}
  34. local links = hashset.from(table.wrap(package:get("links")))
  35. for _, libfile in ipairs(os.files(package:installdir("lib/*"))) do
  36. local link = path.basename(libfile)
  37. if not links:remove(link) then
  38. table.insert(lib_files, path.filename(libfile))
  39. end
  40. end
  41. links = links:to_array()
  42. if #links ~= 0 then
  43. -- TODO: Remove header only "link" or unsupported platform link
  44. wprint("Missing library files\n" .. table.concat(links, "\n"))
  45. end
  46. if #lib_files ~= 0 then
  47. wprint("Missing links\n" .. table.concat(lib_files, "\n"))
  48. end
  49. end
  50. function _add_iostreams_configs(package, configs)
  51. local iostreams_deps = {"zlib", "bzip2", "lzma", "zstd"}
  52. for _, dep in ipairs(iostreams_deps) do
  53. local config = format("-DBOOST_IOSTREAMS_ENABLE_%s=%s", dep:upper(), (package:config(dep) and "ON" or "OFF"))
  54. table.insert(configs, config)
  55. end
  56. end
  57. function _add_libs_configs(package, configs)
  58. if not package:config("all") then
  59. local header_only_buildable
  60. if package:is_headeronly() then
  61. header_only_buildable = hashset.from(libs.get_header_only_buildable())
  62. end
  63. local exclude_libs = {}
  64. libs.for_each(function (libname)
  65. if header_only_buildable and header_only_buildable:has(libname) then
  66. -- continue
  67. else
  68. if not package:config(libname) then
  69. table.insert(exclude_libs, libname)
  70. end
  71. end
  72. end)
  73. table.insert(configs, "-DBOOST_EXCLUDE_LIBRARIES=" .. table.concat(exclude_libs, ";"))
  74. end
  75. table.insert(configs, "-DBOOST_ENABLE_PYTHON=" .. (package:config("python") and "ON" or "OFF"))
  76. table.insert(configs, "-DBOOST_ENABLE_MPI=" .. (package:config("mpi") and "ON" or "OFF"))
  77. if package:config("locale") then
  78. table.insert(configs, "-DCMAKE_CXX_STANDARD=17")
  79. table.insert(configs, "-DBOOST_LOCALE_ENABLE_ICU=" .. (package:config("icu") and "ON" or "OFF"))
  80. end
  81. _add_iostreams_configs(package, configs)
  82. local openssl = package:dep("openssl")
  83. if openssl and not openssl:is_system() then
  84. table.insert(configs, "-DOPENSSL_ROOT_DIR=" .. openssl:installdir())
  85. end
  86. end
  87. function _add_opt(package, opt)
  88. opt.cxflags = {}
  89. local lzma = package:dep("xz")
  90. if lzma and not lzma:config("shared") then
  91. table.insert(opt.cxflags, "-DLZMA_API_STATIC")
  92. end
  93. if package:has_tool("cxx", "cl") then
  94. table.insert(opt.cxflags, "/EHsc")
  95. end
  96. end
  97. function main(package)
  98. import("libs", {rootdir = package:scriptdir()})
  99. local configs = {"-DBOOST_INSTALL_LAYOUT=system"}
  100. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
  101. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  102. _add_libs_configs(package, configs)
  103. if option.get("verbose") then
  104. table.insert(configs, "-DBoost_DEBUG=ON")
  105. end
  106. local opt = {}
  107. _add_opt(package, opt)
  108. import("package.tools.cmake").install(package, configs, opt)
  109. _add_links(package)
  110. if option.get("verbose") then
  111. _check_links(package)
  112. end
  113. end