diff options
| author | Arthur LAURENT <[email protected]> | 2023-01-16 13:56:34 +0100 |
|---|---|---|
| committer | Arthur LAURENT <[email protected]> | 2023-01-16 13:57:07 +0100 |
| commit | d4572f03336508f4b8d9bfa3fb62df5295fed56b (patch) | |
| tree | ae8bef84b61ffa30b93d5a188100d6c80618b9e7 /xmake/rules/c++/modules/modules_support/clang.lua | |
| parent | 57453e7c479bd4a47b7ebfeb2d56f3eac90e269d (diff) | |
Add support of -fmodule-output on llvm >= 16
Diffstat (limited to 'xmake/rules/c++/modules/modules_support/clang.lua')
| -rw-r--r-- | xmake/rules/c++/modules/modules_support/clang.lua | 35 |
1 files changed, 29 insertions, 6 deletions
diff --git a/xmake/rules/c++/modules/modules_support/clang.lua b/xmake/rules/c++/modules/modules_support/clang.lua index 5680c1eac..a6e195e22 100644 --- a/xmake/rules/c++/modules/modules_support/clang.lua +++ b/xmake/rules/c++/modules/modules_support/clang.lua @@ -179,29 +179,39 @@ function _build_modulefile(target, sourcefile, opt) -- init flags local common_args = opt.common_args local requiresflags = opt.requiresflags + local moduleoutputflag = get_moduleoutputflag(target) -- trace progress.show(opt.progress, "${color.build.object}compiling.module.$(mode) %s", opt.provide and opt.provide.name or sourcefile) local bmifile + local compileflags = {} local bmiflags if opt.provide then bmifile = opt.provide.bmifile - bmiflags = table.join("-x", "c++-module", "--precompile", compflags, common_args, requiresflags) + + if moduleoutputflag then + compileflags = table.join("-x", "c++-module", moduleoutputflag .. bmifile, compflags, common_args, requiresflags) + else + bmiflags = table.join("-x", "c++-module", "--precompile", compflags, common_args, requiresflags) + end + end + + if bmiflags then vprint(compinst:compcmd(sourcefile, bmifile, {compflags = bmiflags, rawargs = true})) end - local objflags = table.join(compflags, common_args, requiresflags or {}, (bmifile == nil) and {"-x", "c++"} or {}) - vprint(compinst:compcmd(bmifile or sourcefile, objectfile, {compflags = objflags, rawargs = true})) + compileflags = table.join2(compileflags, compflags, common_args, requiresflags or {}) + vprint(compinst:compcmd(bmifile or sourcefile, objectfile, {compflags = compileflags, rawargs = true})) if not dryrun then -- do compile dependinfo.files = {} - if opt.provide then + if bmiflags then assert(compinst:compile(sourcefile, bmifile, {dependinfo = dependinfo, compflags = bmiflags})) end - assert(compinst:compile(bmifile or sourcefile, objectfile, {compflags = objflags})) + assert(compinst:compile(bmiflags and bmifile or sourcefile, objectfile, {compflags = compileflags})) -- update files and values to the dependent file dependinfo.values = depvalues @@ -781,7 +791,7 @@ 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) + local modulesflag, moduletsflag = get_modulesflag(target) if compinst:has_flags(modulesflag or moduletsflag .. " -std=c++20 -x c++-user-header", "cxxflags", {flagskey = "clang_user_header_unit_support", tryrun = true}) and compinst:has_flags(modulesflag or moduletsflag .. " -std=c++20 -x c++-system-header", "cxxflags", {flagskey = "clang_system_header_unit_support", tryrun = true}) then support_headerunits = true @@ -803,6 +813,19 @@ function has_clangscandepssupport(target) return support_clangscandeps or nil end +function get_moduleoutputflag(target) + local moduleoutputflag = _g.moduleoutputflag + if moduleoutputflag == nil then + local compinst = target:compiler("cxx") + local clang = find_tool("clang", {version = true}) + 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=" + end + _g.moduleoutputflag = moduleoutputflag or false + end + return moduleoutputflag or nil +end + function get_requiresflags(target, requires) local flags = {} -- add deps required module flags |
