From 35fc806c9f1d36bf686c57715249c24699b2905c Mon Sep 17 00:00:00 2001 From: Kajetan Puchalski Date: Wed, 23 Apr 2025 12:00:50 +0000 Subject: [PATCH 1/2] [CMake] Support using precompiled headers with ccache in flang 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 --- flang/CMakeLists.txt | 9 +++++++++ llvm/CMakeLists.txt | 4 ++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/flang/CMakeLists.txt b/flang/CMakeLists.txt index 76eb13295eb07..a2f59214aaf8d 100644 --- a/flang/CMakeLists.txt +++ b/flang/CMakeLists.txt @@ -452,6 +452,10 @@ if (LLVM_COMPILER_IS_GCC_COMPATIBLE) set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fno-semantic-interposition") endif() + # GCC requires this flag in order for precompiled headers to work with ccache + if (CMAKE_CXX_COMPILER_ID MATCHES GCC AND NOT CMAKE_DISABLE_PRECOMPILE_HEADERS) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpch-preprocess") + endif() endif() # Clang on Darwin enables non-POSIX extensions by default, which allows the @@ -462,6 +466,11 @@ if (APPLE) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_POSIX_C_SOURCE=200809") endif() +# Clang requires this flag in order for precompiled headers to work with ccache +if (CMAKE_CXX_COMPILER_ID MATCHES Clang AND NOT CMAKE_DISABLE_PRECOMPILE_HEADERS) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Xclang -fno-pch-timestamp") +endif() + list(REMOVE_DUPLICATES CMAKE_CXX_FLAGS) # Determine HOST_LINK_VERSION on Darwin. diff --git a/llvm/CMakeLists.txt b/llvm/CMakeLists.txt index 693cb085b8e2f..d47ac3ccffd05 100644 --- a/llvm/CMakeLists.txt +++ b/llvm/CMakeLists.txt @@ -273,7 +273,7 @@ if(LLVM_CCACHE_BUILD) if(CCACHE_PROGRAM) set(LLVM_CCACHE_MAXSIZE "" CACHE STRING "Size of ccache") set(LLVM_CCACHE_DIR "" CACHE STRING "Directory to keep ccached data") - set(LLVM_CCACHE_PARAMS "CCACHE_CPP2=yes CCACHE_HASHDIR=yes" + set(LLVM_CCACHE_PARAMS "CCACHE_CPP2=yes CCACHE_HASHDIR=yes CCACHE_SLOPPINESS=pch_defines,time_macros" CACHE STRING "Parameters to pass through to ccache") if(NOT CMAKE_SYSTEM_NAME MATCHES "Windows") @@ -287,7 +287,7 @@ if(LLVM_CCACHE_BUILD) set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ${CCACHE_PROGRAM}) else() if(LLVM_CCACHE_MAXSIZE OR LLVM_CCACHE_DIR OR - NOT LLVM_CCACHE_PARAMS MATCHES "CCACHE_CPP2=yes CCACHE_HASHDIR=yes") + NOT LLVM_CCACHE_PARAMS MATCHES "CCACHE_CPP2=yes CCACHE_HASHDIR=yes CCACHE_SLOPPINESS=pch_defines,time_macros") message(FATAL_ERROR "Ccache configuration through CMake is not supported on Windows. Please use environment variables.") endif() # RULE_LAUNCH_COMPILE should work with Ninja but currently has issues From a1bcf0f7b81511a1c255f37b940b8ba67e07ba79 Mon Sep 17 00:00:00 2001 From: Kajetan Puchalski Date: Thu, 24 Apr 2025 15:45:56 +0100 Subject: [PATCH 2/2] Apply suggestions from Meinersbur Co-authored-by: Michael Kruse --- flang/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/flang/CMakeLists.txt b/flang/CMakeLists.txt index a2f59214aaf8d..ed02fad6a6e66 100644 --- a/flang/CMakeLists.txt +++ b/flang/CMakeLists.txt @@ -453,7 +453,7 @@ if (LLVM_COMPILER_IS_GCC_COMPATIBLE) endif() # GCC requires this flag in order for precompiled headers to work with ccache - if (CMAKE_CXX_COMPILER_ID MATCHES GCC AND NOT CMAKE_DISABLE_PRECOMPILE_HEADERS) + if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND NOT CMAKE_DISABLE_PRECOMPILE_HEADERS) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpch-preprocess") endif() endif() @@ -467,7 +467,7 @@ if (APPLE) endif() # Clang requires this flag in order for precompiled headers to work with ccache -if (CMAKE_CXX_COMPILER_ID MATCHES Clang AND NOT CMAKE_DISABLE_PRECOMPILE_HEADERS) +if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND NOT CMAKE_DISABLE_PRECOMPILE_HEADERS) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Xclang -fno-pch-timestamp") endif()