diff --git a/.ci/ogc/build.sh b/.ci/ogc/build.sh index 8e7558d45f594..7bbfb6d43d24f 100755 --- a/.ci/ogc/build.sh +++ b/.ci/ogc/build.sh @@ -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 \ diff --git a/.docker/docker-qgis-build.sh b/.docker/docker-qgis-build.sh index e76a5cc13bd02..14da08465b359 100755 --- a/.docker/docker-qgis-build.sh +++ b/.docker/docker-qgis-build.sh @@ -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 diff --git a/.github/workflows/macos-build.yml b/.github/workflows/macos-build.yml index 9eaeb4473740c..9395c1c73676d 100644 --- a/.github/workflows/macos-build.yml +++ b/.github/workflows/macos-build.yml @@ -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 diff --git a/.github/workflows/windows-qt6.yml b/.github/workflows/windows-qt6.yml index 865953e64a30c..5562381d73944 100644 --- a/.github/workflows/windows-qt6.yml +++ b/.github/workflows/windows-qt6.yml @@ -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 diff --git a/CMakeLists.txt b/CMakeLists.txt index e09a8243dcfb9..f49f239fee197 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 (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() + 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 (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") + 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() - set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache) - set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache) 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) + 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) diff --git a/ms-windows/mingw/build.sh b/ms-windows/mingw/build.sh index 93d8b966bf7c5..c90e196b248f6 100755 --- a/ms-windows/mingw/build.sh +++ b/ms-windows/mingw/build.sh @@ -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"