summaryrefslogtreecommitdiff
path: root/xmake/rules/c++/modules
diff options
context:
space:
mode:
authorArthur LAURENT <[email protected]>2024-01-30 13:11:25 +0100
committerArthur LAURENT <[email protected]>2024-01-30 13:11:25 +0100
commita9f30404cab3daee8dd92f4e815941b66047166a (patch)
tree5ab713b6cb6d2d1a984bf8a802821b914615c676 /xmake/rules/c++/modules
parent0ff527aa2d4d4c318d5041d043327f4e70767c0a (diff)
use -fkeep-system-includes only if supported by underlying clang
Diffstat (limited to 'xmake/rules/c++/modules')
-rw-r--r--xmake/rules/c++/modules/modules_support/clang/compiler_support.lua14
-rw-r--r--xmake/rules/c++/modules/modules_support/clang/dependency_scanner.lua3
2 files changed, 16 insertions, 1 deletions
diff --git a/xmake/rules/c++/modules/modules_support/clang/compiler_support.lua b/xmake/rules/c++/modules/modules_support/clang/compiler_support.lua
index 6e4b36645..6cd5270dc 100644
--- a/xmake/rules/c++/modules/modules_support/clang/compiler_support.lua
+++ b/xmake/rules/c++/modules/modules_support/clang/compiler_support.lua
@@ -372,6 +372,20 @@ function has_clangscandepssupport(target)
return support_clangscandeps or nil
end
+function get_keepsystemincludesflag(target)
+ local keepsystemincludesflag = _g.keepsystemincludesflag
+ if keepsystemincludesflag == nil then
+ local compinst = target:compiler("cxx")
+ local clang_version = get_clang_version(target)
+ if compinst:has_flags("-fkeep-system-includes", "cxxflags", {flagskey = "clang_keep_system_includes", tryrun = true}) and
+ semver.compare(clang_version, "18.0") >= 0 then
+ keepsystemincludesflag = "-fkeep-system-includes"
+ end
+ _g.keepsystemincludesflag = keepsystemincludesflag or false
+ end
+ return keepsystemincludesflag or nil
+end
+
function get_moduleoutputflag(target)
local moduleoutputflag = _g.moduleoutputflag
if moduleoutputflag == nil then
diff --git a/xmake/rules/c++/modules/modules_support/clang/dependency_scanner.lua b/xmake/rules/c++/modules/modules_support/clang/dependency_scanner.lua
index 71ccabb72..6f78b3a41 100644
--- a/xmake/rules/c++/modules/modules_support/clang/dependency_scanner.lua
+++ b/xmake/rules/c++/modules/modules_support/clang/dependency_scanner.lua
@@ -57,6 +57,7 @@ function generate_dependencies(target, sourcebatch, opt)
io.writefile(jsonfile, outdata)
else
fallback_generate_dependencies(target, jsonfile, sourcefile, function(file)
+ local keepsystemincludesflag = compiler_support.get_keepsystemincludesflag(target)
local compflags = compinst:compflags({sourcefile = file, target = target})
-- exclude -fmodule* and -std=c++/gnu++* flags because,
-- when they are set clang try to find bmi of imported modules but they don't exists a this point of compilation
@@ -64,7 +65,7 @@ function generate_dependencies(target, sourcebatch, opt)
return flag:startswith("-fmodule") or flag:startswith("-std=c++") or flag:startswith("-std=gnu++")
end)
local ifile = path.translate(path.join(outputdir, path.filename(file) .. ".i"))
- local flags = table.join(compflags or {}, {"-E", runtime_flag, "-fkeep-system-includes", "-x", "c++", file, "-o", ifile})
+ local flags = table.join(compflags or {}, keepsystemincludesflag or {}, {"-E", "-x", "c++", file, "-o", ifile})
os.vrunv(compinst:program(), flags)
local content = io.readfile(ifile)
os.rm(ifile)