summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArthur LAURENT <[email protected]>2024-04-03 04:49:45 +0200
committerArthur LAURENT <[email protected]>2024-04-03 05:26:12 +0200
commit3319219a1a2fc26520f0e1760d953e9c0352a91b (patch)
treed880f343790fbe11fb9864e64cb039e817f70760
parent13b1dda53dfe34b24982f1f3c436a860fd257aa1 (diff)
apply runtime to package targets (for check_cxxsnippet support)
-rw-r--r--xmake/core/package/package.lua56
-rw-r--r--xmake/modules/core/tools/clang.lua5
2 files changed, 41 insertions, 20 deletions
diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua
index 4fbfa635a..014d8a82a 100644
--- a/xmake/core/package/package.lua
+++ b/xmake/core/package/package.lua
@@ -39,6 +39,7 @@ local is_cross = require("base/private/is_cross")
local memcache = require("cache/memcache")
local toolchain = require("tool/toolchain")
local compiler = require("tool/compiler")
+local linker = require("tool/linker")
local sandbox = require("sandbox/sandbox")
local config = require("project/config")
local policy = require("project/policy")
@@ -2268,27 +2269,46 @@ end
function _instance:_generate_build_configs(configs, opt)
opt = opt or {}
configs = table.join(self:fetch_librarydeps(), configs)
- if self:is_plat("windows") then
- local ld = self:build_getenv("ld")
- local runtimes = self:runtimes()
- -- since we are ignoring the runtimes of the headeronly library,
- -- we can only get the runtimes from the dependency library to detect the link.
- if self:is_headeronly() and not runtimes and self:librarydeps() then
- for _, dep in ipairs(self:librarydeps()) do
- if dep:is_plat("windows") and dep:runtimes() then
- runtimes = dep:runtimes()
- break
- end
+ -- since we are ignoring the runtimes of the headeronly library,
+ -- we can only get the runtimes from the dependency library to detect the link.
+ local runtimes = self:config("runtimes") or self:runtimes()
+ if self:is_headeronly() and not runtimes and self:librarydeps() then
+ for _, dep in ipairs(self:librarydeps()) do
+ if dep:is_plat("windows") and dep:runtimes() then
+ runtimes = dep:runtimes()
+ break
end
end
- if runtimes and ld and path.basename(ld:lower()) == "link" then -- for msvc?
- configs.cxflags = table.wrap(configs.cxflags)
- table.insert(configs.cxflags, "/" .. runtimes)
- if runtimes:startswith("MT") then
- configs.ldflags = table.wrap(configs.ldflags)
- table.insert(configs.ldflags, "-nodefaultlib:msvcrt.lib")
- end
+ end
+ if runtimes then
+ local sourcekind = opt.sourcekind or "cxx"
+ local tool, name = self:tool("ld")
+ local linker, errors = linker.load("binary", sourcekind, {target = package})
+ if not linker then
+ os.raise(errors)
end
+ local fake_target = {is_shared = function(_) return false end,
+ sourcekinds = function(_) return sourcekind end}
+ local compiler = self:compiler(sourcekind)
+ local cxflags = compiler:map_flags("runtime", runtimes, {target = fake_target})
+ configs.cxflags = table.wrap(configs.cxflags)
+ table.join2(configs.cxflags, cxflags)
+
+ local ldflags = linker:map_flags("runtime", runtimes, {target = fake_target})
+ configs.ldflags = table.wrap(configs.ldflags)
+ table.join2(configs.ldflags, ldflags)
+
+ -- if self:is_plat("windows") then
+ -- local ld = self:build_getenv("ld")
+ -- if ld and path.basename(ld:lower()) == "link" then -- for msvc?
+ -- configs.cxflags = table.wrap(configs.cxflags)
+ -- table.insert(configs.cxflags, "/" .. runtimes)
+ -- if runtimes:startswith("MT") then
+ -- configs.ldflags = table.wrap(configs.ldflags)
+ -- table.insert(configs.ldflags, "-nodefaultlib:msvcrt.lib")
+ -- end
+ -- end
+ -- end
end
if self:config("lto") then
local configs_lto = self:_generate_lto_configs(opt.sourcekind or "cxx")
diff --git a/xmake/modules/core/tools/clang.lua b/xmake/modules/core/tools/clang.lua
index 76f553829..76a1f773b 100644
--- a/xmake/modules/core/tools/clang.lua
+++ b/xmake/modules/core/tools/clang.lua
@@ -268,8 +268,9 @@ function nf_runtime(self, runtime, opt)
maps["c++_shared"] = table.join(maps["c++_shared"], "-cxx-isystem" .. path.join(llvm_rootdir, "include", "c++", "v1"))
end
elseif kind == "ld" or kind == "sh" then
- local target = opt.target
- if target and target.sourcekinds and table.contains(table.wrap(target:sourcekinds()), "cxx") then
+ local target = opt.target or opt
+ local is_cxx = target and (target.sourcekinds and table.contains(table.wrap(target:sourcekinds()), "cxx"))
+ if is_cxx then
maps["c++_static"] = "-stdlib=libc++"
maps["c++_shared"] = "-stdlib=libc++"
maps["stdc++_static"] = "-stdlib=libstdc++"