Skip to content

Commit 2c91043

Browse files
committed
[CMake] Fix using precompiled headers with ccache
Using precompiled headers with ccache requires special accommodations. Add the required CCACHE option and clang compiler flag to CMake. Signed-off-by: Kajetan Puchalski <[email protected]>
1 parent da3ee97 commit 2c91043

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

flang/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,11 @@ if (APPLE)
446446
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_POSIX_C_SOURCE=200809")
447447
endif()
448448

449+
# Clang requires this flag in order for precompiled headers to work with ccache.
450+
if (CMAKE_CXX_COMPILER_ID MATCHES Clang)
451+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Xclang -fno-pch-timestamp")
452+
endif()
453+
449454
list(REMOVE_DUPLICATES CMAKE_CXX_FLAGS)
450455

451456
# Determine HOST_LINK_VERSION on Darwin.

llvm/CMakeLists.txt

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

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

0 commit comments

Comments
 (0)