diff --git a/MANUAL.txt b/MANUAL.txt index 4be33ae..478d36b 100644 --- a/MANUAL.txt +++ b/MANUAL.txt @@ -629,6 +629,8 @@ things to make it work properly: -- ** use the *-include* compiler option to include the precompiled header (i.e., don't use *#include* in the source code to include the header); or +** (Clang compiler) use the *-include-pch* compiler option to include + the PCH file generated from the precompiled header; or ** add the *-fpch-preprocess* compiler option when compiling. If you don't do this, either the non-precompiled version of the header file diff --git a/ccache.c b/ccache.c index 8b50c36..12b62a4 100644 --- a/ccache.c +++ b/ccache.c @@ -167,7 +167,7 @@ static bool profile_use = false; static bool profile_generate = false; /* - * Whether we are using a precompiled header (either via -include or #include). + * Whether we are using a precompiled header (either via -include, #include or clang's -include-pch). */ static bool using_precompiled_header = false; @@ -1355,7 +1355,7 @@ find_compiler(char** argv) bool is_precompiled_header(const char *path) { - return str_eq(get_extension(path), ".gch"); + return str_eq(get_extension(path), ".gch") || str_eq(get_extension(path), ".pch"); } /* @@ -1680,7 +1680,6 @@ cc_process_args(struct args *orig_args, struct args **preprocessor_args, */ if (compopt_takes_path(argv[i])) { char *relpath; - char *pchpath; if (i == argc-1) { cc_log("Missing argument to %s", argv[i]); stats_update(STATS_ARGS); @@ -1693,13 +1692,27 @@ cc_process_args(struct args *orig_args, struct args **preprocessor_args, args_add(stripped_args, relpath); /* Try to be smart about detecting precompiled headers */ - pchpath = format("%s.gch", argv[i+1]); - if (stat(pchpath, &st) == 0) { - cc_log("Detected use of precompiled header: %s", pchpath); - found_pch = true; + if (str_eq(argv[i], "-include-pch")) { + if (stat(argv[i+1], &st) == 0) { + cc_log("Detected use of precompiled header: %s", argv[i+1]); + found_pch = true; + } + } else { + char* gchpath = format("%s.gch", argv[i+1]); + if (stat(gchpath, &st) == 0) { + cc_log("Detected use of precompiled header: %s", gchpath); + found_pch = true; + } else { + char* pchpath = format("%s.pch", argv[i+1]); + if (stat(pchpath, &st) == 0) { + cc_log("Detected use of precompiled header: %s", pchpath); + found_pch = true; + } + free(pchpath); + } + free(gchpath); } - free(pchpath); free(relpath); i++; continue; diff --git a/compopt.c b/compopt.c index 77b57f5..908302e 100644 --- a/compopt.c +++ b/compopt.c @@ -61,6 +61,7 @@ static const struct compopt compopts[] = { {"-imacros", AFFECTS_CPP | TAKES_ARG | TAKES_PATH}, {"-imultilib", AFFECTS_CPP | TAKES_ARG | TAKES_PATH}, {"-include", AFFECTS_CPP | TAKES_ARG | TAKES_PATH}, + {"-include-pch", AFFECTS_CPP | TAKES_ARG | TAKES_PATH}, {"-install_name", TAKES_ARG}, /* Darwin linker option */ {"-iprefix", AFFECTS_CPP | TAKES_ARG | TAKES_PATH}, {"-iquote", AFFECTS_CPP | TAKES_ARG | TAKES_PATH},