From f70ee30b489fef9436425fbd30d72ffa5f955be1 Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 19 May 2022 21:02:19 +0800 Subject: improve preprocess --- xmake/modules/core/tools/gcc.lua | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) 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} -- cgit v1.3.1