summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2024-02-04 00:28:45 +0800
committerGitHub <[email protected]>2024-02-04 00:28:45 +0800
commitd4514c86f937cda6d4ba19c661d7136ce4c3f5ee (patch)
treef30c7a87e661cecf86ba9cdcaa6de2e8599dc8d9
parent3872b4d2b245a0283db617821348fda1504f1322 (diff)
Update clang.lua
-rw-r--r--xmake/modules/core/tools/clang.lua30
1 files changed, 16 insertions, 14 deletions
diff --git a/xmake/modules/core/tools/clang.lua b/xmake/modules/core/tools/clang.lua
index 7915af499..a62da204e 100644
--- a/xmake/modules/core/tools/clang.lua
+++ b/xmake/modules/core/tools/clang.lua
@@ -1,3 +1,4 @@
+
--!A cross-platform build utility based on Lua
--
-- Licensed under the Apache License, Version 2.0 (the "License");
@@ -191,16 +192,17 @@ function _has_static_libstdcxx(self)
return has_static_libstdcxx
end
-function _get_llvm_path(self)
- local llvm_path = _g._LLVM_PATH
- if llvm_path == nil then
- local out, _ = try { function() return os.iorun(self:program() .. " -print-resource-dir") end }
- if out then
- llvm_path = path.normalize(path.join(out, "..", "..", ".."))
+-- 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(), "..", "..", ".."))
end
- _g._LLVM_PATH = llvm_path or false
+ _g._LLVM_ROOTDIR = llvm_rootdir or false
end
- return llvm_path
+ return llvm_rootdir or nil
end
-- make the runtime flag
@@ -209,7 +211,6 @@ function nf_runtime(self, runtime, opt)
opt = opt or {}
local maps
local kind = self:kind()
- local clang_path = _get_llvm_path(self)
if self:is_plat("windows") and runtime then
if not _has_ms_runtime_lib(self) then
if runtime:startswith("MD") then
@@ -243,8 +244,9 @@ function nf_runtime(self, runtime, opt)
-- 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
- maps["c++_static"] = table.join(maps["c++_static"], "-cxx-isystem" .. path.join(clang_path, "include", "c++", "v1"))
- maps["c++_shared"] = table.join(maps["c++_shared"], "-cxx-isystem" .. path.join(clang_path, "include", "c++", "v1"))
+ local llvm_rootdir = _get_llvm_rootdir(self)
+ 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
elseif kind == "ld" or kind == "sh" then
local target = opt.target
@@ -256,8 +258,9 @@ function nf_runtime(self, runtime, opt)
-- 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
- maps["c++_static"] = table.join(maps["c++_static"], "-L" .. path.join(clang_path, "lib"))
- maps["c++_shared"] = table.join(maps["c++_shared"], "-L" .. path.join(clang_path, "lib"))
+ local llvm_rootdir = _get_llvm_rootdir(self)
+ 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
if runtime:endswith("_static") and _has_static_libstdcxx(self) then
maps["c++_static"] = table.join(maps["c++_static"], "-static-libstdc++")
@@ -268,4 +271,3 @@ function nf_runtime(self, runtime, opt)
end
return maps and maps[runtime]
end
-