Skip to content

Commit 0fcc9ff

Browse files
authored
[CMake] Support using precompiled headers with ccache in flang (#136856)
In order for precompiled headers to work with ccache, a specific flag needs to be passed to the compiler and ccache's sloppiness configuration option needs to be set appropriately. Due to issues with configuring CMake on certain Windows platforms, set the required ccache option only on non-Windows systems for the time being. ----- Signed-off-by: Kajetan Puchalski <[email protected]>
1 parent 9ae7aa7 commit 0fcc9ff

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

flang/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,10 @@ if (LLVM_COMPILER_IS_GCC_COMPATIBLE)
452452
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fno-semantic-interposition")
453453
endif()
454454

455+
# GCC requires this flag in order for precompiled headers to work with ccache
456+
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND NOT CMAKE_DISABLE_PRECOMPILE_HEADERS)
457+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpch-preprocess")
458+
endif()
455459
endif()
456460

457461
# Clang on Darwin enables non-POSIX extensions by default, which allows the
@@ -462,6 +466,11 @@ if (APPLE)
462466
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_POSIX_C_SOURCE=200809")
463467
endif()
464468

469+
# Clang requires this flag in order for precompiled headers to work with ccache
470+
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND NOT CMAKE_DISABLE_PRECOMPILE_HEADERS)
471+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Xclang -fno-pch-timestamp")
472+
endif()
473+
465474
list(REMOVE_DUPLICATES CMAKE_CXX_FLAGS)
466475

467476
# Determine HOST_LINK_VERSION on Darwin.

llvm/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ if(LLVM_CCACHE_BUILD)
273273
if(CCACHE_PROGRAM)
274274
set(LLVM_CCACHE_MAXSIZE "" CACHE STRING "Size of ccache")
275275
set(LLVM_CCACHE_DIR "" CACHE STRING "Directory to keep ccached data")
276-
set(LLVM_CCACHE_PARAMS "CCACHE_CPP2=yes CCACHE_HASHDIR=yes"
276+
set(LLVM_CCACHE_PARAMS "CCACHE_CPP2=yes CCACHE_HASHDIR=yes CCACHE_SLOPPINESS=pch_defines,time_macros"
277277
CACHE STRING "Parameters to pass through to ccache")
278278

279279
if(NOT CMAKE_SYSTEM_NAME MATCHES "Windows")
@@ -287,7 +287,7 @@ if(LLVM_CCACHE_BUILD)
287287
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ${CCACHE_PROGRAM})
288288
else()
289289
if(LLVM_CCACHE_MAXSIZE OR LLVM_CCACHE_DIR OR
290-
NOT LLVM_CCACHE_PARAMS MATCHES "CCACHE_CPP2=yes CCACHE_HASHDIR=yes")
290+
NOT LLVM_CCACHE_PARAMS MATCHES "CCACHE_CPP2=yes CCACHE_HASHDIR=yes CCACHE_SLOPPINESS=pch_defines,time_macros")
291291
message(FATAL_ERROR "Ccache configuration through CMake is not supported on Windows. Please use environment variables.")
292292
endif()
293293
# RULE_LAUNCH_COMPILE should work with Ninja but currently has issues

0 commit comments

Comments
 (0)