summaryrefslogtreecommitdiff
path: root/xmake/rules/c++/modules/modules_support/clang.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2022-12-02 08:52:39 +0800
committerGitHub <[email protected]>2022-12-02 08:52:39 +0800
commit5fc45303b35401bc2b1cb8c898c010f1505fce84 (patch)
tree3e7dbaa2cfe5c8b0a5d65b6d7a058dd1250f3283 /xmake/rules/c++/modules/modules_support/clang.lua
parent427f36fa0fc5250bf5a37b492102736bdd80867f (diff)
parentdaca55898c15cf8e486e29d55ebb11dfb0e6190b (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/clang.lua')
-rw-r--r--xmake/rules/c++/modules/modules_support/clang.lua29
1 files changed, 28 insertions, 1 deletions
diff --git a/xmake/rules/c++/modules/modules_support/clang.lua b/xmake/rules/c++/modules/modules_support/clang.lua
index 379aa517c..ad32931de 100644
--- a/xmake/rules/c++/modules/modules_support/clang.lua
+++ b/xmake/rules/c++/modules/modules_support/clang.lua
@@ -253,7 +253,34 @@ 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 defines = {}
+ 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(includedirs, defines, {"-E", "-x", "c++", file, "-o", ifile}))
+ local content = io.readfile(ifile)
+ os.rm(ifile)
+ return content
+ end)
changed = true
local dependinfo = io.readfile(jsonfile)