diff options
| author | ruki <[email protected]> | 2024-01-26 23:01:44 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-01-26 23:01:44 +0800 |
| commit | fd85ae0a81de712ca3837b262e936fd67b8f483f (patch) | |
| tree | 97894c8d36a17ca6437aedd10400b8f24574d783 /xmake/modules/core/tools | |
| parent | 042362f4c3f1dab8b6b5a32fcbbae20e66e224de (diff) | |
| parent | 2a43a89241ff5044661fa7449d6455386cd3a449 (diff) | |
Merge pull request #4630 from xmake-io/runtimes
Improve runtimes to support libc++/libstdc++
Diffstat (limited to 'xmake/modules/core/tools')
| -rw-r--r-- | xmake/modules/core/tools/cl.lua | 14 | ||||
| -rw-r--r-- | xmake/modules/core/tools/clang.lua | 54 | ||||
| -rw-r--r-- | xmake/modules/core/tools/link.lua | 6 | ||||
| -rw-r--r-- | xmake/modules/core/tools/nvcc.lua | 12 |
4 files changed, 69 insertions, 17 deletions
diff --git a/xmake/modules/core/tools/cl.lua b/xmake/modules/core/tools/cl.lua index 2d60f2a1b..18f6ee868 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..313728894 100644 --- a/xmake/modules/core/tools/clang.lua +++ b/xmake/modules/core/tools/clang.lua @@ -178,18 +178,33 @@ function _has_ms_runtime_lib(self) return has_ms_runtime_lib end --- make vs runtime flag +-- has -static-libstdc++? +function _has_static_libstdcxx(self) + local has_static_libstdcxx = _g._HAS_STATIC_LIBSTDCXX + if has_static_libstdcxx == nil then + if self:has_flags("-static-libstdc++ -Werror", "ldflags", {flagskey = "clang_static_libstdcxx"}) then + has_static_libstdcxx = true + end + has_static_libstdcxx = has_static_libstdcxx or false + _g._HAS_STATIC_LIBSTDCXX = has_static_libstdcxx + end + return has_static_libstdcxx +end + + +-- 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, opt) + opt = opt or {} + 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 +220,32 @@ function nf_runtime(self, vs_runtime) MDd = "-nostdlib" } end - return maps and maps[vs_runtime] + return maps and maps[runtime] + elseif not self:is_plat("android") then -- we will set runtimes in android ndk toolchain + local maps + if kind == "cxx" then + maps = { + ["c++_static"] = "-stdlib=libc++", + ["c++_shared"] = "-stdlib=libc++", + ["stdc++_static"] = "-stdlib=libstdc++", + ["stdc++_shared"] = "-stdlib=libstdc++", + } + 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 + maps = { + ["c++_static"] = "-stdlib=libc++", + ["c++_shared"] = "-stdlib=libc++", + ["stdc++_static"] = "-stdlib=libstdc++", + ["stdc++_shared"] = "-stdlib=libstdc++", + } + if runtime:endswith("_static") and _has_static_libstdcxx(self) then + maps["c++_static"] = table.join(maps["c++_static"], "-static-libstdc++") + maps["stdc++_static"] = table.join(maps["stdc++_static"], "-static-libstdc++") + end + end + 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 604fbe505..127f51656 100644 --- a/xmake/modules/core/tools/nvcc.lua +++ b/xmake/modules/core/tools/nvcc.lua @@ -171,9 +171,15 @@ function nf_optimize(self, level) end -- make vs runtime flag -function nf_runtime(self, vs_runtime) - if self:is_plat("windows") and vs_runtime then - return '-Xcompiler "-' .. vs_runtime .. '"' +function nf_runtime(self, runtime) + if self:is_plat("windows") and runtime then + local maps = { + MT = '-Xcompiler "-MT"', + MD = '-Xcompiler "-MD"', + MTd = '-Xcompiler "-MTd"', + MDd = '-Xcompiler "-MDd"' + } + return maps[runtime] end end |
