summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2024-01-22 22:33:01 +0800
committerruki <[email protected]>2024-01-25 12:09:58 +0800
commit5d2f15a1004be7baaaeb08b2e196ad77c52f9647 (patch)
tree95e24fb92cf22cbbf20deb66b5a5cf68b8686ed4
parentbda43e3e865e2336db2bdf2b66af9beb235da1df (diff)
improve clang runtime
-rw-r--r--xmake/core/project/target.lua2
-rw-r--r--xmake/modules/core/tools/cl.lua14
-rw-r--r--xmake/modules/core/tools/clang.lua32
-rw-r--r--xmake/modules/core/tools/link.lua6
-rw-r--r--xmake/modules/core/tools/nvcc.lua8
5 files changed, 46 insertions, 16 deletions
diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua
index fd8421051..19f19e664 100644
--- a/xmake/core/project/target.lua
+++ b/xmake/core/project/target.lua
@@ -2390,7 +2390,7 @@ function _instance:runtimes()
elseif self:is_plat("android") then
runtimes = runtimes or config.get("ndk_cxxstl")
end
- if runtimes then
+ if type(runtimes) == "string" then
runtimes = runtimes:split(",", {plain = true})
if #runtimes > 0 then
runtimes = table.unwrap(runtimes)
diff --git a/xmake/modules/core/tools/cl.lua b/xmake/modules/core/tools/cl.lua
index 2d267f508..799596ab7 100644
--- a/xmake/modules/core/tools/cl.lua
+++ b/xmake/modules/core/tools/cl.lua
@@ -184,10 +184,16 @@ function nf_optimize(self, level)
return maps[level]
end
--- make vs runtime flag
-function nf_runtime(self, vs_runtime)
- if vs_runtime then
- return "-" .. vs_runtime
+-- make the runtime flag
+function nf_runtime(self, runtime)
+ if runtime then
+ local maps = {
+ MT = "-MT",
+ MD = "-MD",
+ MTd = "-MTd",
+ MDd = "-MDd"
+ }
+ return maps[runtime]
end
end
diff --git a/xmake/modules/core/tools/clang.lua b/xmake/modules/core/tools/clang.lua
index 28a00d84f..c9c6b854d 100644
--- a/xmake/modules/core/tools/clang.lua
+++ b/xmake/modules/core/tools/clang.lua
@@ -178,18 +178,18 @@ function _has_ms_runtime_lib(self)
return has_ms_runtime_lib
end
--- make vs runtime flag
+-- make the runtime flag
-- @see https://github.com/xmake-io/xmake/issues/3546
-function nf_runtime(self, vs_runtime)
- if self:is_plat("windows") and vs_runtime then
+function nf_runtime(self, runtime)
+ local kind = self:kind()
+ if self:is_plat("windows") and runtime then
if not _has_ms_runtime_lib(self) then
- if vs_runtime:startswith("MD") then
- wprint("%s runtime is not available for the current Clang compiler.", vs_runtime)
+ if runtime:startswith("MD") then
+ wprint("%s runtime is not available for the current Clang compiler.", runtime)
end
return
end
local maps
- local kind = self:kind()
if language.sourcekinds()[kind] then
maps = {
MT = "-fms-runtime-lib=static",
@@ -205,7 +205,25 @@ function nf_runtime(self, vs_runtime)
MDd = "-nostdlib"
}
end
- return maps and maps[vs_runtime]
+ return maps and maps[runtime]
+ else
+ local maps
+ if kind == "cxx" then
+ maps = {
+ ["c++_static"] = "-stdlib=libc++",
+ ["c++_shared"] = "-stdlib=libc++",
+ ["stdc++_static"] = "-stdlib=libstdc++",
+ ["stdc++_shared"] = "-stdlib=libstdc++",
+ }
+ else
+ maps = {
+ ["c++_static"] = {"-stdlib=libc++", "-static-libstdc++"},
+ ["c++_shared"] = "-stdlib=libc++",
+ ["stdc++_static"] = {"-stdlib=libstdc++", "-static-libstdc++"},
+ ["stdc++_shared"] = "-stdlib=libstdc++",
+ }
+ end
+ return maps and maps[runtime]
end
end
diff --git a/xmake/modules/core/tools/link.lua b/xmake/modules/core/tools/link.lua
index 9c53c2e28..a144d515e 100644
--- a/xmake/modules/core/tools/link.lua
+++ b/xmake/modules/core/tools/link.lua
@@ -113,9 +113,9 @@ function nf_syslink(self, lib)
return nf_link(self, lib)
end
--- make vs runtime flag
-function nf_runtime(self, vs_runtime)
- if vs_runtime and vs_runtime:startswith("MT") then
+-- make the runtime flag
+function nf_runtime(self, runtime)
+ if runtime and runtime:startswith("MT") then
return "-nodefaultlib:msvcrt.lib"
end
end
diff --git a/xmake/modules/core/tools/nvcc.lua b/xmake/modules/core/tools/nvcc.lua
index e67dc0749..3d23c0998 100644
--- a/xmake/modules/core/tools/nvcc.lua
+++ b/xmake/modules/core/tools/nvcc.lua
@@ -172,7 +172,13 @@ end
-- make vs runtime flag
function nf_runtime(self, vs_runtime)
if self:is_plat("windows") and vs_runtime then
- return '-Xcompiler "-' .. vs_runtime .. '"'
+ local maps = {
+ MT = '-Xcompiler "-MT"',
+ MD = '-Xcompiler "-MD"',
+ MTd = '-Xcompiler "-MTd"',
+ MDd = '-Xcompiler "-MDd"'
+ }
+ return maps[vs_runtime]
end
end