From b95ae652a0d72b3e3cd1ceefafb9e733282ca59d Mon Sep 17 00:00:00 2001 From: Arthur LAURENT Date: Sun, 4 Feb 2024 18:58:36 +0100 Subject: [PATCH] support --sdk for --runtimes --- xmake/modules/core/tools/clang.lua | 40 ++++++++++++++++++------------ 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/xmake/modules/core/tools/clang.lua b/xmake/modules/core/tools/clang.lua index 1a7f25d335b..fe4641e778d 100644 --- a/xmake/modules/core/tools/clang.lua +++ b/xmake/modules/core/tools/clang.lua @@ -243,14 +243,18 @@ 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 + local llvm_rootdir + if get_config("sdk") then + -- if a sdk dir is defined, we should redirect include path to have the correct includes + llvm_rootdir = get_config("sdk") + elseif self:is_plat("windows") then + -- 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 + llvm_rootdir = _get_llvm_rootdir(self) + end + 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 elseif kind == "ld" or kind == "sh" then local target = opt.target @@ -259,14 +263,18 @@ 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 + local llvm_rootdir + if get_config("sdk") then + -- if a sdk dir is defined, we should redirect library path for linking the right libc++ + llvm_rootdir = get_config("sdk") + elseif self:is_plat("windows") then + -- 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 + llvm_rootdir = _get_llvm_rootdir(self) + end + 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 if runtime:endswith("_static") and _has_static_libstdcxx(self) then maps["c++_static"] = table.join(maps["c++_static"], "-static-libstdc++")