From: Joel Rosdahl Date: Sat, 27 Apr 2024 13:22:40 +0000 (+0200) Subject: feat: Support -Xpreprocessor -fopenmp in direct mode X-Git-Tag: v4.10~35 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=bea737780727e751a8193fc80c83c7c072b8048e;p=thirdparty%2Fccache.git feat: Support -Xpreprocessor -fopenmp in direct mode All uses of -Xpreprocessor disable the direct mode as a safety measure since the command line could include things like -Xpreprocessor -MF -Xpreprocessor file.d which ccache needs to understand as -MF file.d Ideally, ccache should handle this in a generic way. Meanwhile, let's allow it in the a special case of "-Xpreprocessor -fopenmp" since that's required on macOS to enable OpenMP. Closes #1434. --- diff --git a/doc/MANUAL.adoc b/doc/MANUAL.adoc index 9e74030c..73aca1b3 100644 --- a/doc/MANUAL.adoc +++ b/doc/MANUAL.adoc @@ -1621,10 +1621,10 @@ The direct mode will be disabled if any of the following holds: * <> is false * a modification time of one of the include files is too new (needed to avoid a race condition) -* a compiler option not supported by the direct mode is used: +* a compiler option not supported by the direct mode is used, for example: ** a `-Wp,++*++` compiler option other than `-Wp,-MD,`, `-Wp,-MMD,`, `-Wp,-D` or `-Wp,-U` -** `-Xpreprocessor` +** most uses of `-Xpreprocessor` * the string `+__TIME__+` is present in the source code diff --git a/src/ccache/argprocessing.cpp b/src/ccache/argprocessing.cpp index f8f454eb..c0149833 100644 --- a/src/ccache/argprocessing.cpp +++ b/src/ccache/argprocessing.cpp @@ -433,6 +433,23 @@ process_option_arg(const Context& ctx, config.set_direct_mode(false); } + // Handle -Xpreprocessor options. + if (util::starts_with(arg, "-Xpreprocessor")) { + if (i == args.size() - 1) { + LOG("Missing argument to {}", args[i]); + return Statistic::bad_compiler_arguments; + } + if (args[i + 1] == "-fopenmp") { + ++i; + return Statistic::none; + } else { + LOG("Unsupported compiler option for direct mode: {} {}", + args[i], + args[i + 1]); + config.set_direct_mode(false); + } + } + // Handle -Xarch_* options. if (util::starts_with(arg, "-Xarch_")) { if (i == args.size() - 1) { diff --git a/src/ccache/compopt.cpp b/src/ccache/compopt.cpp index 04be7b63..ee4dcb7f 100644 --- a/src/ccache/compopt.cpp +++ b/src/ccache/compopt.cpp @@ -96,7 +96,7 @@ const CompOpt compopts[] = { {"-Xclang", TAKES_ARG}, {"-Xcompiler", AFFECTS_CPP | TAKES_ARG}, // nvcc {"-Xlinker", TAKES_ARG | TAKES_CONCAT_ARG | AFFECTS_COMP}, - {"-Xpreprocessor", AFFECTS_CPP | TOO_HARD_DIRECT | TAKES_ARG}, + {"-Xpreprocessor", AFFECTS_CPP | TAKES_ARG}, {"-Yc", AFFECTS_CPP | TAKES_ARG | TAKES_CONCAT_ARG | TAKES_PATH}, // msvc {"-Yu", AFFECTS_CPP | TAKES_ARG | TAKES_CONCAT_ARG | TAKES_PATH}, // msvc {"-all_load", AFFECTS_COMP}, diff --git a/unittest/test_compopt.cpp b/unittest/test_compopt.cpp index 84e10bbd..220d1486 100644 --- a/unittest/test_compopt.cpp +++ b/unittest/test_compopt.cpp @@ -65,7 +65,6 @@ TEST_CASE("too_hard") TEST_CASE("too_hard_for_direct_mode") { - CHECK(compopt_too_hard_for_direct_mode("-Xpreprocessor")); CHECK(!compopt_too_hard_for_direct_mode("-nostdinc")); }