summaryrefslogtreecommitdiff
path: root/xmake/rules/c++/modules/modules_support/gcc.lua
diff options
context:
space:
mode:
Diffstat (limited to 'xmake/rules/c++/modules/modules_support/gcc.lua')
-rw-r--r--xmake/rules/c++/modules/modules_support/gcc.lua105
1 files changed, 86 insertions, 19 deletions
diff --git a/xmake/rules/c++/modules/modules_support/gcc.lua b/xmake/rules/c++/modules/modules_support/gcc.lua
index 99045cf54..663e4ea07 100644
--- a/xmake/rules/c++/modules/modules_support/gcc.lua
+++ b/xmake/rules/c++/modules/modules_support/gcc.lua
@@ -131,15 +131,15 @@ function generate_dependencies(target, sourcebatch, opt)
progress.show(opt.progress, "${color.build.object}generating.cxx.module.deps %s", sourcefile)
end
- local outdir = path.translate(path.join(cachedir, path.directory(path.relative(sourcefile, projectdir))))
- if not os.isdir(outdir) then
- os.mkdir(outdir)
+ local outputdir = path.translate(path.join(cachedir, path.directory(path.relative(sourcefile, projectdir))))
+ if not os.isdir(outputdir) then
+ os.mkdir(outputdir)
end
- local jsonfile = path.translate(path.join(outdir, path.filename(sourcefile) .. ".json"))
+ local jsonfile = path.translate(path.join(outputdir, path.filename(sourcefile) .. ".json"))
if trtbdflag and depfileflag and depoutputflag then
- local ifile = path.translate(path.join(outdir, path.filename(sourcefile) .. ".i"))
- local dfile = path.translate(path.join(outdir, path.filename(sourcefile) .. ".d"))
+ local ifile = path.translate(path.join(outputdir, path.filename(sourcefile) .. ".i"))
+ local dfile = path.translate(path.join(outputdir, path.filename(sourcefile) .. ".d"))
local args = {sourcefile, "-MD", "-MT", jsonfile, "-MF", dfile, depfileflag .. jsonfile, trtbdflag, depoutputfile .. target:objectfile(sourcefile), "-o", ifile}
os.vrunv(compinst:program(), table.join(compinst:compflags({target = target}), common_args, args), {envs = vcvars})
else
@@ -154,12 +154,34 @@ function generate_dependencies(target, sourcebatch, opt)
return changed
end
+-- generate target stl header units for batchjobs
+function generate_stl_headerunits_for_batchjobs(target, batchjobs, headerunits, opt)
+ local compinst = target:compiler("cxx")
+ local mapper_file = _get_module_mapper()
+ local stlcachedir = common.stlmodules_cachedir(target)
+
+ -- build headerunits
+ local projectdir = os.projectdir()
+ local depmtime = 0
+ for _, headerunit in ipairs(headerunits) do
+ local bmifile = path.join(stlcachedir, headerunit.name .. get_bmi_extension())
+ if not os.isfile(bmifile) then
+ batchjobs:addjob(headerunit.name, function (index, total)
+ depend.on_changed(function()
+ progress.show((index * 100) / total, "${color.build.object}generating.cxx.headerunit.bmi %s", headerunit.name)
+ local args = {"-c", "-x", "c++-system-header", headerunit.name}
+ os.vrunv(compinst:program(), table.join(compinst:compflags({target = target}), args))
+ _add_module_to_mapper(mapper_file, headerunit.path, path.absolute(bmifile, projectdir))
+ end, {dependfile = target:dependfile(bmifile), files = {headerunit.path}})
+ end, {rootjob = opt.rootjob})
+ end
+ end
+end
+
-- generate target stl header units for batchcmds
function generate_stl_headerunits_for_batchcmds(target, batchcmds, headerunits, opt)
local compinst = target:compiler("cxx")
local mapper_file = _get_module_mapper()
-
- -- get cachedirs
local stlcachedir = common.stlmodules_cachedir(target)
-- build headerunits
@@ -172,21 +194,67 @@ function generate_stl_headerunits_for_batchcmds(target, batchcmds, headerunits,
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
-
batchcmds:add_depfiles(headerunit.path)
-
_add_module_to_mapper(mapper_file, headerunit.path, path.absolute(bmifile, projectdir))
depmtime = math.max(depmtime, os.mtime(bmifile))
end
batchcmds:set_depmtime(depmtime)
end
+-- generate target user header units for batchjobs
+function generate_user_headerunits_for_batchjobs(target, batchjobs, headerunits, opt)
+ local compinst = target:compiler("cxx")
+ local mapper_file = _get_module_mapper()
+ local cachedir = common.modules_cachedir(target)
+
+ -- build headerunits
+ local projectdir = os.projectdir()
+ local depmtime = 0
+ for _, headerunit in ipairs(headerunits) do
+ local bmifilename = path.basename(objectfile) .. get_bmi_extension()
+ local bmifile = (outputdir and path.join(outputdir, bmifilename) or bmifilename)
+ batchjobs:addjob(headerunit.name, function (index, total)
+ depend.on_changed(function()
+ progress.show((index * 100) / total, "${color.build.object}generating.cxx.headerunit.bmi %s", headerunit.name)
+ local file = path.relative(headerunit.path, projectdir)
+ local objectfile = target:objectfile(file)
+ local outputdir
+ if headerunit.type == ":quote" then
+ outputdir = path.join(cachedir, path.directory(path.relative(headerunit.path, projectdir)))
+ else
+ outputdir = path.join(cachedir, path.directory(headerunit.path))
+ end
+ local objectdir = path.directory(objectfile)
+ if not os.isdir(objectdir) then
+ os.mkdir(objectdir)
+ end
+ if not os.isdir(outputdir) then
+ os.mkdir(outputdir)
+ end
+
+ -- generate headerunit
+ 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 })
+ headerunit_path = path.join(".", path.relative(headerunit.path, projectdir))
+ elseif headerunit.type == ":angle" then
+ 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
+ os.vrunv(compinst:program(), table.join(compinst:compflags({target = target}), args))
+ _add_module_to_mapper(mapper_file, headerunit_path, path.absolute(bmifile, projectdir))
+
+ end, {dependfile = target:dependfile(bmifile), files = {headerunit.path}})
+ end, {rootjob = opt.rootjob})
+ end
+end
+
-- generate target user header units for batchcmds
function generate_user_headerunits_for_batchcmds(target, batchcmds, headerunits, opt)
local compinst = target:compiler("cxx")
local mapper_file = _get_module_mapper()
-
- -- get cachedirs
local cachedir = common.modules_cachedir(target)
-- build headerunits
@@ -195,17 +263,16 @@ function generate_user_headerunits_for_batchcmds(target, batchcmds, headerunits,
for _, headerunit in ipairs(headerunits) do
local file = path.relative(headerunit.path, projectdir)
local objectfile = target:objectfile(file)
-
- local outdir
+ local outputdir
if headerunit.type == ":quote" then
- outdir = path.join(cachedir, path.directory(path.relative(headerunit.path, projectdir)))
+ outputdir = path.join(cachedir, path.directory(path.relative(headerunit.path, projectdir)))
else
- outdir = path.join(cachedir, path.directory(headerunit.path))
+ outputdir = path.join(cachedir, path.directory(headerunit.path))
end
- batchcmds:mkdir(outdir)
+ batchcmds:mkdir(outputdir)
local bmifilename = path.basename(objectfile) .. get_bmi_extension()
- local bmifile = (outdir and path.join(outdir, bmifilename) or bmifilename)
+ local bmifile = (outputdir and path.join(outputdir, bmifilename) or bmifilename)
batchcmds:mkdir(path.directory(objectfile))
local args = { "-c" }
@@ -336,4 +403,4 @@ function get_depoutputflag(target)
_g.depoutputflag = depoutputflag or false
end
return depoutputflag or nil
-end \ No newline at end of file
+end