diff options
| author | ruki <[email protected]> | 2022-12-02 08:52:39 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-12-02 08:52:39 +0800 |
| commit | 5fc45303b35401bc2b1cb8c898c010f1505fce84 (patch) | |
| tree | 3e7dbaa2cfe5c8b0a5d65b6d7a058dd1250f3283 /xmake/rules/c++/modules/modules_support/msvc.lua | |
| parent | 427f36fa0fc5250bf5a37b492102736bdd80867f (diff) | |
| parent | daca55898c15cf8e486e29d55ebb11dfb0e6190b (diff) | |
Merge pull request #3122 from Arthapz/process_modules
Generate dependencies of preprocessed modules to avoid importing #ifdef import
Diffstat (limited to 'xmake/rules/c++/modules/modules_support/msvc.lua')
| -rw-r--r-- | xmake/rules/c++/modules/modules_support/msvc.lua | 43 |
1 files changed, 42 insertions, 1 deletions
diff --git a/xmake/rules/c++/modules/modules_support/msvc.lua b/xmake/rules/c++/modules/modules_support/msvc.lua index d9f3019d6..da0f69535 100644 --- a/xmake/rules/c++/modules/modules_support/msvc.lua +++ b/xmake/rules/c++/modules/modules_support/msvc.lua @@ -208,6 +208,8 @@ end -- generate dependency files function generate_dependencies(target, sourcebatch, opt) + local toolchain = target:toolchain("msvc") + local scandependenciesflag = nil -- get_scandependenciesflag(target) local scandependenciesflag = get_scandependenciesflag(target) local common_flags = {"-TP", scandependenciesflag} local cachedir = common.modules_cachedir(target) @@ -228,7 +230,36 @@ function generate_dependencies(target, sourcebatch, opt) local flags = {jsonfile, sourcefile, "-Fo" .. target:objectfile(sourcefile)} _compile(target, table.join(common_flags, flags)) else - common.fallback_generate_dependencies(target, jsonfile, sourcefile) + 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 _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) + end + end + local includedirs = {} + for i, includedir in pairs(_includedirs) do + table.insert(includedirs, "/I") + table.insert(includedirs, includedir) + end + local ifile = path.translate(path.join(outputdir, path.filename(file) .. ".i")) + os.vrunv(compinst:program(), table.join(includedirs, defines, {"/nologo", get_cppversionflag(target), "/P", "-TP", file, "/Fi" .. ifile}), {envs = toolchain:runenvs()}) + local content = io.readfile(ifile) + os.rm(ifile) + return content + end) end changed = true @@ -789,3 +820,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 |
