From 768bca92e3cd079b03879f2b872a7df548ef91ff Mon Sep 17 00:00:00 2001 From: Arthur LAURENT Date: Thu, 1 Dec 2022 00:31:52 +0100 Subject: [PATCH] update msvc.lua --- xmake/rules/c++/modules/modules_support/msvc.lua | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/xmake/rules/c++/modules/modules_support/msvc.lua b/xmake/rules/c++/modules/modules_support/msvc.lua index 0f71339bcd5..c1c8c9320c2 100644 --- a/xmake/rules/c++/modules/modules_support/msvc.lua +++ b/xmake/rules/c++/modules/modules_support/msvc.lua @@ -143,8 +143,12 @@ function generate_dependencies(target, sourcebatch, opt) 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(), table.join(compinst:compflags({target = target}), {"/TP", "/P", file, "/Fi" .. ifile})) + os.vrunv(compinst:program(), table.join(defines, {"/nologo", get_cppversionflag(target), "/P", file, "/Fi" .. ifile})) return io.readfile(ifile) end) end @@ -700,3 +704,13 @@ function get_requiresflags(target, requires, opt) return requireflags end 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++latest") + end + return cppversionflag or nil +end