diff options
| author | ruki <[email protected]> | 2022-08-13 10:55:47 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2022-08-13 10:55:47 +0800 |
| commit | 85759892a32f733dd5d368f17547a65501dce88f (patch) | |
| tree | 899e72c59192076c0cacee1ed78f90b4f01cfe07 | |
| parent | a8829eee52be60f9ee7cf3b29ea03c42bd6c986e (diff) | |
improve requriesflags
| -rw-r--r-- | xmake/rules/c++/modules/modules_support/clang.lua | 45 | ||||
| -rw-r--r-- | xmake/rules/c++/modules/modules_support/msvc.lua | 66 |
2 files changed, 47 insertions, 64 deletions
diff --git a/xmake/rules/c++/modules/modules_support/clang.lua b/xmake/rules/c++/modules/modules_support/clang.lua index c6e6de6af..bd4448ae7 100644 --- a/xmake/rules/c++/modules/modules_support/clang.lua +++ b/xmake/rules/c++/modules/modules_support/clang.lua @@ -361,10 +361,9 @@ function build_modules_for_batchjobs(target, batchjobs, objectfiles, modules, op moduleinfo.job = batchjobs:newjob(provide.sourcefile, function (index, total) -- append module mapper flags first -- @note we add it at the end to ensure that the full modulemap are already stored in the mapper - local flags + local requiresflags if module.requires then - flags = get_requiresflags(target, module.requires) - flags = table.unique(flags) + requiresflags = get_requiresflags(target, module.requires) end depend.on_changed(function() @@ -378,10 +377,10 @@ function build_modules_for_batchjobs(target, batchjobs, objectfiles, modules, op os.mkdir(objectdir) end local args = { "-c", "-x", "c++-module", "--precompile", provide.sourcefile, "-o", bmifile} - os.vrunv(compinst:program(), table.join(compinst:compflags({target = target}), common_args, flags or {}, args)) - os.vrunv(compinst:program(), table.join(compinst:compflags({target = target}), common_args, flags or {}, {bmifile}, {"-c", "-o", objectfile})) + os.vrunv(compinst:program(), table.join(compinst:compflags({target = target}), common_args, requiresflags or {}, args)) + os.vrunv(compinst:program(), table.join(compinst:compflags({target = target}), common_args, requiresflags or {}, {bmifile}, {"-c", "-o", objectfile})) end, {dependfile = target:dependfile(bmifile), files = {provide.sourcefile}}) - _add_module_to_mapper(target, name, bmifile, flags) + _add_module_to_mapper(target, name, bmifile, requiresflags) end) if module.requires then moduleinfo.deps = table.keys(module.requires) @@ -396,18 +395,12 @@ function build_modules_for_batchjobs(target, batchjobs, objectfiles, modules, op deps = table.keys(module.requires), sourcefile = module.cppfile, job = batchjobs:newjob(module.cppfile, function(index, total) - function contains(t, v) - for _, flag in pairs(t) do - if table.contains(flag, v) then - return true - end - end - return false - end -- append module mapper flags -- @note we add it at the end to ensure that the full modulemap are already stored in the mapper - local flags = get_requiresflags(target, module.requires) - target:fileconfig_add(module.cppfile, {force = {cxxflags = table.unique(flags or {})}}) + local requiresflags = get_requiresflags(target, module.requires) + if requiresflags then + target:fileconfig_add(module.cppfile, {force = {cxxflags = requiresflags}}) + end end) } end @@ -441,23 +434,23 @@ function build_modules_for_batchcmds(target, batchcmds, objectfiles, modules, op end local bmifile = provide.bmi local args = { "-c", "-x", "c++-module", "--precompile", provide.sourcefile, "-o", bmifile } - local flags + local requiresflags if module.requires then - flags = get_requiresflags(target, module.requires) - flags = table.unique(flags) + requiresflags = get_requiresflags(target, module.requires) end 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, flags or {}, args)) - batchcmds:vrunv(compinst:program(), table.join(compinst:compflags({target = target}), common_args, flags or {}, {bmifile}, {"-c", "-o", 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:add_depfiles(provide.sourcefile) _add_module_to_mapper(target, name, bmifile) depmtime = math.max(depmtime, os.mtime(bmifile)) else if module.requires then - local flags = get_requiresflags(target, module.requires) - flags = table.unique(flags) - target:fileconfig_add(module.cppfile, {force = {cxxflags = flags}}) + local requiresflags = get_requiresflags(target, module.requires) + if requiresflags then + target:fileconfig_add(module.cppfile, {force = {cxxflags = requiresflags}}) + end end end end @@ -602,5 +595,7 @@ function get_requiresflags(target, requires) ::continue:: end - return flags + if #flags > 0 then + return table.unique(flags) + end end diff --git a/xmake/rules/c++/modules/modules_support/msvc.lua b/xmake/rules/c++/modules/modules_support/msvc.lua index a53748baa..d09275e9d 100644 --- a/xmake/rules/c++/modules/modules_support/msvc.lua +++ b/xmake/rules/c++/modules/modules_support/msvc.lua @@ -382,17 +382,10 @@ function build_modules_for_batchjobs(target, batchjobs, objectfiles, modules, op moduleinfo.job = batchjobs:newjob(provide.sourcefile, function (index, total) -- append module mapper flags first -- @note we add it at the end to ensure that the full modulemap are already stored in the mapper - local flags + local requiresflags if module.requires then - local flags_ = get_requiresflags(target, module.requires) - flags = flags or {} - for i = 1, #flags_, 2 do - if not table.contains(flags, flags_[i + 1]) then - table.join2(flags, {flags_[i], flags_[i + 1]}) - end - end + requiresflags = get_requiresflags(target, module.requires) end - depend.on_changed(function() progress.show((index * 100) / total, "${color.build.object}generating.cxx.module.bmi %s", name) local objectdir = path.directory(objectfile) @@ -400,9 +393,9 @@ function build_modules_for_batchjobs(target, batchjobs, objectfiles, modules, op os.mkdir(objectdir) end local args = {"-c", "-Fo" .. objectfile, interfaceflag, ifcoutputflag, bmifile, provide.sourcefile} - os.vrunv(compinst:program(), table.join(compinst:compflags({target = target}), common_args, flags or {}, args), {envs = vcvars}) + os.vrunv(compinst:program(), table.join(compinst:compflags({target = target}), common_args, requiresflags or {}, args), {envs = vcvars}) end, {dependfile = target:dependfile(bmifile), files = {provide.sourcefile}}) - _add_module_to_mapper(target, referenceflag, name, bmifile, flags) + _add_module_to_mapper(target, referenceflag, name, bmifile, requiresflags) end) if module.requires then moduleinfo.deps = table.keys(module.requires) @@ -427,14 +420,10 @@ function build_modules_for_batchjobs(target, batchjobs, objectfiles, modules, op end -- append module mapper flags -- @note we add it at the end to ensure that the full modulemap are already stored in the mapper - local flags_ = get_requiresflags(target, module.requires) - local flags = {} - for i = 1, #flags_, 2 do - if not contains(flags, flags_[i + 1]) then - table.insert(flags, {flags_[i], flags_[i + 1]}) - end + local requiresflags = get_requiresflags(target, module.requires) + if requiresflags then + target:fileconfig_add(module.cppfile, {force = {cxxflags = requiresflags}}) end - target:fileconfig_add(module.cppfile, {force = {cxxflags = flags}}) end) } end @@ -473,38 +462,25 @@ function build_modules_for_batchcmds(target, batchcmds, objectfiles, modules, op end -- append required modulemap flags to module - local flags + local requiresflags if module.requires then - local flags_ = get_requiresflags(target, module.requires) - flags = flags or {} - for i = 1, #flags_, 2 do - if not table.contains(flags, flags_[i + 1]) then - table.join2(flags, {flags_[i], flags_[i + 1]}) - end - end + requiresflags = get_requiresflags(target, module.requires) end local bmifile = provide.bmi local args = {"-c", "-Fo" .. objectfile, interfaceflag, ifcoutputflag, bmifile, 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, flags or {}, args), {envs = vcvars}) + batchcmds:vrunv(compinst:program(), table.join(compinst:compflags({target = target}), common_args, requiresflags or {}, args), {envs = vcvars}) batchcmds:add_depfiles(provide.sourcefile) - _add_module_to_mapper(target, referenceflag, name, bmifile, flags) + _add_module_to_mapper(target, referenceflag, name, bmifile, requiresflags) depmtime = math.max(depmtime, os.mtime(bmifile)) else if module.requires then - local flags - if module.requires then - local flags_ = get_requiresflags(target, module.requires) - flags = flags or {} - for i = 1, #flags_, 2 do - if not table.contains(flags, flags_[i + 1]) then - table.insert(flags, {flags_[i], flags_[i + 1]}) - end - end + local requiresflags = get_requiresflags(target, module.requires) + if requiresflags then + target:fileconfig_add(module.cppfile, {force = {cxxflags = requiresflags}}) end - target:fileconfig_add(module.cppfile, {force = {cxxflags = flags}}) end end end @@ -680,5 +656,17 @@ function get_requiresflags(target, requires) ::continue:: end - return flags + local requireflags = {} + local contains = {} + for i = 1, #flags, 2 do + local value = flags[i + 1] + if not contains[value] then + local key = flags[i] + table.insert(requireflags, {key, value}) + contains[value] = true + end + end + if #requireflags > 0 then + return requireflags + end end |
