From 97c36a86e182c2fcac292275badf2cd231eb8640 Mon Sep 17 00:00:00 2001 From: Arthur LAURENT Date: Wed, 30 Nov 2022 23:34:45 +0100 Subject: Add defines to clang and gcc --- xmake/rules/c++/modules/modules_support/gcc.lua | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'xmake/rules/c++/modules/modules_support/gcc.lua') 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 -- cgit v1.3.1