From 6bcfad861ab7c499681e3a48ecdfd9262ef3d683 Mon Sep 17 00:00:00 2001 From: Arthur LAURENT Date: Wed, 30 Nov 2022 18:05:05 +0100 Subject: Generate dependencies of preprocessed modules to avoid importing #ifdef import --- xmake/rules/c++/modules/modules_support/clang.lua | 7 ++++++- xmake/rules/c++/modules/modules_support/common.lua | 4 ++-- xmake/rules/c++/modules/modules_support/gcc.lua | 6 +++++- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/xmake/rules/c++/modules/modules_support/clang.lua b/xmake/rules/c++/modules/modules_support/clang.lua index e67bacef1..160c08b25 100644 --- a/xmake/rules/c++/modules/modules_support/clang.lua +++ b/xmake/rules/c++/modules/modules_support/clang.lua @@ -150,7 +150,12 @@ function generate_dependencies(target, sourcebatch, opt) -- no support of p1689 atm local jsonfile = path.translate(path.join(outputdir, path.filename(sourcefile) .. ".json")) - common.fallback_generate_dependencies(target, jsonfile, sourcefile) + common.fallback_generate_dependencies(target, jsonfile, sourcefile, function(file) + local compinst = target:compiler("cxx") + local ifile = path.translate(path.join(outputdir, path.filename(file) .. ".i")) + os.vrunv(compinst:program(), {"-E", "-x", "c++", file, "-o", ifile}) + return io.readfile(ifile) + end) changed = true local dependinfo = io.readfile(jsonfile) diff --git a/xmake/rules/c++/modules/modules_support/common.lua b/xmake/rules/c++/modules/modules_support/common.lua index 593913887..e91712ffd 100644 --- a/xmake/rules/c++/modules/modules_support/common.lua +++ b/xmake/rules/c++/modules/modules_support/common.lua @@ -376,7 +376,7 @@ end } ] }]] -function fallback_generate_dependencies(target, jsonfile, sourcefile) +function fallback_generate_dependencies(target, jsonfile, sourcefile, preprocess_file) local output = {version = 0, revision = 0, rules = {}} local rule = {outputs = {jsonfile}} rule["primary-output"] = target:objectfile(sourcefile) @@ -385,7 +385,7 @@ function fallback_generate_dependencies(target, jsonfile, sourcefile) local module_name_private local module_deps = {} local module_deps_set = hashset.new() - local sourcecode = io.readfile(sourcefile) + local sourcecode = preprocess_file(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 20a8437aa..1d26a543e 100644 --- a/xmake/rules/c++/modules/modules_support/gcc.lua +++ b/xmake/rules/c++/modules/modules_support/gcc.lua @@ -145,7 +145,11 @@ function generate_dependencies(target, sourcebatch, opt) local args = {sourcefile, "-MD", "-MT", jsonfile, "-MF", dfile, depfileflag .. jsonfile, trtbdflag, depoutputfile .. target:objectfile(sourcefile), "-o", ifile} os.vrunv(compinst:program(), table.join(compinst:compflags({target = target}), common_args, args), {envs = vcvars}) else - common.fallback_generate_dependencies(target, jsonfile, sourcefile) + common.fallback_generate_dependencies(target, jsonfile, sourcefile, function(file) + local ifile = path.translate(path.join(outputdir, path.filename(file) .. ".i")) + os.vrunv(compinst:program(), {"-E", "-x", "c++", file, "-o", ifile}) + return io.readfile(ifile) + end) end changed = true -- cgit v1.3.1 From 7ead9d50bb600a60387009f8dcc98ab87ff21789 Mon Sep 17 00:00:00 2001 From: Arthur LAURENT Date: Wed, 30 Nov 2022 18:08:37 +0100 Subject: add test --- tests/projects/c++/modules/ifdef_module/src/main.cpp | 7 +++++++ tests/projects/c++/modules/ifdef_module/test.lua | 1 + tests/projects/c++/modules/ifdef_module/xmake.lua | 6 ++++++ 3 files changed, 14 insertions(+) create mode 100644 tests/projects/c++/modules/ifdef_module/src/main.cpp create mode 100644 tests/projects/c++/modules/ifdef_module/test.lua create mode 100644 tests/projects/c++/modules/ifdef_module/xmake.lua diff --git a/tests/projects/c++/modules/ifdef_module/src/main.cpp b/tests/projects/c++/modules/ifdef_module/src/main.cpp new file mode 100644 index 000000000..d7fd82548 --- /dev/null +++ b/tests/projects/c++/modules/ifdef_module/src/main.cpp @@ -0,0 +1,7 @@ +#ifdef FOO +import hello; +#endif + +int main() { + return 0; +} diff --git a/tests/projects/c++/modules/ifdef_module/test.lua b/tests/projects/c++/modules/ifdef_module/test.lua new file mode 100644 index 000000000..7717f8049 --- /dev/null +++ b/tests/projects/c++/modules/ifdef_module/test.lua @@ -0,0 +1 @@ +inherit(".test_base") diff --git a/tests/projects/c++/modules/ifdef_module/xmake.lua b/tests/projects/c++/modules/ifdef_module/xmake.lua new file mode 100644 index 000000000..ee931a801 --- /dev/null +++ b/tests/projects/c++/modules/ifdef_module/xmake.lua @@ -0,0 +1,6 @@ +add_rules("mode.release", "mode.debug") +set_languages("c++20") +target("ifdef_module") + set_kind("binary") + add_files("src/*.cpp") + set_policy("build.c++.modules", true) -- cgit v1.3.1 From eb78bb8a58ed6f2f4b737c2cf5905538e076824d Mon Sep 17 00:00:00 2001 From: Arthur LAURENT Date: Wed, 30 Nov 2022 18:31:43 +0100 Subject: preprocess msvc --- xmake/rules/c++/modules/modules_support/msvc.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/xmake/rules/c++/modules/modules_support/msvc.lua b/xmake/rules/c++/modules/modules_support/msvc.lua index 8048b7041..8138d6af1 100644 --- a/xmake/rules/c++/modules/modules_support/msvc.lua +++ b/xmake/rules/c++/modules/modules_support/msvc.lua @@ -141,7 +141,11 @@ function generate_dependencies(target, sourcebatch, opt) local flags = {jsonfile, sourcefile, "-Fo" .. target:objectfile(sourcefile)} os.vrunv(compinst:program(), table.join(compinst:compflags({target = target}), common_flags, flags), {envs = vcvars}) else - common.fallback_generate_dependencies(target, jsonfile, sourcefile) + common.fallback_generate_dependencies(target, jsonfile, sourcefile, function(file) + 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})) + return io.readfile(ifile) + end) end changed = true -- cgit v1.3.1 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/clang.lua | 6 +++++- xmake/rules/c++/modules/modules_support/common.lua | 2 +- 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 -- cgit v1.3.1 From 944c55ad89e0ee78d70451097f37ae11651e82b8 Mon Sep 17 00:00:00 2001 From: Arthur LAURENT Date: Thu, 1 Dec 2022 12:01:45 +0100 Subject: update msvc.lua update msvc.lua update msvc.lua update clang.lua update msvc.lua --- xmake/rules/c++/modules/modules_support/clang.lua | 2 +- xmake/rules/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 6e6a7cb89..437582ac2 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 8138d6af1..6305f7933 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 -- cgit v1.3.1 From 3758d42fbe0ed0b98a3022bcbf3217494275a6f3 Mon Sep 17 00:00:00 2001 From: Arthur LAURENT Date: Thu, 1 Dec 2022 15:13:12 +0100 Subject: fix cppversion flag cache in gcc.lua --- xmake/rules/c++/modules/modules_support/gcc.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/xmake/rules/c++/modules/modules_support/gcc.lua b/xmake/rules/c++/modules/modules_support/gcc.lua index 7e5d93f38..e58f875f3 100644 --- a/xmake/rules/c++/modules/modules_support/gcc.lua +++ b/xmake/rules/c++/modules/modules_support/gcc.lua @@ -517,6 +517,7 @@ function get_cppversionflag(target) 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" + _g.cppversionflag = cppversionflag end return cppversionflag or nil end \ No newline at end of file -- cgit v1.3.1 From e2c6eb2208f05cba0fe499656e2d8de1b70c9410 Mon Sep 17 00:00:00 2001 From: Arthur LAURENT Date: Thu, 1 Dec 2022 15:16:06 +0100 Subject: remove .i after reading it --- xmake/rules/c++/modules/modules_support/clang.lua | 4 +++- xmake/rules/c++/modules/modules_support/gcc.lua | 4 +++- xmake/rules/c++/modules/modules_support/msvc.lua | 5 +++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/xmake/rules/c++/modules/modules_support/clang.lua b/xmake/rules/c++/modules/modules_support/clang.lua index 6ba2508d3..6f8b87303 100644 --- a/xmake/rules/c++/modules/modules_support/clang.lua +++ b/xmake/rules/c++/modules/modules_support/clang.lua @@ -224,7 +224,9 @@ function generate_dependencies(target, sourcebatch, opt) 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})) - return io.readfile(ifile) + local content = io.readfile(ifile) + os.rm(ifile) + return content end) changed = true diff --git a/xmake/rules/c++/modules/modules_support/gcc.lua b/xmake/rules/c++/modules/modules_support/gcc.lua index e58f875f3..2b65acf27 100644 --- a/xmake/rules/c++/modules/modules_support/gcc.lua +++ b/xmake/rules/c++/modules/modules_support/gcc.lua @@ -187,7 +187,9 @@ function generate_dependencies(target, sourcebatch, opt) end local ifile = path.translate(path.join(outputdir, path.filename(file) .. ".i")) os.vrunv(compinst:program(), table.join(defines, {get_cppversionflag(target), "-E", "-x", "c++", file, "-o", ifile})) - return io.readfile(ifile) + local content = io.readfile(ifile) + os.rm(ifile) + return content end) end changed = true diff --git a/xmake/rules/c++/modules/modules_support/msvc.lua b/xmake/rules/c++/modules/modules_support/msvc.lua index 73aea8122..d153bc2d2 100644 --- a/xmake/rules/c++/modules/modules_support/msvc.lua +++ b/xmake/rules/c++/modules/modules_support/msvc.lua @@ -171,7 +171,6 @@ end -- generate dependency files 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) @@ -202,7 +201,9 @@ function generate_dependencies(target, sourcebatch, opt) end local ifile = path.translate(path.join(outputdir, path.filename(file) .. ".i")) os.vrunv(compinst:program(), table.join(defines, {"/nologo", get_cppversionflag(target), "/P", file, "/Fi" .. ifile}), {envs = vcvars}) - return io.readfile(ifile) + local content = io.readfile(ifile) + os.rm(ifile) + return content end) end changed = true -- cgit v1.3.1 From 6479822a2179db58dab05e0f1b60aa4cf6c48b98 Mon Sep 17 00:00:00 2001 From: Arthur LAURENT Date: Thu, 1 Dec 2022 15:57:04 +0100 Subject: fix msvc.lua --- xmake/rules/c++/modules/modules_support/common.lua | 5 +++-- xmake/rules/c++/modules/modules_support/msvc.lua | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/xmake/rules/c++/modules/modules_support/common.lua b/xmake/rules/c++/modules/modules_support/common.lua index 45a1cac2f..b21613f61 100644 --- a/xmake/rules/c++/modules/modules_support/common.lua +++ b/xmake/rules/c++/modules/modules_support/common.lua @@ -446,10 +446,10 @@ function fallback_generate_dependencies(target, jsonfile, sourcefile, preprocess sourcecode = sourcecode:gsub("/%*.-%*/", "") for _, line in ipairs(sourcecode:split("\n", {plain = true})) do if not module_name_export then - module_name_export = line:match("export%s+module%s+(.+)%s*;") + module_name_export = line:match("export%s+module%s+(.+)%s*;") or line:match("export%s+__preprocessed_module%s+(.+)%s*;") end if not module_name_private then - module_name_private = line:match("module%s+(.+)%s*;") + module_name_private = line:match("module%s+(.+)%s*;") or line:match("__preprocessed_module%s+(.+)%s*;") end local module_depname = line:match("import%s+(.+)%s*;") -- we need parse module interface dep in cxx/impl_unit.cpp, e.g. hello.mpp and hello_impl.cpp @@ -487,6 +487,7 @@ function fallback_generate_dependencies(target, jsonfile, sourcefile, preprocess local provide = {} provide["logical-name"] = module_name_export provide["source-path"] = path.absolute(sourcefile, project.directory()) + provide["is-interface"] = true rule.provides = {} table.insert(rule.provides, provide) diff --git a/xmake/rules/c++/modules/modules_support/msvc.lua b/xmake/rules/c++/modules/modules_support/msvc.lua index d153bc2d2..91b7afbc5 100644 --- a/xmake/rules/c++/modules/modules_support/msvc.lua +++ b/xmake/rules/c++/modules/modules_support/msvc.lua @@ -172,7 +172,7 @@ end -- generate dependency files function generate_dependencies(target, sourcebatch, opt) local toolchain = target:toolchain("msvc") - local vcvars = toolchain:config("vcvars") + local scandependenciesflag = nil -- get_scandependenciesflag(target) local scandependenciesflag = get_scandependenciesflag(target) local common_flags = {"-TP", scandependenciesflag} local cachedir = common.modules_cachedir(target) @@ -200,7 +200,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, {"/nologo", get_cppversionflag(target), "/P", file, "/Fi" .. ifile}), {envs = vcvars}) + os.vrunv(compinst:program(), table.join(defines, {"/nologo", get_cppversionflag(target), "/P", "-TP", file, "/Fi" .. ifile}), {envs = toolchain:runenvs()}) local content = io.readfile(ifile) os.rm(ifile) return content -- cgit v1.3.1 From daca55898c15cf8e486e29d55ebb11dfb0e6190b Mon Sep 17 00:00:00 2001 From: Arthur LAURENT Date: Thu, 1 Dec 2022 17:00:40 +0100 Subject: add includedirs to preprocess stage --- xmake/rules/c++/modules/modules_support/clang.lua | 20 ++++++++++++++++++-- xmake/rules/c++/modules/modules_support/gcc.lua | 18 +++++++++++++++++- xmake/rules/c++/modules/modules_support/msvc.lua | 20 +++++++++++++++++++- 3 files changed, 54 insertions(+), 4 deletions(-) diff --git a/xmake/rules/c++/modules/modules_support/clang.lua b/xmake/rules/c++/modules/modules_support/clang.lua index 6f8b87303..5fb5e4389 100644 --- a/xmake/rules/c++/modules/modules_support/clang.lua +++ b/xmake/rules/c++/modules/modules_support/clang.lua @@ -219,11 +219,27 @@ function generate_dependencies(target, sourcebatch, opt) common.fallback_generate_dependencies(target, jsonfile, sourcefile, function(file) local compinst = target:compiler("cxx") local defines = {} - for _, define in ipairs(target:get("defines")) do + for _, define in pairs(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 + for i, includedir in pairs(includedirs) do + includedirs[i] = "-I" .. includedir + 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(includedirs, defines, {"-E", "-x", "c++", file, "-o", ifile})) local content = io.readfile(ifile) os.rm(ifile) return content diff --git a/xmake/rules/c++/modules/modules_support/gcc.lua b/xmake/rules/c++/modules/modules_support/gcc.lua index 2b65acf27..64199c831 100644 --- a/xmake/rules/c++/modules/modules_support/gcc.lua +++ b/xmake/rules/c++/modules/modules_support/gcc.lua @@ -185,8 +185,24 @@ function generate_dependencies(target, sourcebatch, opt) 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 + for i, includedir in pairs(includedirs) do + includedirs[i] = "-I" .. includedir + end local ifile = path.translate(path.join(outputdir, path.filename(file) .. ".i")) - os.vrunv(compinst:program(), table.join(defines, {get_cppversionflag(target), "-E", "-x", "c++", file, "-o", ifile})) + os.vrunv(compinst:program(), table.join(includedirs, defines, {get_cppversionflag(target), "-E", "-x", "c++", file, "-o", ifile})) local content = io.readfile(ifile) os.rm(ifile) return content diff --git a/xmake/rules/c++/modules/modules_support/msvc.lua b/xmake/rules/c++/modules/modules_support/msvc.lua index 91b7afbc5..d0a052f4b 100644 --- a/xmake/rules/c++/modules/modules_support/msvc.lua +++ b/xmake/rules/c++/modules/modules_support/msvc.lua @@ -199,8 +199,26 @@ function generate_dependencies(target, sourcebatch, opt) 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(defines, {"/nologo", get_cppversionflag(target), "/P", "-TP", file, "/Fi" .. ifile}), {envs = toolchain:runenvs()}) + 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 -- cgit v1.3.1