diff options
| author | ruki <[email protected]> | 2025-12-26 00:01:13 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2025-12-26 00:01:13 +0800 |
| commit | 06b9a04ed59c2595c2c7610d7f8b08712d710352 (patch) | |
| tree | dd83ee3261d17843a9e09c874a481ac9864e3cf4 | |
| parent | 0322af3c7241da09e69282c369bfbbf9d5931c9b (diff) | |
improve clang module flags
| -rw-r--r-- | xmake/rules/c++/modules/clang/support.lua | 67 |
1 files changed, 41 insertions, 26 deletions
diff --git a/xmake/rules/c++/modules/clang/support.lua b/xmake/rules/c++/modules/clang/support.lua index 9447d9c97..cb5b342ea 100644 --- a/xmake/rules/c++/modules/clang/support.lua +++ b/xmake/rules/c++/modules/clang/support.lua @@ -325,16 +325,18 @@ function get_modulesflag(target) local modulestsflag = _g.modulestsflag local withoutflag = _g.withoutflag if clangmodulesflag == nil and modulestsflag == nil then - local compinst = target:compiler("cxx") - if compinst:has_flags("-fmodules", "cxxflags", {flagskey = "clang_modules"}) then - clangmodulesflag = "-fmodules" - end - if compinst:has_flags("-fmodules-ts", "cxxflags", {flagskey = "clang_modules_ts"}) then - modulestsflag = "-fmodules-ts" - end local clang_version = get_clang_version(target) withoutflag = semver.compare(clang_version, "16.0") >= 0 - assert(withoutflag or modulestsflag, "compiler(clang): does not support c++ module!") + if not withoutflag then + local compinst = target:compiler("cxx") + if compinst:has_flags("-fmodules", "cxxflags", {flagskey = "clang_modules"}) then + clangmodulesflag = "-fmodules" + end + if compinst:has_flags("-fmodules-ts", "cxxflags", {flagskey = "clang_modules_ts"}) then + modulestsflag = "-fmodules-ts" + end + assert(modulestsflag or clangmodulesflag, "compiler(clang): does not support c++ module!") + end _g.clangmodulesflag = clangmodulesflag or false _g.modulestsflag = modulestsflag or false _g.withoutflag = withoutflag or false @@ -345,9 +347,12 @@ end function get_modulefileflag(target) local modulefileflag = _g.modulefileflag if modulefileflag == nil then - local compinst = target:compiler("cxx") - if compinst:has_flags("-fmodule-file=" .. os.tmpfile() .. get_bmi_extension(), "cxxflags", {flagskey = "clang_module_file"}) then - modulefileflag = "-fmodule-file=" + local clang_version = get_clang_version(target) + if semver.compare(clang_version, "16.0") >= 0 then + local compinst = target:compiler("cxx") + if compinst:has_flags("-fmodule-file=" .. os.tmpfile() .. get_bmi_extension(), "cxxflags", {flagskey = "clang_module_file"}) then + modulefileflag = "-fmodule-file=" + end end assert(modulefileflag, "compiler(clang): does not support c++ module!") _g.modulefileflag = modulefileflag or false @@ -358,9 +363,12 @@ end function get_moduleheaderflag(target) local moduleheaderflag = _g.moduleheaderflag if moduleheaderflag == nil then - local compinst = target:compiler("cxx") - if compinst:has_flags("-fmodule-header=system", "cxxflags", {flagskey = "clang_module_header"}) then - moduleheaderflag = "-fmodule-header=" + local clang_version = get_clang_version(target) + if semver.compare(clang_version, "16.0") >= 0 then + local compinst = target:compiler("cxx") + if compinst:has_flags("-fmodule-header=system", "cxxflags", {flagskey = "clang_module_header"}) then + moduleheaderflag = "-fmodule-header=" + end end _g.moduleheaderflag = moduleheaderflag or false end @@ -370,11 +378,14 @@ end function get_modulesreducedbmiflag(target) local modulesreducedbmiflag = _g.modulesreducedbmiflag if modulesreducedbmiflag == nil then - local compinst = target:compiler("cxx") - if compinst:has_flags("-fmodules-reduced-bmi", "cxxflags", {flagskey = "clang_modules_reduced_bmi"}) then - modulesreducedbmiflag = "-fmodules-reduced-bmi" - elseif compinst:has_flags("-fexperimental-modules-reduced-bmi", "cxxflags", {flagskey = "clang_modules_reduced_bmi"}) then - modulesreducedbmiflag = "-fexperimental-modules-reduced-bmi" + local clang_version = get_clang_version(target) + if semver.compare(clang_version, "16.0") >= 0 then + local compinst = target:compiler("cxx") + if compinst:has_flags("-fmodules-reduced-bmi", "cxxflags", {flagskey = "clang_modules_reduced_bmi"}) then + modulesreducedbmiflag = "-fmodules-reduced-bmi" + elseif compinst:has_flags("-fexperimental-modules-reduced-bmi", "cxxflags", {flagskey = "clang_modules_reduced_bmi"}) then + modulesreducedbmiflag = "-fexperimental-modules-reduced-bmi" + end end _g.modulesreducedbmiflag = modulesreducedbmiflag or false end @@ -411,11 +422,12 @@ end function get_moduleoutputflag(target) local moduleoutputflag = _g.moduleoutputflag if moduleoutputflag == nil then - local compinst = target:compiler("cxx") local clang_version = get_clang_version(target) - if compinst:has_flags("-fmodule-output=", "cxxflags", {flagskey = "clang_module_output", tryrun = true}) and - semver.compare(clang_version, "16.0") >= 0 then - moduleoutputflag = "-fmodule-output=" + if semver.compare(clang_version, "16.0") >= 0 then + local compinst = target:compiler("cxx") + if compinst:has_flags("-fmodule-output=", "cxxflags", {flagskey = "clang_module_output", tryrun = true}) then + moduleoutputflag = "-fmodule-output=" + end end _g.moduleoutputflag = moduleoutputflag or false end @@ -425,9 +437,12 @@ end function get_print_library_module_manifest_path_flag(target) local print_library_module_manifest_path_flag = _g.print_library_module_manifest_path_flag if print_library_module_manifest_path_flag == nil then - local compinst = target:compiler("cxx") - if compinst:has_flags("-print-library-module-manifest-path", "cxxflags", {flagskey = "clang_print_library_module_manifest_path", tryrun = true}) then - print_library_module_manifest_path_flag = "-print-library-module-manifest-path" + local clang_version = get_clang_version(target) + if semver.compare(clang_version, "16.0") >= 0 then + local compinst = target:compiler("cxx") + if compinst:has_flags("-print-library-module-manifest-path", "cxxflags", {flagskey = "clang_print_library_module_manifest_path", tryrun = true}) then + print_library_module_manifest_path_flag = "-print-library-module-manifest-path" + end end _g.print_library_module_manifest_path_flag = print_library_module_manifest_path_flag or false end |
