summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2022-05-19 21:02:19 +0800
committerruki <[email protected]>2022-05-19 21:02:19 +0800
commitf70ee30b489fef9436425fbd30d72ffa5f955be1 (patch)
tree433b0ecaa8a0d2188eb3ff2ee152b99ebd44924f
parent95d7f5df2e1aa01cca69e74f0c4dadad8d37f4d0 (diff)
improve preprocess
-rw-r--r--xmake/modules/core/tools/gcc.lua12
1 files changed, 11 insertions, 1 deletions
diff --git a/xmake/modules/core/tools/gcc.lua b/xmake/modules/core/tools/gcc.lua
index 67667149a..72d3dc784 100644
--- a/xmake/modules/core/tools/gcc.lua
+++ b/xmake/modules/core/tools/gcc.lua
@@ -431,11 +431,21 @@ function _preprocess(program, argv, opt)
if not os.isdir(cppfiledir) then
os.mkdir(cppfiledir)
end
- -- TODO try -fdirectives-only
table.insert(cppflags, "-E")
+ -- it will be faster for preprocessing
+ -- when preprocessing, handle directives, but do not expand macros.
+ table.insert(cppflags, "-fdirectives-only")
table.insert(cppflags, "-o")
table.insert(cppflags, cppfile)
table.insert(cppflags, sourcefile)
+
+ -- we need mark as it when compiling the preprocessed source file
+ -- it will indicate to the preprocessor that the input file has already been preprocessed.
+ table.insert(flags, "-fpreprocessed")
+ -- with -fpreprocessed, predefinition of command line and most builtin macros is disabled.
+ table.insert(flags, "-fdirectives-only")
+
+ -- do preprocess
return try {function ()
local outdata, errdata = os.iorunv(program, cppflags, opt)
return {outdata = outdata, errdata = errdata, sourcefile = sourcefile, objectfile = objectfile, cppfile = cppfile, cppflags = flags}