diff --git a/packages/b/boost/cmake/install.lua b/packages/b/boost/cmake/install.lua index cf7278f0d..98ede1411 100644 --- a/packages/b/boost/cmake/install.lua +++ b/packages/b/boost/cmake/install.lua @@ -11,31 +11,7 @@ end -- Only get package dep version in on_install function _add_links(package) local prefix = _mangle_link_string(package) - - local sub_libs_map = { - test = {"prg_exec_monitor", "unit_test_framework"}, - serialization = {"wserialization", "serialization"}, - fiber = {"fiber", "fiber_numa"}, - log = {"log", "log_setup"}, - stacktrace = { - "stacktrace_noop", - "stacktrace_backtrace", - "stacktrace_addr2line", - "stacktrace_basic", - "stacktrace_windbg", - "stacktrace_windbg_cached", - }, - } - - if package:config("python") then - local py_ver = assert(package:dep("python"):version(), "Can't get python version") - py_ver = py_ver:major() .. py_ver:minor() - -- TODO: detect numpy - sub_libs_map["python"] = { - "python" .. py_ver, - "numpy" .. py_ver, - } - end + local sub_libs_map = libs.get_sub_libs(package) libs.for_each(function (libname) if not package:config(libname) then diff --git a/packages/b/boost/fetch.lua b/packages/b/boost/fetch.lua new file mode 100644 index 000000000..289b1bedc --- /dev/null +++ b/packages/b/boost/fetch.lua @@ -0,0 +1,73 @@ +import("lib.detect.find_library") +import("lib.detect.find_tool") +import("core.base.semver") + +function _get_python_libs() + local opt = {version = true} + local result = find_tool("python3", opt) + if not result then + result = find_tool("python", opt) + end + + local libs = {} + local version = result.version + if version then + local py_ver = semver.new(version) + py_ver = py_ver:major() .. py_ver:minor() + table.insert(libs, "python" .. py_ver) + table.insert(libs, "numpy" .. py_ver) + end + return libs +end + +function _add_info(linkinfo, result) + if linkinfo then + table.insert(result.linkdirs, linkinfo.linkdir) + table.insert(result.libfiles, linkinfo.filename) + table.insert(result.links, linkinfo.link) + end +end + +function main(package, opt) + if opt.system then + import("libs", {rootdir = package:scriptdir()}) + + local paths = { + "/usr/lib", + "/usr/lib64", + "/usr/local/lib", + "/usr/lib/x86_64-linux-gnu", + } + + local result = { + libfiles = {}, + linkdirs = {}, + links = {}, + } + + local opt = { + plat = package:plat(), + kind = package:config("shared") and "shared" or "static", + } + + local sub_libs_map = libs.get_sub_libs(package) + sub_libs_map["python"] = _get_python_libs() + table.insert(sub_libs_map.test, "test_exec_monitor") + + libs.for_each(function (libname) + local sub_libs = sub_libs_map[libname] + if sub_libs then + for _, sub_libname in ipairs(sub_libs) do + local linkinfo = find_library("boost_" .. sub_libname, paths, opt) + _add_info(linkinfo, result) + end + else + local linkinfo = find_library("boost_" .. libname, paths, opt) + _add_info(linkinfo, result) + end + end) + + result.linkdirs = table.unique(result.linkdirs) + return result + end +end diff --git a/packages/b/boost/libs.lua b/packages/b/boost/libs.lua index 00759472f..cd4762b7d 100644 --- a/packages/b/boost/libs.lua +++ b/packages/b/boost/libs.lua @@ -189,3 +189,32 @@ function for_each_lib_deps(lambda) lambda(libname, deps) end end + +function get_sub_libs(package) + local sub_libs_map = { + test = {"prg_exec_monitor", "unit_test_framework"}, + serialization = {"wserialization", "serialization"}, + fiber = {"fiber", "fiber_numa"}, + log = {"log", "log_setup"}, + stacktrace = { + "stacktrace_noop", + "stacktrace_backtrace", + "stacktrace_addr2line", + "stacktrace_basic", + "stacktrace_windbg", + "stacktrace_windbg_cached", + }, + } + + if package:config("python") then + local py_ver = assert(package:dep("python"):version(), "Can't get python version") + py_ver = py_ver:major() .. py_ver:minor() + -- TODO: detect numpy + sub_libs_map["python"] = { + "python" .. py_ver, + "numpy" .. py_ver, + } + end + + return sub_libs_map +end diff --git a/packages/b/boost/xmake.lua b/packages/b/boost/xmake.lua index cd9053c80..b0ce0376d 100644 --- a/packages/b/boost/xmake.lua +++ b/packages/b/boost/xmake.lua @@ -63,6 +63,8 @@ package("boost") add_syslinks("pthread", "dl") end + on_fetch("fetch") + if on_check then on_check(function (package) if not package:is_plat("macosx", "linux", "windows", "bsd", "mingw", "cross") then