summaryrefslogtreecommitdiff
path: root/xmake/rules/c++
diff options
context:
space:
mode:
authorruki <[email protected]>2021-07-15 22:58:21 +0800
committerGitHub <[email protected]>2021-07-15 22:58:21 +0800
commitba4ebd5a676ad15d8d72fe4fefa4d949ea11bc68 (patch)
tree817b50173948547f7e4b491da271918c67b8a5ff /xmake/rules/c++
parent8c1141aba414c07554179cb28687124514f6e770 (diff)
parent942c32f448d9b8a850438aa2af1de2415b7ae872 (diff)
Merge pull request #1519 from aacirino/master
Added the correct support to build C++ projects that use modules
Diffstat (limited to 'xmake/rules/c++')
-rw-r--r--xmake/rules/c++/modules/build_modulefiles.lua43
1 files changed, 29 insertions, 14 deletions
diff --git a/xmake/rules/c++/modules/build_modulefiles.lua b/xmake/rules/c++/modules/build_modulefiles.lua
index 992344059..4e26f1eca 100644
--- a/xmake/rules/c++/modules/build_modulefiles.lua
+++ b/xmake/rules/c++/modules/build_modulefiles.lua
@@ -35,7 +35,7 @@ function _build_modulefiles_clang(target, sourcebatch, opt)
end
-- compile module files to *.pcm
- opt = table.join(opt, {configs = {force = {cxxflags = {"-fmodules-ts", "--precompile", "-x c++-module"}}}})
+ opt = table.join(opt, {configs = {force = {cxxflags = {opt.modulesflag, "--precompile", "-x c++-module"}}}})
import("private.action.build.object").build(target, sourcebatch, opt)
-- compile *.pcm to object files
@@ -48,12 +48,12 @@ function _build_modulefiles_clang(target, sourcebatch, opt)
sourcebatch.dependfiles[idx] = target:dependfile(objectfile)
table.insert(modulefiles, modulefile)
end
- opt.configs = {cxxflags = {"-fmodules-ts"}}
+ opt.configs = {cxxflags = {opt.modulesflag}}
opt.quiet = true
import("private.action.build.object").build(target, sourcebatch, opt)
-- add module files
- target:add("cxxflags", "-fmodules-ts")
+ target:add("cxxflags", opt.modulesflag)
for _, modulefile in ipairs(modulefiles) do
target:add("cxxflags", "-fmodule-file=" .. modulefile)
end
@@ -77,7 +77,7 @@ function _build_modulefiles_gcc(target, sourcebatch, opt)
-- compile module file to *.pcm
local singlebatch = {sourcekind = "cxx", sourcefiles = {sourcefile}, objectfiles = {objectfile}, dependfiles = {dependfile}}
- opt.configs.cxxflags = {"-fmodules-ts", "-fmodule-output=" .. modulefile, "-x c++"}
+ opt.configs.cxxflags = {"-fmodules", "-fmodule-output=" .. modulefile, "-x c++"}
import("private.action.build.object").build(target, singlebatch, opt)
table.insert(modulefiles, modulefile)
table.insert(sourcebatch.objectfiles, objectfile)
@@ -86,7 +86,7 @@ function _build_modulefiles_gcc(target, sourcebatch, opt)
-- add module files
for _, modulefile in ipairs(modulefiles) do
- target:add("cxxflags", "-fmodules-ts", "-fmodule-file=" .. modulefile)
+ target:add("cxxflags", "-fmodules", "-fmodule-file=" .. modulefile)
end]]
raise("compiler(gcc): not implemented for c++ module!")
end
@@ -124,15 +124,30 @@ end
function main(target, sourcebatch, opt)
-- do compile
+ local modulesflag = nil
+ local _, toolname = target:tool("cxx")
local compinst = compiler.load("cxx")
- if compinst:name() == "clang" and compinst:has_flags("-fmodules-ts") then
- _build_modulefiles_clang(target, sourcebatch, opt)
- elseif compinst:name() == "gcc" and compinst:has_flags("-fmodules-ts") then
- _build_modulefiles_gcc(target, sourcebatch, opt)
- elseif compinst:name() == "cl" and compinst:has_flags("/experimental:module") then
- _build_modulefiles_msvc(target, sourcebatch, opt)
- else
- raise("compiler(%s): does not support c++ module!", compinst:name())
+ if toolname:find("clang", 1, true) or toolname:find("gcc", 1, true) then
+ if compinst:has_flags("-fmodules") then
+ modulesflag = "-fmodules"
+ elseif compinst:has_flags("-fmodules-ts") then
+ modulesflag = "-fmodules-ts"
+ end
+ elseif toolname == "cl" then
+ if compinst:has_flags("/experimental:module") then
+ modulesflag = "/experimental:module"
+ end
+ end
+ if modulesflag then
+ opt.modulesflag = modulesflag
+ if toolname:find("clang", 1, true) then
+ _build_modulefiles_clang(target, sourcebatch, opt)
+ elseif toolname:find("gcc", 1, true) then
+ _build_modulefiles_gcc(target, sourcebatch, opt)
+ elseif toolname == "cl" then
+ _build_modulefiles_msvc(target, sourcebatch, opt)
+ else
+ raise("compiler(%s): does not support c++ module!", toolname)
+ end
end
end
-