diff options
| author | ruki <[email protected]> | 2024-02-04 09:01:45 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-02-04 09:01:45 +0800 |
| commit | 54d678da728afa5805819082b8afbe198c2a0180 (patch) | |
| tree | f03045542994f109bd1ecf21c61e748473bee352 | |
| parent | 0beb1080c48f4cc32e2f706300a1993614458a33 (diff) | |
| parent | 9f47d4543b03127c08923568a37e0f1b3f2ed44c (diff) | |
Merge pull request #4681 from Arthapz/fix-libcppruntime-windows
fix libc++ support on windows
| -rw-r--r-- | xmake/modules/core/tools/clang.lua | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/xmake/modules/core/tools/clang.lua b/xmake/modules/core/tools/clang.lua index 763a87f41..1a7f25d33 100644 --- a/xmake/modules/core/tools/clang.lua +++ b/xmake/modules/core/tools/clang.lua @@ -191,6 +191,21 @@ function _has_static_libstdcxx(self) return has_static_libstdcxx end +-- get llvm sdk root directory +function _get_llvm_rootdir(self) + local llvm_rootdir = _g._LLVM_ROOTDIR + if llvm_rootdir == nil then + local outdata = try { function() return os.iorun(self:program() .. " -print-resource-dir") end } + if outdata then + llvm_rootdir = path.normalize(path.join(outdata:trim(), "..", "..", "..")) + if not os.isdir(llvm_rootdir) then + llvm_rootdir = nil + end + end + _g._LLVM_ROOTDIR = llvm_rootdir or false + end + return llvm_rootdir or nil +end -- make the runtime flag -- @see https://github.com/xmake-io/xmake/issues/3546 @@ -228,6 +243,15 @@ function nf_runtime(self, runtime, opt) maps["c++_shared"] = "-stdlib=libc++" maps["stdc++_static"] = "-stdlib=libstdc++" maps["stdc++_shared"] = "-stdlib=libstdc++" + -- clang on windows fail to add libc++ includepath when using -stdlib=libc++ so we manually add it + -- @see https://github.com/llvm/llvm-project/issues/79647 + if self:is_plat("windows") then + local llvm_rootdir = _get_llvm_rootdir(self) + if llvm_rootdir then + maps["c++_static"] = table.join(maps["c++_static"], "-cxx-isystem" .. path.join(llvm_rootdir, "include", "c++", "v1")) + maps["c++_shared"] = table.join(maps["c++_shared"], "-cxx-isystem" .. path.join(llvm_rootdir, "include", "c++", "v1")) + end + 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 @@ -235,6 +259,15 @@ function nf_runtime(self, runtime, opt) maps["c++_shared"] = "-stdlib=libc++" maps["stdc++_static"] = "-stdlib=libstdc++" maps["stdc++_shared"] = "-stdlib=libstdc++" + -- clang on windows fail to add libc++ librarypath when using -stdlib=libc++ so we manually add it + -- @see https://github.com/llvm/llvm-project/issues/79647 + if self:is_plat("windows") then + local llvm_rootdir = _get_llvm_rootdir(self) + if llvm_rootdir then + maps["c++_static"] = table.join(maps["c++_static"], "-L" .. path.join(llvm_rootdir, "lib")) + maps["c++_shared"] = table.join(maps["c++_shared"], "-L" .. path.join(llvm_rootdir, "lib")) + end + end 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++") @@ -244,4 +277,3 @@ function nf_runtime(self, runtime, opt) end return maps and maps[runtime] end - |
