Fix issue with .gch ccach'ing not working with QT6 and gcc

This commit is contained in:
Even Rouault 2024-12-02 02:19:57 +01:00 committed by Nyall Dawson
parent ddaca73dbf
commit 8dd4f8455c
6 changed files with 38 additions and 17 deletions

View File

@ -14,7 +14,7 @@ ccache -M 2.0G
ccache -z
# To make ccache work properly with precompiled headers
ccache --set-config sloppiness=pch_defines,time_macros
ccache --set-config sloppiness=pch_defines,time_macros,include_file_mtime,include_file_ctime
cmake -GNinja \
-DUSE_CCACHE=ON \

View File

@ -19,7 +19,7 @@ ccache -M 2.0G
ccache -z
# To make ccache work properly with precompiled headers
ccache --set-config sloppiness=pch_defines,time_macros
ccache --set-config sloppiness=pch_defines,time_macros,include_file_mtime,include_file_ctime
##############################
# Variables for output styling

View File

@ -109,7 +109,7 @@ jobs:
brew install ccache
ccache --set-config=max_size=2.0G
# To make ccache work properly with precompiled headers
ccache --set-config sloppiness=pch_defines,time_macros
ccache --set-config sloppiness=pch_defines,time_macros,include_file_mtime,include_file_ctime
ccache -s
- name: Run cmake

View File

@ -57,7 +57,7 @@ jobs:
shell: bash
run: |
# To make ccache work properly with precompiled headers
ccache --set-config sloppiness=pch_defines,time_macros
ccache --set-config sloppiness=pch_defines,time_macros,include_file_mtime,include_file_ctime
- name: 🌱 Install dependencies and generate project files
shell: bash

View File

@ -128,25 +128,46 @@ if (USE_CCACHE)
message(STATUS "ccache found")
execute_process(COMMAND ccache --help OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE CCACHE_HELP)
execute_process(COMMAND ccache --get-config sloppiness OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE CCACHE_SLOPPINESS)
execute_process(COMMAND ccache --get-config compiler_type OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE CCACHE_COMPILER_TYPE)
string(FIND "${CCACHE_SLOPPINESS}" "pch_defines" fpch_defines_found_index)
string(FIND "${CCACHE_SLOPPINESS}" "time_macros" time_macros_found_index)
string(FIND "${CCACHE_SLOPPINESS}" "include_file_mtime" include_file_mtime_found_index)
string(FIND "${CCACHE_SLOPPINESS}" "include_file_ctime" include_file_ctime_found_index)
# Detect if we have ccache >= 4.8 which accepts passing configuration settings when invoking the compiler
string(FIND "${CCACHE_HELP}" "ccache [KEY=VALUE ...] compiler" ccache_key_value_found_index)
if (ccache_key_value_found_index EQUAL -1 )
if (fpch_defines_found_index EQUAL -1 OR time_macros_found_index EQUAL -1)
message(FATAL_ERROR "The use of precompiled headers only work if the ccache 'sloppiness' settings contains 'pch_defines' and 'time_macros'. Consider running 'ccache --set-config sloppiness=pch_defines,time_macros' to define them")
endif()
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache)
if (fpch_defines_found_index EQUAL -1 OR time_macros_found_index EQUAL -1 OR
(BUILD_WITH_QT6 AND (include_file_mtime_found_index EQUAL -1 OR include_file_ctime_found_index EQUAL -1)))
set(CCACHE_SLOPPINESS_REQUIRED "pch_defines,time_macros")
if (BUILD_WITH_QT6 AND (include_file_mtime_found_index EQUAL -1 OR include_file_ctime_found_index EQUAL -1))
string(APPEND CCACHE_SLOPPINESS_REQUIRED ",include_file_mtime,include_file_ctime")
endif()
else()
if (fpch_defines_found_index EQUAL -1 OR time_macros_found_index EQUAL -1)
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "ccache sloppiness=pch_defines,time_macros")
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK "ccache sloppiness=pch_defines,time_macros")
else()
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache)
set(CCACHE_SLOPPINESS_REQUIRED "")
endif()
if (BUILD_WITH_QT6 AND CMAKE_CXX_COMPILER STREQUAL "/usr/bin/c++" AND CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND NOT "${CCACHE_COMPILER_TYPE}" STREQUAL "gcc")
# Cf https://github.com/ccache/ccache/discussions/959
set(CCACHE_COMPILER_TYPE_GCC_REQUIRED ON)
else()
set(CCACHE_COMPILER_TYPE_GCC_REQUIRED OFF)
endif()
set(CCACHE_INVOCATION_COMMAND "ccache")
if (ccache_key_value_found_index EQUAL -1 )
if (CCACHE_SLOPPINESS_REQUIRED)
message(FATAL_ERROR "The use of precompiled headers only works if the ccache 'sloppiness' settings contains 'pch_defines' and 'time_macros'. Consider running 'ccache --set-config sloppiness=${CCACHE_SLOPPINESS_REQUIRED}' to define them")
endif()
if (CCACHE_COMPILER_TYPE_GCC_REQUIRED)
message(FATAL_ERROR "The use of precompiled headers only works properly with QT6 if the ccache 'compiler_type' settings is set to 'gcc'. Consider running 'ccache --set-config compiler_type=gcc'")
endif()
else()
if (CCACHE_SLOPPINESS_REQUIRED)
string(APPEND CCACHE_INVOCATION_COMMAND " sloppiness=${CCACHE_SLOPPINESS_REQUIRED}")
endif()
if (CCACHE_COMPILER_TYPE_GCC_REQUIRED)
string(APPEND CCACHE_INVOCATION_COMMAND " compiler_type=gcc")
endif()
endif()
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_INVOCATION_COMMAND}")
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK "${CCACHE_INVOCATION_COMMAND}")
endif(CCACHE_FOUND)
endif(USE_CCACHE)

View File

@ -68,7 +68,7 @@ installroot="$BUILDDIR/dist"
installprefix="$installroot/usr/$arch-w64-mingw32/sys-root/mingw"
# To make ccache work properly with precompiled headers
ccache --set-config sloppiness=pch_defines,time_macros
ccache --set-config sloppiness=pch_defines,time_macros,include_file_mtime,include_file_ctime
# Cleanup
rm -rf "$installroot"