From 944c55ad89e0ee78d70451097f37ae11651e82b8 Mon Sep 17 00:00:00 2001 From: Arthur LAURENT Date: Thu, 1 Dec 2022 12:01:45 +0100 Subject: [PATCH] update msvc.lua update msvc.lua update msvc.lua update clang.lua update msvc.lua --- .../c++/modules/modules_support/clang.lua | 2 +- .../c++/modules/modules_support/msvc.lua | 19 +++++++++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/xmake/rules/c++/modules/modules_support/clang.lua b/xmake/rules/c++/modules/modules_support/clang.lua index 6e6a7cb89d2..437582ac241 100644 --- a/xmake/rules/c++/modules/modules_support/clang.lua +++ b/xmake/rules/c++/modules/modules_support/clang.lua @@ -157,7 +157,7 @@ function generate_dependencies(target, sourcebatch, opt) table.insert(defines, "-D" .. define) end local ifile = path.translate(path.join(outputdir, path.filename(file) .. ".i")) - os.vrunv(compinst:program(), table.join(defines, {"-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/msvc.lua b/xmake/rules/c++/modules/modules_support/msvc.lua index 8138d6af1b1..6305f7933a3 100644 --- a/xmake/rules/c++/modules/modules_support/msvc.lua +++ b/xmake/rules/c++/modules/modules_support/msvc.lua @@ -121,7 +121,7 @@ function generate_dependencies(target, sourcebatch, opt) local compinst = target:compiler("cxx") local toolchain = target:toolchain("msvc") local vcvars = toolchain:config("vcvars") - local scandependenciesflag = get_scandependenciesflag(target) + local scandependenciesflag = nil -- get_scandependenciesflag(target) local common_flags = {"-TP", scandependenciesflag} local cachedir = common.modules_cachedir(target) local changed = false @@ -142,8 +142,13 @@ function generate_dependencies(target, sourcebatch, opt) os.vrunv(compinst:program(), table.join(compinst:compflags({target = target}), common_flags, flags), {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(), 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}), {envs = vcvars}) return io.readfile(ifile) end) end @@ -699,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