summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2024-05-14 00:35:31 +0800
committerruki <[email protected]>2024-05-14 00:35:31 +0800
commit4fef554cbad3b2c2d9148e231f4163f16c695544 (patch)
tree8d2969e6b6a0758c553b8435d1edf3d5913086ed
parentb6a7910cd38819db8546ec5ad2bd8e85ab38afd5 (diff)
set default languages for c++modules
-rw-r--r--xmake/rules/c++/modules/modules_support/clang/dependency_scanner.lua4
-rw-r--r--xmake/rules/c++/modules/modules_support/compiler_support.lua15
2 files changed, 17 insertions, 2 deletions
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 9e3982bb0..009bf519a 100644
--- a/xmake/rules/c++/modules/modules_support/clang/dependency_scanner.lua
+++ b/xmake/rules/c++/modules/modules_support/clang/dependency_scanner.lua
@@ -60,8 +60,8 @@ function generate_dependency_for(target, sourcefile, opt)
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
+ -- 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 in this point of compilation
table.remove_if(compflags, function(_, flag)
return flag:startswith("-fmodule") or flag:startswith("-std=c++") or flag:startswith("-std=gnu++")
end)
diff --git a/xmake/rules/c++/modules/modules_support/compiler_support.lua b/xmake/rules/c++/modules/modules_support/compiler_support.lua
index d7cf0b262..d53e92974 100644
--- a/xmake/rules/c++/modules/modules_support/compiler_support.lua
+++ b/xmake/rules/c++/modules/modules_support/compiler_support.lua
@@ -46,6 +46,21 @@ end
-- load module support for the current target
function load(target)
+
+ -- At least std c++20 is required, and we should call `set_languages("c++20")` to set it
+ local languages = target:get("languages")
+ local cxxlang = false
+ for _, lang in ipairs(languages) do
+ if lang:find("cxx", 1, true) or lang:find("c++", 1, true) then
+ cxxlang = true
+ break
+ end
+ end
+ if not cxxlang then
+ target:add("languages", "c++20")
+ end
+
+ -- load module support for the specific compiler
_compiler_support(target).load(target)
end