diff options
| -rw-r--r-- | xmake/modules/core/tools/clang.lua | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/xmake/modules/core/tools/clang.lua b/xmake/modules/core/tools/clang.lua index 673500599..a34487686 100644 --- a/xmake/modules/core/tools/clang.lua +++ b/xmake/modules/core/tools/clang.lua @@ -178,6 +178,20 @@ function _has_ms_runtime_lib(self) return has_ms_runtime_lib end +-- 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, runtime) @@ -217,11 +231,15 @@ function nf_runtime(self, runtime) } else maps = { - ["c++_static"] = {"-stdlib=libc++", "-static-libstdc++"}, + ["c++_static"] = "-stdlib=libc++", ["c++_shared"] = "-stdlib=libc++", - ["stdc++_static"] = {"-stdlib=libstdc++", "-static-libstdc++"}, + ["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 return maps and maps[runtime] end |
