source code only has to be preprocessed once. The downside is that some
compilers won't produce the same result (for instance diagnostics warnings)
when compiling preprocessed source code.
++
+An alternative to *run_second_cpp* is to use *-fdirectives-only* (for GCC) or
+*-frewrite-includes* (for Clang). This will cause the compiler to leave the
+macros and other preprocessor information, and only process the *#include*
+directives. When run in this way, the preprocessor arguments will be passed
+to the compiler since it still has to do _some_ preprocessing (like macros).
*sloppiness* (*CCACHE_SLOPPINESS*)::
bool found_color_diagnostics = false;
+ bool found_directives_only = false;
+ bool found_rewrite_includes = false;
+
int argc = expanded_args->argc;
char **argv = expanded_args->argv;
args_add(stripped_args, argv[0]);
continue;
}
+ // GCC
+ if (str_eq(argv[i], "-fdirectives-only")) {
+ found_directives_only = true;
+ }
+ // Clang
+ if (str_eq(argv[i], "-frewrite-includes")) {
+ found_rewrite_includes = true;
+ }
+
// Options taking an argument that we may want to rewrite to relative paths
// to get better hit rate. A secondary effect is that paths in the standard
// error output produced by the compiler will be normalized.
*compiler_args = args_copy(stripped_args);
if (conf->run_second_cpp) {
args_extend(*compiler_args, cpp_args);
+ } else if (found_directives_only || found_rewrite_includes) {
+ // Need to pass the macros and any other preprocessor directives again
+ args_extend(*compiler_args, cpp_args);
+ if (found_rewrite_includes) {
+ // The preprocessed source code still needs some more preprocessing
+ args_add(*compiler_args, "-x");
+ args_add(*compiler_args, actual_language);
+ }
} else if (explicit_language) {
// Workaround for a bug in Apple's patched distcc -- it doesn't properly
// reset the language specified with -x, so if -x is given, we have to