]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
support for precompiled headers with clang
authorLuboš Luňák <l.lunak@suse.cz>
Fri, 6 Jul 2012 16:09:36 +0000 (18:09 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Fri, 13 Jul 2012 20:40:14 +0000 (22:40 +0200)
Support the clang-specific -include-pch option, which references
the PCH file itself, and support the .pch extension when using
the gcc -include way.

MANUAL.txt
ccache.c
compopt.c

index 4be33aedc88cd99e57e2bf049385c23a4faa6f7e..478d36be8efc7c2b97b0ea6ba6719f83941f9212 100644 (file)
@@ -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
index 8b50c36f18a758dab6d1fdb19b7dbe9a01666ac3..12b62a43a7bc6d0df4fe437484a7d5bec0146ad3 100644 (file)
--- 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;
index 77b57f592b13f0c3cf8216ad2760ade421d0cb44..908302e0a57b88048c257399c016c6b50bc43e20 100644 (file)
--- 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},