diff options
| author | Arthur LAURENT <[email protected]> | 2023-01-06 19:43:26 +0100 |
|---|---|---|
| committer | Arthur LAURENT <[email protected]> | 2023-01-12 14:56:28 +0100 |
| commit | e89202a2c646e28b5fc59303df7500077f6eb0b4 (patch) | |
| tree | 339894dbeb3e20aca5d7fc7e5006237c5c62dfa9 /xmake/rules/c++/modules/modules_support | |
| parent | 9b1bbefd2ea8132c702bccfa35f9bab5787b66b1 (diff) | |
improve clang module compflags
Diffstat (limited to 'xmake/rules/c++/modules/modules_support')
| -rw-r--r-- | xmake/rules/c++/modules/modules_support/clang.lua | 38 |
1 files changed, 12 insertions, 26 deletions
diff --git a/xmake/rules/c++/modules/modules_support/clang.lua b/xmake/rules/c++/modules/modules_support/clang.lua index 4d1f07747..4c1dfeae5 100644 --- a/xmake/rules/c++/modules/modules_support/clang.lua +++ b/xmake/rules/c++/modules/modules_support/clang.lua @@ -152,9 +152,9 @@ end -- do compile for batchcmds -- @note we need use batchcmds:compilev to translate paths in compflags for generator, e.g. -Ixx -function _batchcmds_compile(batchcmds, target, flags) +function _batchcmds_compile(batchcmds, target, sourcefile, flags) local compinst = target:compiler("cxx") - local compflags = compinst:compflags({target = target}) + local compflags = compinst:compflags({sourcefile = sourcefile, target = target}) batchcmds:compilev(table.join(compflags or {}, flags), {compiler = compinst, sourcekind = "cxx"}) end @@ -163,7 +163,7 @@ function _build_modulefile(target, sourcefile, opt) local objectfile = opt.objectfile local dependfile = opt.dependfile local compinst = compiler.load("cxx", {target = target}) - local compflags = compinst:compflags({target = target}) + local compflags = compinst:compflags({sourcefile = sourcefile, target = target}) local dependinfo = option.get("rebuild") and {} or (depend.load(dependfile) or {}) -- need build this object? @@ -252,28 +252,15 @@ function generate_dependencies(target, sourcebatch, opt) local jsonfile = path.translate(path.join(outputdir, path.filename(sourcefile) .. ".json")) common.fallback_generate_dependencies(target, jsonfile, sourcefile, function(file) local compinst = target:compiler("cxx") - local defines = {} - for _, define in pairs(target:get("defines")) do - table.insert(defines, "-D" .. define) - end - local includedirs = table.join({}, target:get("includedirs")) - for _, dep in ipairs(target:orderdeps()) do - local includedir = dep:get("sysincludedirs") or dep:get("includedirs") - if includedir then - table.join2(includedirs, includedir) - end - end - for _, pkg in pairs(target:pkgs()) do - local includedir = pkg:get("sysincludedirs") or pkg:get("includedirs") - if includedir then - table.join2(includedirs, includedir) + local compflags = compinst:compflags({sourcefile = file, target = target}) + local flags = {} + for _, flag in pairs(compflags) do + if flag:startswith("-stdlib") or flag:startswith("-f") or flag:startswith("-D") or flag:startswith("-U") or flag:startswith("-I") or flag:startswith("-isystem") then + table.append(flags, flag) end end - for i, includedir in pairs(includedirs) do - includedirs[i] = "-I" .. includedir - end local ifile = path.translate(path.join(outputdir, path.filename(file) .. ".i")) - os.vrunv(compinst:program(), table.join(includedirs, defines, {"-E", "-x", "c++", file, "-o", ifile})) + os.vrunv(compinst:program(), table.join(flags, {"-E", "-x", "c++", file, "-o", ifile})) local content = io.readfile(ifile) os.rm(ifile) return content @@ -331,7 +318,7 @@ function generate_stl_headerunits_for_batchjobs(target, batchjobs, headerunits, end, {rootjob = opt.rootjob}) -- build headerunits - for i, headerunit in ipairs(headerunits) do + 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) @@ -361,9 +348,8 @@ function generate_stl_headerunits_for_batchcmds(target, batchcmds, headerunits, assert(has_headerunitsupport(target), "compiler(clang): does not support c++ header units!") -- build headerunits - local projectdir = os.projectdir() local depmtime = 0 - for i, headerunit in ipairs(headerunits) do + for _, headerunit in ipairs(headerunits) do local bmifile = path.join(stlcachedir, headerunit.name .. get_bmi_extension()) -- don't build same header unit at the same time if not common.memcache():get2(headerunit.name, "building") then @@ -629,7 +615,7 @@ function build_modules_for_batchcmds(target, batchcmds, objectfiles, modules, op {"-x", "c++-module", "--precompile", "-c", path(cppfile), "-o", path(provide.bmi)})) _add_module_to_mapper(target, name, provide.bmi) end - _batchcmds_compile(batchcmds, target, table.join(flags, + _batchcmds_compile(batchcmds, target, file, table.join(flags, not provide and {"-x", "c++"} or {}, {"-c", file, "-o", path(objectfile)})) target:add("objectfiles", objectfile) elseif requiresflags then |
