summaryrefslogtreecommitdiff
path: root/xmake/rules/c++/modules
diff options
context:
space:
mode:
authorruki <[email protected]>2022-08-15 11:19:15 +0800
committerGitHub <[email protected]>2022-08-15 11:19:15 +0800
commit4e4559e121c1ea1387874809fb448548dc0dba80 (patch)
treea994abe7a9836df6afe1bd201cda2dd2864b9d99 /xmake/rules/c++/modules
parent595a078ba33abd374cf900a07570222151caf605 (diff)
parentff971cdfeb55701078e894c380939ed7146b5638 (diff)
Merge pull request #2673 from xmake-io/generator
improve generator for cxxmodules
Diffstat (limited to 'xmake/rules/c++/modules')
-rw-r--r--xmake/rules/c++/modules/modules_support/clang.lua14
-rw-r--r--xmake/rules/c++/modules/modules_support/common.lua2
-rw-r--r--xmake/rules/c++/modules/modules_support/gcc.lua10
-rw-r--r--xmake/rules/c++/modules/modules_support/msvc.lua14
-rw-r--r--xmake/rules/c++/modules/xmake.lua1
5 files changed, 26 insertions, 15 deletions
diff --git a/xmake/rules/c++/modules/modules_support/clang.lua b/xmake/rules/c++/modules/modules_support/clang.lua
index bd4448ae7..fb3a2d1fa 100644
--- a/xmake/rules/c++/modules/modules_support/clang.lua
+++ b/xmake/rules/c++/modules/modules_support/clang.lua
@@ -210,7 +210,9 @@ function generate_stl_headerunits_for_batchcmds(target, batchcmds, headerunits,
-- don't build same header unit at the same time
if not common.memcache():get2(headerunit.name, "building") then
common.memcache():set2(headerunit.name, "building", true)
- local args = {modulecachepathflag .. stlcachedir, "-c", "-o", bmifile, "-x", "c++-system-header", headerunit.name}
+ local args = {
+ path(stlcachedir, function (p) return modulecachepathflag .. p end),
+ "-c", "-o", path(bmifile), "-x", "c++-system-header", headerunit.name}
batchcmds:show_progress(opt.progress, "${color.build.object}generating.cxx.headerunit.bmi %s", headerunit.name)
batchcmds:vrunv(compinst:program(), table.join(compinst:compflags({target = target}), args))
end
@@ -306,9 +308,9 @@ function generate_user_headerunits_for_batchcmds(target, batchcmds, headerunits,
local bmifile = (outputdir and path.join(outputdir, bmifilename) or bmifilename)
batchcmds:mkdir(path.directory(objectfile))
- local args = { modulecachepathflag .. cachedir, "-c", "-o", bmifile}
+ local args = {path(cachedir, function (p) return modulecachepathflag .. p end), "-c", "-o", path(bmifile)}
if headerunit.type == ":quote" then
- table.join2(args, {"-I", path.directory(headerunit.path), "-x", "c++-user-header", headerunit.path})
+ table.join2(args, {"-I", path(headerunit.path):directory(), "-x", "c++-user-header", path(headerunit.path)})
elseif headerunit.type == ":angle" then
table.join2(args, {"-x", "c++-system-header", headerunit.name})
end
@@ -421,7 +423,7 @@ function build_modules_for_batchcmds(target, batchcmds, objectfiles, modules, op
-- build modules
local depmtime = 0
- local common_args = {modulecachepathflag .. cachedir}
+ local common_args = {path(cachedir, function (p) return modulecachepathflag .. p end)}
for _, objectfile in ipairs(objectfiles) do
local module = modules[objectfile]
if module then
@@ -433,7 +435,7 @@ function build_modules_for_batchcmds(target, batchcmds, objectfiles, modules, op
break
end
local bmifile = provide.bmi
- local args = { "-c", "-x", "c++-module", "--precompile", provide.sourcefile, "-o", bmifile }
+ local args = {"-c", "-x", "c++-module", "--precompile", path(provide.sourcefile), "-o", path(bmifile)}
local requiresflags
if module.requires then
requiresflags = get_requiresflags(target, module.requires)
@@ -441,7 +443,7 @@ function build_modules_for_batchcmds(target, batchcmds, objectfiles, modules, op
batchcmds:show_progress(opt.progress, "${color.build.object}generating.cxx.module.bmi %s", name)
batchcmds:mkdir(path.directory(objectfile))
batchcmds:vrunv(compinst:program(), table.join(compinst:compflags({target = target}), common_args, requiresflags or {}, args))
- batchcmds:vrunv(compinst:program(), table.join(compinst:compflags({target = target}), common_args, requiresflags or {}, {bmifile}, {"-c", "-o", objectfile}))
+ batchcmds:vrunv(compinst:program(), table.join(compinst:compflags({target = target}), common_args, requiresflags or {}, path(bmifile), {"-c", "-o", path(objectfile)}))
batchcmds:add_depfiles(provide.sourcefile)
_add_module_to_mapper(target, name, bmifile)
depmtime = math.max(depmtime, os.mtime(bmifile))
diff --git a/xmake/rules/c++/modules/modules_support/common.lua b/xmake/rules/c++/modules/modules_support/common.lua
index 39ad17f2e..aa7c0fb59 100644
--- a/xmake/rules/c++/modules/modules_support/common.lua
+++ b/xmake/rules/c++/modules/modules_support/common.lua
@@ -88,7 +88,6 @@ end
-- patch sourcebatch
function patch_sourcebatch(target, sourcebatch)
- local cachedir = modules_cachedir(target)
sourcebatch.sourcekind = "cxx"
sourcebatch.objectfiles = {}
sourcebatch.dependfiles = {}
@@ -138,6 +137,7 @@ end
-- this target contains module files?
function contains_modules(target)
+ -- we can not use `"c++.build.modules.builder"`, because it contains sourcekind/cxx.
local target_with_modules = target:sourcebatches()["c++.build.modules"] and true or false
if not target_with_modules then
for _, dep in ipairs(target:orderdeps()) do
diff --git a/xmake/rules/c++/modules/modules_support/gcc.lua b/xmake/rules/c++/modules/modules_support/gcc.lua
index a37346bad..1405d1cfa 100644
--- a/xmake/rules/c++/modules/modules_support/gcc.lua
+++ b/xmake/rules/c++/modules/modules_support/gcc.lua
@@ -189,7 +189,7 @@ function generate_stl_headerunits_for_batchcmds(target, batchcmds, headerunits,
for _, headerunit in ipairs(headerunits) do
local bmifile = path.join(stlcachedir, headerunit.name .. get_bmi_extension())
if not os.isfile(bmifile) then
- local args = { "-c", "-x", "c++-system-header", headerunit.name }
+ local args = {"-c", "-x", "c++-system-header", headerunit.name}
batchcmds:show_progress(opt.progress, "${color.build.object}generating.cxx.headerunit.bmi %s", headerunit.name)
batchcmds:vrunv(compinst:program(), table.join(compinst:compflags({target = target}), args))
end
@@ -276,13 +276,13 @@ function generate_user_headerunits_for_batchcmds(target, batchcmds, headerunits,
local bmifile = (outputdir and path.join(outputdir, bmifilename) or bmifilename)
batchcmds:mkdir(path.directory(objectfile))
- local args = { "-c" }
+ local args = {"-c"}
local headerunit_path
if headerunit.type == ":quote" then
- table.join2(args, { "-I", path.directory(path.relative(headerunit.path, projectdir)), "-x", "c++-user-header", headerunit.name })
+ table.join2(args, {"-I", path(path.relative(headerunit.path, projectdir)):directory(), "-x", "c++-user-header", headerunit.name})
headerunit_path = path.join(".", path.relative(headerunit.path, projectdir))
elseif headerunit.type == ":angle" then
- table.join2(args, { "-x", "c++-system-header", headerunit.name })
+ table.join2(args, {"-x", "c++-system-header", headerunit.name})
-- if path is relative then its a subtarget path
headerunit_path = path.is_absolute(headerunit.path) and headerunit.path or path.join(".", headerunit.path)
end
@@ -375,7 +375,7 @@ function build_modules_for_batchcmds(target, batchcmds, objectfiles, modules, op
end
local bmifile = provide.bmi
- local args = {"-o", objectfile, "-c", provide.sourcefile}
+ local args = {"-o", path(objectfile), "-c", path(provide.sourcefile)}
batchcmds:show_progress(opt.progress, "${color.build.object}generating.cxx.module.bmi %s", name)
batchcmds:mkdir(path.directory(objectfile))
batchcmds:vrunv(compinst:program(), table.join(compinst:compflags({target = target}), common_args, args))
diff --git a/xmake/rules/c++/modules/modules_support/msvc.lua b/xmake/rules/c++/modules/modules_support/msvc.lua
index 4f7c8edc2..5214f12df 100644
--- a/xmake/rules/c++/modules/modules_support/msvc.lua
+++ b/xmake/rules/c++/modules/modules_support/msvc.lua
@@ -219,7 +219,12 @@ function generate_stl_headerunits_for_batchcmds(target, batchcmds, headerunits,
-- don't build same header unit at the same time
if not common.memcache():get2(headerunit.name, "building") then
common.memcache():set2(headerunit.name, "building", true)
- local args = {headernameflag .. ":angle", headerunit.name, ifcoutputflag, headerunit.name:startswith("experimental/") and path.join(stlcachedir, "experimental") or stlcachedir, "-Fo" .. objectfile}
+ local args = {
+ headernameflag .. ":angle",
+ headerunit.name,
+ ifcoutputflag,
+ path(headerunit.name:startswith("experimental/") and path.join(stlcachedir, "experimental") or stlcachedir),
+ path(objectfile, function (p) return "-Fo" .. p end)}
batchcmds:show_progress(opt.progress, "${color.build.object}generating.cxx.headerunit.bmi %s", headerunit.name)
batchcmds:vrunv(compinst:program(), table.join(compinst:compflags({target = target}), common_args, args), {envs = vcvars})
batchcmds:add_depfiles(headerunit.path)
@@ -468,7 +473,12 @@ function build_modules_for_batchcmds(target, batchcmds, objectfiles, modules, op
end
local bmifile = provide.bmi
- local args = {"-c", "-Fo" .. objectfile, interfaceflag, ifcoutputflag, bmifile, provide.sourcefile}
+ local args = {"-c",
+ path(objectfile, function (p) return "-Fo" .. p end),
+ interfaceflag,
+ ifcoutputflag,
+ path(bmifile),
+ path(provide.sourcefile)}
batchcmds:show_progress(opt.progress, "${color.build.object}generating.cxx.module.bmi %s", name)
batchcmds:mkdir(path.directory(objectfile))
batchcmds:vrunv(compinst:program(), table.join(compinst:compflags({target = target}), common_args, requiresflags or {}, args), {envs = vcvars})
diff --git a/xmake/rules/c++/modules/xmake.lua b/xmake/rules/c++/modules/xmake.lua
index 276566a27..3ef960d7a 100644
--- a/xmake/rules/c++/modules/xmake.lua
+++ b/xmake/rules/c++/modules/xmake.lua
@@ -21,7 +21,6 @@
-- define rule: c++.build.modules
rule("c++.build.modules")
set_extensions(".mpp", ".mxx", ".cppm", ".ixx")
-
add_deps("c++.build.modules.builder")
add_deps("c++.build.modules.install")