summaryrefslogtreecommitdiff
path: root/xmake
diff options
context:
space:
mode:
Diffstat (limited to 'xmake')
-rw-r--r--xmake/core/project/policy.lua2
-rw-r--r--xmake/modules/utils/archive/merge_staticlib.lua13
-rw-r--r--xmake/rules/utils/merge_archive/xmake.lua29
3 files changed, 35 insertions, 9 deletions
diff --git a/xmake/core/project/policy.lua b/xmake/core/project/policy.lua
index c624aed96..418d4d566 100644
--- a/xmake/core/project/policy.lua
+++ b/xmake/core/project/policy.lua
@@ -43,6 +43,8 @@ function policy.policies()
["check.target_package_licenses"] = {description = "Enable check the compatibility of target and package licenses.", default = true, type = "boolean"},
-- we can compile the source files for each target in parallel
["build.across_targets_in_parallel"] = {description = "Enable compile the source files for each target in parallel.", default = true, type = "boolean"},
+ -- merge archive intead of linking for all dependent targets
+ ["build.merge_archive"] = {description = "Enable merge archive intead of linking for all dependent targets.", default = false, type = "boolean"},
-- we need enable longpaths when building target or installing package
["platform.longpaths"] = {description = "Enable long paths when building target or installing package on windows.", default = false, type = "boolean"},
-- lock required packages
diff --git a/xmake/modules/utils/archive/merge_staticlib.lua b/xmake/modules/utils/archive/merge_staticlib.lua
index db72a8d97..8675f6c52 100644
--- a/xmake/modules/utils/archive/merge_staticlib.lua
+++ b/xmake/modules/utils/archive/merge_staticlib.lua
@@ -22,12 +22,17 @@
import("core.base.option")
-- merge *.a archive libraries for ar
-function _merge_for_ar(program, outputfile, libraryfiles, opt)
+function _merge_for_ar(target, program, outputfile, libraryfiles, opt)
opt = opt or {}
+ if target:is_plat("macosx") then
+ os.vrunv("libtool", table.join("-static", "-o", outputfile, libraryfiles))
+ else
+ os.vrunv(program, table.join("crsT", outputfile, libraryfiles))
+ end
end
-- merge *.a archive libraries for msvc/lib.exe
-function _merge_for_msvclib(program, outputfile, libraryfiles, opt)
+function _merge_for_msvclib(target, program, outputfile, libraryfiles, opt)
opt = opt or {}
end
@@ -36,7 +41,7 @@ function main(target, outputfile, libraryfiles)
local program, toolname = target:tool("ar")
if program and toolname then
if toolname:find("ar") then
- _merge_for_ar(program, outputfile, libraryfiles)
+ _merge_for_ar(target, program, outputfile, libraryfiles)
elseif toolname == "link" and target:is_plat("windows") then
local msvc
for _, toolchain_inst in ipairs(target:toolchains()) do
@@ -45,7 +50,7 @@ function main(target, outputfile, libraryfiles)
break
end
end
- _merge_for_msvclib((program:gsub("link%.exe", "lib.exe")), outputfile, libraryfiles, {envs = msvc and msvc:runenvs()})
+ _merge_for_msvclib(target, (program:gsub("link%.exe", "lib.exe")), outputfile, libraryfiles, {envs = msvc and msvc:runenvs()})
else
raise("cannot merge (%s): unknown ar tool %s!", table.concat(libraryfiles, ", "), toolname)
end
diff --git a/xmake/rules/utils/merge_archive/xmake.lua b/xmake/rules/utils/merge_archive/xmake.lua
index 6d57f55bb..63c947d08 100644
--- a/xmake/rules/utils/merge_archive/xmake.lua
+++ b/xmake/rules/utils/merge_archive/xmake.lua
@@ -18,12 +18,31 @@
-- @file xmake.lua
--
--- define rule: utils.merge.archive
rule("utils.merge.archive")
-
- -- set extensions
set_extensions(".a", ".lib")
-
- -- on build file
on_build_files("merge_archive")
+ after_link(function (target, opt)
+ if target:policy("build.merge_archive") and target:is_static() then
+ import("utils.archive.merge_staticlib")
+ import("core.project.depend")
+ import("private.utils.progress")
+ local libraryfiles = {}
+ for _, dep in ipairs(target:orderdeps()) do
+ if dep:is_static() then
+ table.insert(libraryfiles, dep:targetfile())
+ end
+ end
+ if #libraryfiles > 0 then
+ table.insert(libraryfiles, target:targetfile())
+ end
+ depend.on_changed(function ()
+ progress.show(opt.progress, "${color.build.target}merging.$(mode) %s", path.filename(target:targetfile()))
+ if #libraryfiles > 0 then
+ local tmpfile = os.tmpfile() .. path.extension(target:targetfile())
+ merge_staticlib(target, tmpfile, libraryfiles)
+ os.mv(tmpfile, target:targetfile())
+ end
+ end, {dependfile = target:dependfile(target:targetfile() .. ".merge_archive"), files = libraryfiles})
+ end
+ end)