From 86c250d98f5842cb4bd971c95af301ebef2518b6 Mon Sep 17 00:00:00 2001 From: Joerg Bornemann Date: Sun, 6 Apr 2025 17:50:08 +0200 Subject: [PATCH] CMake: make ccache + pch + clang build more robust The ccache man page says we have to compile with -fno-pch-timestamp when using clang and precompiled headers. "Professional CMake" also recommends this approach, and the ccache statistics report a marginally better hit rate with this patch. Task-number: QTBUG-131650 Change-Id: Ic1c17a3977771673ac256674143dbdf8d5ffa28c Reviewed-by: Alexey Edelev --- cmake/QtInternalTargets.cmake | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/cmake/QtInternalTargets.cmake b/cmake/QtInternalTargets.cmake index d7c823995c0..a1f4cb7281c 100644 --- a/cmake/QtInternalTargets.cmake +++ b/cmake/QtInternalTargets.cmake @@ -381,6 +381,15 @@ if(QT_FEATURE_stdlib_libcpp) target_compile_definitions(PlatformCommonInternal INTERFACE _LIBCPP_REMOVE_TRANSITIVE_INCLUDES) endif() +if(QT_USE_CCACHE AND CLANG AND BUILD_WITH_PCH) + # The ccache man page says we must compile with -fno-pch-timestamp when using clang and pch. + foreach(language IN ITEMS C CXX OBJC OBJCXX) + target_compile_options(PlatformCommonInternal INTERFACE + "$<$:SHELL:-Xclang -fno-pch-timestamp>" + ) + endforeach() +endif() + # Hardening options qt_internal_apply_intel_cet_harderning(PlatformCommonInternal)