summaryrefslogtreecommitdiff
path: root/xmake/rules/c++/modules/modules_support
diff options
context:
space:
mode:
Diffstat (limited to 'xmake/rules/c++/modules/modules_support')
-rw-r--r--xmake/rules/c++/modules/modules_support/clang.lua37
1 files changed, 18 insertions, 19 deletions
diff --git a/xmake/rules/c++/modules/modules_support/clang.lua b/xmake/rules/c++/modules/modules_support/clang.lua
index 763cfb6cd..54be2c80f 100644
--- a/xmake/rules/c++/modules/modules_support/clang.lua
+++ b/xmake/rules/c++/modules/modules_support/clang.lua
@@ -116,22 +116,16 @@ end
-- load module support for the current target
function load(target)
- local modulesflag, modulestsflag = get_modulesflag(target)
- local builtinmodulemapflag = get_builtinmodulemapflag(target)
- local implicitmodulesflag = get_implicitmodulesflag(target)
- local noimplicitmodulemapsflag = get_noimplicitmodulemapsflag(target)
+ local clangmodulesflag, modulestsflag, withoutflag = get_modulesflag(target)
-- add module flags
- target:add("cxxflags", modulesflag)
- if not modulesflag then
+ if not withoutflag then
target:add("cxxflags", modulestsflag)
end
+ -- enable clang modules to emulate std modules
if target:policy("build.c++.clang.stdmodules") then
- target:add("cxxflags", builtinmodulemapflag, {force = true})
- target:add("cxxflags", implicitmodulesflag, {force = true})
- else
- target:add("cxxflags", noimplicitmodulemapsflag, {force = true})
+ target:add("cxxflags", clangmodulesflag)
end
-- fix default visibility for functions and variables [-fvisibility] differs in PCH file vs. current file
@@ -698,21 +692,25 @@ function get_bmi_extension()
end
function get_modulesflag(target)
- local modulesflag = _g.modulesflag
+ local clangmodulesflag = _g.clangmodulesflag
local modulestsflag = _g.modulestsflag
- if modulesflag == nil and modulestsflag == nil then
+ 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
- modulesflag = "-fmodules"
+ clangmodulesflag = "-fmodules"
end
if compinst:has_flags("-fmodules-ts", "cxxflags", {flagskey = "clang_modules_ts"}) then
modulestsflag = "-fmodules-ts"
end
- assert(modulesflag or modulestsflag, "compiler(clang): does not support c++ module!")
- _g.modulesflag = modulesflag or false
+ 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!")
+ _g.clangmodulesflag = clangmodulesflag or false
_g.modulestsflag = modulestsflag or false
+ _g.withoutflag = withoutflag or false
end
- return modulesflag or nil, modulestsflag or nil
+ return clangmodulesflag or nil, modulestsflag or nil, withoutflag or nil
end
function get_builtinmodulemapflag(target)
@@ -814,9 +812,10 @@ function has_headerunitsupport(target)
local support_headerunits = _g.support_headerunits
if support_headerunits == nil then
local compinst = target:compiler("cxx")
- local modulesflag, modulestsflag = get_modulesflag(target)
- if compinst:has_flags(modulesflag or modulestsflag .. " -std=c++20 -x c++-user-header", "cxxflags", {flagskey = "clang_user_header_unit_support", tryrun = true}) and
- compinst:has_flags(modulesflag or modulestsflag .. " -std=c++20 -x c++-system-header", "cxxflags", {flagskey = "clang_system_header_unit_support", tryrun = true}) then
+ local _, modulestsflag, withoutflag = get_modulesflag(target)
+ modulestsflag = withoutflag and "" or modulestsflag
+ if compinst:has_flags(modulestsflag .. " -std=c++20 -x c++-user-header", "cxxflags", {flagskey = "clang_user_header_unit_support", tryrun = true}) and
+ compinst:has_flags(modulestsflag .. " -std=c++20 -x c++-system-header", "cxxflags", {flagskey = "clang_system_header_unit_support", tryrun = true}) then
support_headerunits = true
end
_g.support_headerunits = support_headerunits or false