From 63f03d5e15fbe61cdda83af7cc6128ba5c400527 Mon Sep 17 00:00:00 2001 From: Gabriel Ferreira Date: Fri, 3 Jun 2022 18:26:30 -0300 Subject: [PATCH] build: re-enable PCH with CCache Includes: - disable PCH validation when using XCode - disable Clang's PCH timestamping - add ostream header to the PCH --- CMakeLists.txt | 12 ++++++------ build-support/macros-and-definitions.cmake | 12 ++++++++++++ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3c64fea45..ef32f33f7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,15 +4,15 @@ cmake_minimum_required(VERSION 3.10..3.10) # Use ccache if available -mark_as_advanced(CCACHE_FOUND) +mark_as_advanced(CCACHE) find_program(CCACHE ccache) if(NOT ("${CCACHE}" STREQUAL "CCACHE-NOTFOUND")) set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache) - message( - STATUS "CCache is enabled. Precompiled headers are disabled by default." - ) - set(NS3_PRECOMPILE_HEADERS OFF - CACHE BOOL "Precompile module headers to speed up compilation" FORCE + message(STATUS "CCache is enabled.") + execute_process( + COMMAND + ${CCACHE} --set-config + sloppiness=pch_defines,time_macros,include_file_mtime,include_file_ctime ) endif() diff --git a/build-support/macros-and-definitions.cmake b/build-support/macros-and-definitions.cmake index d816aeb68..e43eda439 100644 --- a/build-support/macros-and-definitions.cmake +++ b/build-support/macros-and-definitions.cmake @@ -1236,6 +1236,17 @@ macro(process_options) endif() if(${PRECOMPILE_HEADERS_ENABLED}) + if(CLANG) + # Clang adds a timestamp to the PCH, which prevents ccache from working + # correctly + # https://github.com/ccache/ccache/issues/539#issuecomment-664198545 + add_definitions(-Xclang -fno-pch-timestamp) + endif() + if(${XCODE}) + # XCode is weird and messes up with the PCH, requiring this flag + # https://github.com/ccache/ccache/issues/156 + add_definitions(-Xclang -fno-validate-pch) + endif() set(precompiled_header_libraries @@ -1247,6 +1258,7 @@ macro(process_options) +