Skip to content

Commit 25e08c0

Browse files
authored
Revert "[CMake] Fix using precompiled headers with ccache" (#134848)
Reverts #131397 Reverting for now on account of build bot failures on certain platforms.
1 parent a51e282 commit 25e08c0

File tree

2 files changed

+16
-38
lines changed

2 files changed

+16
-38
lines changed

flang/CMakeLists.txt

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -452,10 +452,6 @@ 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 MATCHES GCC AND NOT CMAKE_DISABLE_PRECOMPILE_HEADERS)
457-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpch-preprocess")
458-
endif()
459455
endif()
460456

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

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-
474465
list(REMOVE_DUPLICATES CMAKE_CXX_FLAGS)
475466

476467
# Determine HOST_LINK_VERSION on Darwin.

llvm/CMakeLists.txt

Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -271,43 +271,30 @@ set(LLVM_CCACHE_BUILD OFF CACHE BOOL "Set to ON for a ccache enabled build")
271271
if(LLVM_CCACHE_BUILD)
272272
find_program(CCACHE_PROGRAM ccache)
273273
if(CCACHE_PROGRAM)
274-
# ccache --version example output: "ccache version 4.9.1\n(..)"
275-
execute_process(COMMAND ${CCACHE_PROGRAM} --version OUTPUT_VARIABLE CCACHE_VERSION_STR)
276-
string(REGEX MATCH "[0-9]+\.[0-9]+\.?[0-9]*" CCACHE_VERSION "${CCACHE_VERSION_STR}")
277-
278274
set(LLVM_CCACHE_MAXSIZE "" CACHE STRING "Size of ccache")
279275
set(LLVM_CCACHE_DIR "" CACHE STRING "Directory to keep ccached data")
276+
set(LLVM_CCACHE_PARAMS "CCACHE_CPP2=yes CCACHE_HASHDIR=yes"
277+
CACHE STRING "Parameters to pass through to ccache")
280278

281-
# ccache only supports passing options on the command line from version 4.8.0
282-
# use a workaround with ad-hoc environment variables for older versions
283-
if (CCACHE_VERSION VERSION_LESS "4.8.0")
284-
set(LLVM_CCACHE_PARAMS "CCACHE_CPP2=yes;CCACHE_HASHDIR=yes;CCACHE_SLOPPINESS=pch_defines,time_macros"
285-
CACHE STRING "Parameters to pass through to ccache")
286-
287-
set(launcher_params ${LLVM_CCACHE_PARAMS})
288-
if (CCACHE_MAXSIZE)
289-
set(launcher_params "CCACHE_MAXSIZE=${CCACHE_MAXSIZE};${launcher_params}")
279+
if(NOT CMAKE_SYSTEM_NAME MATCHES "Windows")
280+
set(CCACHE_PROGRAM "${LLVM_CCACHE_PARAMS} ${CCACHE_PROGRAM}")
281+
if (LLVM_CCACHE_MAXSIZE)
282+
set(CCACHE_PROGRAM "CCACHE_MAXSIZE=${LLVM_CCACHE_MAXSIZE} ${CCACHE_PROGRAM}")
290283
endif()
291-
if (CCACHE_DIR)
292-
set(launcher_params "CCACHE_DIR=${CCACHE_DIR};${launcher_params}")
284+
if (LLVM_CCACHE_DIR)
285+
set(CCACHE_PROGRAM "CCACHE_DIR=${LLVM_CCACHE_DIR} ${CCACHE_PROGRAM}")
293286
endif()
294-
set(launcher "${launcher_params};${CCACHE_PROGRAM}")
287+
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ${CCACHE_PROGRAM})
295288
else()
296-
set(LLVM_CCACHE_PARAMS "run_second_cpp=true;hash_dir=true;sloppiness=pch_defines,time_macros"
297-
CACHE STRING "Parameters to pass through to ccache")
298-
299-
set(launcher_params ${LLVM_CCACHE_PARAMS})
300-
if (CCACHE_MAXSIZE)
301-
set(launcher_params "max_size=${CCACHE_MAXSIZE};${launcher_params}")
289+
if(LLVM_CCACHE_MAXSIZE OR LLVM_CCACHE_DIR OR
290+
NOT LLVM_CCACHE_PARAMS MATCHES "CCACHE_CPP2=yes CCACHE_HASHDIR=yes")
291+
message(FATAL_ERROR "Ccache configuration through CMake is not supported on Windows. Please use environment variables.")
302292
endif()
303-
if (CCACHE_DIR)
304-
set(launcher_params "cache_dir=${CCACHE_DIR};${launcher_params}")
305-
endif()
306-
set(launcher "${CCACHE_PROGRAM};${launcher_params}")
293+
# RULE_LAUNCH_COMPILE should work with Ninja but currently has issues
294+
# with cmd.exe and some MSVC tools other than cl.exe
295+
set(CMAKE_C_COMPILER_LAUNCHER ${CCACHE_PROGRAM})
296+
set(CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE_PROGRAM})
307297
endif()
308-
309-
set(CMAKE_C_COMPILER_LAUNCHER ${launcher})
310-
set(CMAKE_CXX_COMPILER_LAUNCHER ${launcher})
311298
else()
312299
message(FATAL_ERROR "Unable to find the program ccache. Set LLVM_CCACHE_BUILD to OFF")
313300
endif()

0 commit comments

Comments
 (0)