diff options
| author | Arthur LAURENT <[email protected]> | 2022-11-30 23:34:45 +0100 |
|---|---|---|
| committer | Arthur LAURENT <[email protected]> | 2022-11-30 23:34:45 +0100 |
| commit | 97c36a86e182c2fcac292275badf2cd231eb8640 (patch) | |
| tree | 17109ef162f0621ceb2a54454684f48c3cad3726 | |
| parent | 7735eb5da1f03fa0fc3152cfc4901daf3cad9845 (diff) | |
Add defines to clang and gcc
| -rw-r--r-- | xmake/rules/c++/modules/modules_support/clang.lua | 6 | ||||
| -rw-r--r-- | xmake/rules/c++/modules/modules_support/common.lua | 2 | ||||
| -rw-r--r-- | xmake/rules/c++/modules/modules_support/gcc.lua | 17 |
3 files changed, 22 insertions, 3 deletions
diff --git a/xmake/rules/c++/modules/modules_support/clang.lua b/xmake/rules/c++/modules/modules_support/clang.lua index 160c08b25..6e6a7cb89 100644 --- a/xmake/rules/c++/modules/modules_support/clang.lua +++ b/xmake/rules/c++/modules/modules_support/clang.lua @@ -152,8 +152,12 @@ 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 ipairs(target:get("defines")) do + table.insert(defines, "-D" .. define) + end local ifile = path.translate(path.join(outputdir, path.filename(file) .. ".i")) - os.vrunv(compinst:program(), {"-E", "-x", "c++", file, "-o", ifile}) + os.vrunv(compinst:program(), table.join(defines, {"-E", "-x", "c++", file, "-o", ifile})) return io.readfile(ifile) end) changed = true diff --git a/xmake/rules/c++/modules/modules_support/common.lua b/xmake/rules/c++/modules/modules_support/common.lua index e91712ffd..0779881d5 100644 --- a/xmake/rules/c++/modules/modules_support/common.lua +++ b/xmake/rules/c++/modules/modules_support/common.lua @@ -385,7 +385,7 @@ function fallback_generate_dependencies(target, jsonfile, sourcefile, preprocess local module_name_private local module_deps = {} local module_deps_set = hashset.new() - local sourcecode = preprocess_file(sourcefile) + local sourcecode = preprocess_file(sourcefile) or io.readfile(sourcefile) sourcecode = sourcecode:gsub("//.-\n", "\n") sourcecode = sourcecode:gsub("/%*.-%*/", "") for _, line in ipairs(sourcecode:split("\n", {plain = true})) do diff --git a/xmake/rules/c++/modules/modules_support/gcc.lua b/xmake/rules/c++/modules/modules_support/gcc.lua index 1d26a543e..3d427c1d2 100644 --- a/xmake/rules/c++/modules/modules_support/gcc.lua +++ b/xmake/rules/c++/modules/modules_support/gcc.lua @@ -146,8 +146,13 @@ function generate_dependencies(target, sourcebatch, opt) os.vrunv(compinst:program(), table.join(compinst:compflags({target = target}), common_args, args), {envs = vcvars}) else common.fallback_generate_dependencies(target, jsonfile, sourcefile, function(file) + local compinst = target:compiler("cxx") + local defines = {} + for _, define in ipairs(target:get("defines")) do + table.insert(defines, "-D" .. define) + end local ifile = path.translate(path.join(outputdir, path.filename(file) .. ".i")) - os.vrunv(compinst:program(), {"-E", "-x", "c++", file, "-o", ifile}) + os.vrunv(compinst:program(), table.join(defines, {get_cppversionflag(target), "-E", "-x", "c++", file, "-o", ifile})) return io.readfile(ifile) end) end @@ -477,3 +482,13 @@ function get_depoutputflag(target) end return depoutputflag or nil end + +function get_cppversionflag(target) + local cppversionflag = _g.cppversionflag + if cppversionflag == nil then + local compinst = target:compiler("cxx") + local flags = compinst:compflags({target = target}) + cppversionflag = table.find_if(flags, function(v) string.startswith(v, "-std=c++") end) or "-std=c++20" + end + return cppversionflag or nil +end
\ No newline at end of file |
