summaryrefslogtreecommitdiff
path: root/xmake/rules/c++/modules/modules_support
diff options
context:
space:
mode:
authorruki <[email protected]>2023-09-15 16:39:46 +0800
committerGitHub <[email protected]>2023-09-15 16:39:46 +0800
commitf47973ccb2d60daf469f831ae3e7bcb85643ba85 (patch)
tree54dd0d147fbfb8f8d32eea9756c36a0821f37cf1 /xmake/rules/c++/modules/modules_support
parent61db1413d0cf16d41a5ad6cf21b586bb94a2ea78 (diff)
parent3f10a225581a76e8219c779518697507c9ab38de (diff)
Merge pull request #4199 from glcraft/dev
Add C++ module for `xmake project`
Diffstat (limited to 'xmake/rules/c++/modules/modules_support')
-rw-r--r--xmake/rules/c++/modules/modules_support/clang.lua10
-rw-r--r--xmake/rules/c++/modules/modules_support/gcc.lua16
-rw-r--r--xmake/rules/c++/modules/modules_support/msvc.lua2
3 files changed, 16 insertions, 12 deletions
diff --git a/xmake/rules/c++/modules/modules_support/clang.lua b/xmake/rules/c++/modules/modules_support/clang.lua
index 32cdc4d4f..265b0247e 100644
--- a/xmake/rules/c++/modules/modules_support/clang.lua
+++ b/xmake/rules/c++/modules/modules_support/clang.lua
@@ -235,7 +235,7 @@ end
-- do compile for batchcmds
-- @note we need to use batchcmds:compilev to translate paths in compflags for generator, e.g. -Ixx
-function _batchcmds_compile(batchcmds, target, sourcefile, flags)
+function _batchcmds_compile(batchcmds, target, flags, sourcefile)
local compinst = target:compiler("cxx")
local compflags = compinst:compflags({sourcefile = sourcefile, target = target})
batchcmds:compilev(table.join(compflags or {}, flags), {compiler = compinst, sourcekind = "cxx"})
@@ -709,11 +709,13 @@ function build_modules_for_batchcmds(target, batchcmds, objectfiles, modules, op
batchcmds:mkdir(path.directory(objectfile))
if provide then
_batchcmds_compile(batchcmds, target, table.join(flags,
- {"-x", "c++-module", "--precompile", "-c", path(cppfile), "-o", path(provide.bmi)}))
+ {"-x", "c++-module", "--precompile", "-c", path(cppfile), "-o", path(provide.bmi)}), cppfile)
_add_module_to_mapper(target, name, provide.bmi, {namedmodule = true})
+ -- add requiresflags to module. it will be used for project generation
+ target:fileconfig_add(cppfile, {force = {cxxflags = requiresflags}})
end
- _batchcmds_compile(batchcmds, target, file, table.join(flags,
- not provide and {"-x", "c++"} or {}, {"-c", file, "-o", path(objectfile)}))
+ _batchcmds_compile(batchcmds, target, table.join(flags,
+ not provide and {"-x", "c++"} or {}, {"-c", file, "-o", path(objectfile)}), file)
target:add("objectfiles", objectfile)
elseif requiresflags then
local cxxflags = {}
diff --git a/xmake/rules/c++/modules/modules_support/gcc.lua b/xmake/rules/c++/modules/modules_support/gcc.lua
index 4fa92e4df..762810f08 100644
--- a/xmake/rules/c++/modules/modules_support/gcc.lua
+++ b/xmake/rules/c++/modules/modules_support/gcc.lua
@@ -113,7 +113,7 @@ end
-- @note we need to use batchcmds:compilev to translate paths in compflags for generator, e.g. -Ixx
function _batchcmds_compile(batchcmds, target, flags, sourcefile)
local compinst = target:compiler("cxx")
- local compflags = compinst:compflags({sourcefile = sourcefile}, {target = target})
+ local compflags = compinst:compflags({sourcefile = sourcefile, target = target})
batchcmds:compilev(table.join(compflags or {}, flags), {compiler = compinst, sourcekind = "cxx"})
end
@@ -511,13 +511,13 @@ function build_modules_for_batchcmds(target, batchcmds, objectfiles, modules, op
break
end
end
- local flags = {"-x", "c++", "-c", path(cppfile), "-o", path(objectfile)}
- batchcmds:show_progress(opt.progress, "${color.build.object}compiling.module.$(mode) %s", name or cppfile)
- batchcmds:mkdir(path.directory(objectfile))
- _batchcmds_compile(batchcmds, target, flags)
- batchcmds:add_depfiles(cppfile)
- target:add("objectfiles", objectfile)
- if provide then
+ if provide or common.has_module_extension(cppfile) then
+ local flags = {"-x", "c++", "-c", path(cppfile), "-o", path(objectfile)}
+ batchcmds:show_progress(opt.progress, "${color.build.object}compiling.module.$(mode) %s", name or cppfile)
+ batchcmds:mkdir(path.directory(objectfile))
+ _batchcmds_compile(batchcmds, target, flags, cppfile)
+ batchcmds:add_depfiles(cppfile)
+ target:add("objectfiles", objectfile)
_add_module_to_mapper(mapper_file, name, path.absolute(provide.bmi, projectdir))
end
depmtime = math.max(depmtime, os.mtime(provide and provide.bmi or objectfile))
diff --git a/xmake/rules/c++/modules/modules_support/msvc.lua b/xmake/rules/c++/modules/modules_support/msvc.lua
index 0643117d0..e90ae3df3 100644
--- a/xmake/rules/c++/modules/modules_support/msvc.lua
+++ b/xmake/rules/c++/modules/modules_support/msvc.lua
@@ -557,6 +557,8 @@ function build_modules_for_batchcmds(target, batchcmds, objectfiles, modules, op
_add_objectfile_to_link_arguments(target, path.translate(objectfile))
if provide then
_add_module_to_mapper(target, referenceflag, name, name, objectfile, provide.bmi, requiresflags)
+ -- add requiresflags to module. it will be used for project generation
+ target:fileconfig_add(cppfile, {force = {cxxflags = requiresflags}})
end
depmtime = math.max(depmtime, os.mtime(provide and provide.bmi or objectfile))
elseif requiresflags then