Skip to content

Commit

Permalink
Fix issue with .gch ccach'ing not working with QT6 and gcc
Browse files Browse the repository at this point in the history
  • Loading branch information
rouault committed Dec 2, 2024
1 parent 075ea95 commit 116f81b
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .ci/ogc/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
2 changes: 1 addition & 1 deletion .docker/docker-qgis-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/macos-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/windows-qt6.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
41 changes: 31 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion ms-windows/mingw/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 116f81b

Please sign in to comment.