diff --git a/.ci/ogc/build.sh b/.ci/ogc/build.sh index 55787a7e376..8e7558d45f5 100755 --- a/.ci/ogc/build.sh +++ b/.ci/ogc/build.sh @@ -13,6 +13,9 @@ ccache -M 2.0G # export CCACHE_LOGFILE=/tmp/cache.debug ccache -z +# To make ccache work properly with precompiled headers +ccache --set-config sloppiness=pch_defines,time_macros + cmake -GNinja \ -DUSE_CCACHE=ON \ -DWITH_QUICK=OFF \ diff --git a/.docker/docker-qgis-build.sh b/.docker/docker-qgis-build.sh index db3a3cc0cd2..e76a5cc13bd 100755 --- a/.docker/docker-qgis-build.sh +++ b/.docker/docker-qgis-build.sh @@ -18,6 +18,9 @@ ccache -M 2.0G # export CCACHE_LOGFILE=/tmp/cache.debug ccache -z +# To make ccache work properly with precompiled headers +ccache --set-config sloppiness=pch_defines,time_macros + ############################## # Variables for output styling ############################## diff --git a/.github/workflows/macos-build.yml b/.github/workflows/macos-build.yml index 2b906bca633..9eaeb447374 100644 --- a/.github/workflows/macos-build.yml +++ b/.github/workflows/macos-build.yml @@ -108,6 +108,8 @@ jobs: mkdir -p ${CCACHE_DIR} 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 -s - name: Run cmake diff --git a/.github/workflows/windows-qt6.yml b/.github/workflows/windows-qt6.yml index 39979ca7f97..a27fc344bcf 100644 --- a/.github/workflows/windows-qt6.yml +++ b/.github/workflows/windows-qt6.yml @@ -53,6 +53,12 @@ jobs: key: build-ccache-win64-qt6-${{ github.event.pull_request.base.ref || github.ref_name }} save: ${{ github.event_name == 'push' }} + - name: 🛍️ Tune ccache configuration + shell: bash + run: | + # To make ccache work properly with precompiled headers + ccache --set-config sloppiness=pch_defines,time_macros + - name: 🌱 Install dependencies and generate project files shell: bash run: | diff --git a/CMakeLists.txt b/CMakeLists.txt index 3eedb9b4f40..e09a8243dcf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -125,9 +125,28 @@ option(USE_CCACHE "Use ccache" ON) if (USE_CCACHE) find_program(CCACHE_FOUND ccache) if(CCACHE_FOUND) - set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache) - set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK 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) + string(FIND "${CCACHE_SLOPPINESS}" "pch_defines" fpch_defines_found_index) + string(FIND "${CCACHE_SLOPPINESS}" "time_macros" time_macros_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) + 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) + endif() + endif() endif(CCACHE_FOUND) endif(USE_CCACHE) diff --git a/ms-windows/mingw/build.sh b/ms-windows/mingw/build.sh index 9bc0d0e01c6..93d8b966bf7 100755 --- a/ms-windows/mingw/build.sh +++ b/ms-windows/mingw/build.sh @@ -67,6 +67,9 @@ fi 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 + # Cleanup rm -rf "$installroot"