summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArthur LAURENT <[email protected]>2023-01-22 21:53:53 +0100
committerArthur LAURENT <[email protected]>2023-01-22 21:53:53 +0100
commitcd2be29f2bfc8e5bc85767b9ab182d3712e11532 (patch)
treeda050fd799565ac016e2a55484f4677d635fc9f8
parentae76b2aaf0c8ee2bbc1452999e57284a08ddba7c (diff)
improve module compilation on gcc
-rw-r--r--xmake/rules/c++/modules/modules_support/gcc.lua64
1 files changed, 23 insertions, 41 deletions
diff --git a/xmake/rules/c++/modules/modules_support/gcc.lua b/xmake/rules/c++/modules/modules_support/gcc.lua
index 07b4d130b..722706603 100644
--- a/xmake/rules/c++/modules/modules_support/gcc.lua
+++ b/xmake/rules/c++/modules/modules_support/gcc.lua
@@ -74,7 +74,7 @@ function load(target)
end
target:add("cxxflags", {modulesflag, modulemapperflag .. path.translate(_get_module_mapper(target))}, {force = true, expand = false})
-- fix cxxabi issue, @see https://github.com/xmake-io/xmake/issues/2716#issuecomment-1225057760
- target:add("cxxflags", "-D_GLIBCXX_USE_CXX11_ABI=0")
+ -- target:add("cxxflags", "-D_GLIBCXX_USE_CXX11_ABI=0")
end
-- get includedirs for stl headers
@@ -170,7 +170,6 @@ end
-- generate dependency files
function generate_dependencies(target, sourcebatch, opt)
- local cachedir = common.modules_cachedir(target)
local compinst = target:compiler("cxx")
local common_args = {"-E", "-x", "c++"}
local depformatflag = get_depflag(target, "p1689r5") or get_depflag(target, "trtbd")
@@ -184,11 +183,7 @@ function generate_dependencies(target, sourcebatch, opt)
progress.show(opt.progress, "${color.build.object}generating.module.deps %s", sourcefile)
end
- local outputdir = path.translate(path.join(cachedir, path.directory(path.relative(sourcefile, projectdir))))
- if not os.isdir(outputdir) then
- os.mkdir(outputdir)
- end
-
+ local outputdir = common.get_outputdir(target, sourcefile)
local jsonfile = path.translate(path.join(outputdir, path.filename(sourcefile) .. ".json"))
if depformatflag and depfileflag and depoutputflag and not target:policy("build.c++.gcc.fallbackscanner") then
local ifile = path.translate(path.join(outputdir, path.filename(sourcefile) .. ".i"))
@@ -206,9 +201,14 @@ function generate_dependencies(target, sourcebatch, opt)
local compinst = target:compiler("cxx")
local compflags = compinst:compflags({sourcefile = file, target = target})
local flags = {}
+ local next_flag = false
for _, flag in ipairs(compflags) do
- if flag:startswith("-std") or (flag:startswith("-f") and not flag:startswith("-fmodules")) or flag:startswith("-D") or flag:startswith("-U") or flag:startswith("-I") or flag:startswith("-isystem") then
+ if flag == "-m64" or flag == "-g" or flag:startswith("-m") or flag:startswith("-std") or (flag:startswith("-f") and not flag:startswith("-fmodule")) or flag:startswith("-D") or flag:startswith("-U") or flag:startswith("-I") or flag:startswith("-isystem") or next_flag then
table.insert(flags, flag)
+ next_flag = false
+ if flag:startswith("-isystem") then
+ next_flag = true
+ end
end
end
local ifile = path.translate(path.join(outputdir, path.filename(file) .. ".i"))
@@ -292,28 +292,21 @@ end
function generate_user_headerunits_for_batchjobs(target, batchjobs, headerunits, opt)
local compinst = target:compiler("cxx")
local mapper_file = _get_module_mapper(target)
- local cachedir = common.modules_cachedir(target)
-- build headerunits
local projectdir = os.projectdir()
for _, headerunit in ipairs(headerunits) do
- local file = path.relative(headerunit.path, projectdir)
- local objectfile = target:objectfile(file)
- local outputdir
local headerunit_path
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 bmifilename = path.basename(objectfile) .. get_bmi_extension()
- local bmifile = (outputdir and path.join(outputdir, bmifilename) or bmifilename)
- if headerunit.type == ":quote" then
headerunit_path = path.join(".", path.relative(headerunit.path, projectdir))
elseif headerunit.type == ":angle" then
-- 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
+ local objectfile = target:objectfile(headerunit_path)
+ local outputdir = common.get_outputdir(target, headerunit.path)
+ local bmifilename = path.basename(objectfile) .. get_bmi_extension()
+ local bmifile = path.join(outputdir, bmifilename)
batchjobs:addjob(headerunit.name, function (index, total)
depend.on_changed(function()
progress.show((index * 100) / total, "${color.build.object}compiling.headerunit.$(mode) %s", headerunit.name)
@@ -321,9 +314,6 @@ function generate_user_headerunits_for_batchjobs(target, batchjobs, headerunits,
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" }
@@ -343,28 +333,13 @@ end
-- generate target user header units for batchcmds
function generate_user_headerunits_for_batchcmds(target, batchcmds, headerunits, opt)
local mapper_file = _get_module_mapper(target)
- local cachedir = common.modules_cachedir(target)
-- build headerunits
local projectdir = os.projectdir()
local depmtime = 0
for _, headerunit in ipairs(headerunits) do
- 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
- batchcmds:mkdir(outputdir)
-
- local bmifilename = path.basename(objectfile) .. get_bmi_extension()
- local bmifile = (outputdir and path.join(outputdir, bmifilename) or bmifilename)
- batchcmds:mkdir(path.directory(objectfile))
-
- local flags = {"-c"}
local headerunit_path
+ local flags = {"-c"}
if headerunit.type == ":quote" then
table.join2(flags, {"-I", path(path.relative(headerunit.path, projectdir)):directory(), "-x", "c++-user-header", headerunit.name})
headerunit_path = path.join(".", path.relative(headerunit.path, projectdir))
@@ -373,6 +348,14 @@ function generate_user_headerunits_for_batchcmds(target, batchcmds, headerunits,
-- 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
+ local objectfile = target:objectfile(headerunit_path)
+ local outputdir = common.get_outputdir(target, headerunit.path)
+ batchcmds:mkdir(outputdir)
+
+ local bmifilename = path.basename(objectfile) .. get_bmi_extension()
+ local bmifile = (outputdir and path.join(outputdir, bmifilename) or bmifilename)
+ batchcmds:mkdir(path.directory(objectfile))
+
batchcmds:show_progress(opt.progress, "${color.build.object}compiling.headerunit.$(mode) %s", headerunit.name)
_batchcmds_compile(batchcmds, target, flags)
@@ -417,8 +400,8 @@ function build_modules_for_batchjobs(target, batchjobs, objectfiles, modules, op
local fileconfig = target:fileconfig(cppfile)
if fileconfig and fileconfig.install then
batchjobs:addjob(name .. "_metafile", function(index, total)
- local cachedir = common.modules_cachedir(target)
- local metafilepath = path.join(cachedir, path.filename(cppfile) .. ".meta-info")
+ local outputdir = common.get_outputdir(target, cppfile)
+ local metafilepath = path.join(outputdir, path.filename(cppfile) .. ".meta-info")
depend.on_changed(function()
progress.show(opt.progress, "${color.build.object}generating.module.metadata %s", name)
local metadata = common.generate_meta_module_info(target, name, cppfile, module.requires)
@@ -477,7 +460,6 @@ end
-- build module files for batchcmds
function build_modules_for_batchcmds(target, batchcmds, objectfiles, modules, opt)
- local modulemapperflag = get_modulemapperflag(target)
local mapper_file = _get_module_mapper(target)
-- build modules