[clang] [flang] [llvm] [mlir] [polly] [CMake][LLVM] Add PCH infrastructure and LLVMSupport PCH (PR #176420)

Nikita Popov via cfe-commits cfe-commits at lists.llvm.org
Mon Jan 26 02:17:19 PST 2026


================
@@ -1304,11 +1304,48 @@ if (LLVM_BUILD_INSTRUMENTED AND LLVM_BUILD_INSTRUMENTED_COVERAGE)
   message(FATAL_ERROR "LLVM_BUILD_INSTRUMENTED and LLVM_BUILD_INSTRUMENTED_COVERAGE cannot both be specified")
 endif()
 
+if(NOT DEFINED CMAKE_DISABLE_PRECOMPILE_HEADERS)
+  if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
+    # Pre-compiled headers with GCC (tested versions 14+15) provide very little
+    # compile-time improvements, but substantially increase the build dir size.
+    # Therefore, disable PCH with GCC by default.
+    message(NOTICE "Precompiled headers are disabled by default with GCC. "
+      "Pass -DCMAKE_DISABLE_PRECOMPILE_HEADERS=OFF to override.")
+    set(CMAKE_DISABLE_PRECOMPILE_HEADERS ON)
+  endif()
+
+  # Warn on possibly unintended interactions with ccache/sccache if the user
+  # sets this via CMAKE_CXX_COMPILER_LAUNCHER (and not using LLVM_CCACHE_BUILD).
+  if(CMAKE_CXX_COMPILER_LAUNCHER MATCHES "sccache")
+    # It is unclear to what extent sccache supports PCH.
+    # https://github.com/mozilla/sccache/issues/615
+    message(WARNING "Using sccache with precompiled headers is unsupported. "
+      "Set CMAKE_DISABLE_PRECOMPILE_HEADERS to ON/OFF to silence this warning.")
----------------
nikic wrote:

Based on your last comment, it sounds like the sccache support situation is the same as ccache (i.e. only works for Clang), so should these two cases get merged?

https://github.com/llvm/llvm-project/pull/176420


More information about the cfe-commits mailing list