2022-05-17 17:06:13 +00:00
# Setup integration with ccache to speed up builds, see https://ccache.dev/
2022-05-10 11:51:34 +00:00
if ( CMAKE_CXX_COMPILER_LAUNCHER MATCHES "ccache" OR CMAKE_C_COMPILER_LAUNCHER MATCHES "ccache" )
2022-05-17 17:23:06 +00:00
# custom compiler launcher already defined, most likely because cmake was invoked with like "-DCMAKE_CXX_COMPILER_LAUNCHER=ccache" or
# via environment variable --> respect setting and trust that the launcher was specified correctly
message ( STATUS "Using custom C compiler launcher: ${CMAKE_C_COMPILER_LAUNCHER}" )
message ( STATUS "Using custom C++ compiler launcher: ${CMAKE_CXX_COMPILER_LAUNCHER}" )
return ( )
2020-08-27 11:04:17 +00:00
endif ( )
2022-05-17 17:58:38 +00:00
option ( ENABLE_CCACHE "Speedup re-compilations using ccache (external tool)" ON )
2020-08-27 11:04:17 +00:00
2022-05-17 17:58:38 +00:00
if ( NOT ENABLE_CCACHE )
message ( STATUS "Using ccache: no (disabled via configuration)" )
return ( )
2020-08-27 11:04:17 +00:00
endif ( )
2022-05-17 17:58:38 +00:00
find_program ( CCACHE_EXECUTABLE ccache )
2020-08-14 15:44:04 +00:00
2022-05-17 17:58:38 +00:00
if ( NOT CCACHE_EXECUTABLE )
message ( ${ RECONFIGURE_MESSAGE_LEVEL } "Using ccache: no (Could not find find ccache. To significantly reduce compile times for the 2nd, 3rd, etc. build, it is highly recommended to install ccache. To suppress this message, run cmake with -DENABLE_CCACHE=0)" )
2020-08-14 15:44:04 +00:00
return ( )
endif ( )
2022-05-17 17:58:38 +00:00
execute_process ( COMMAND ${ CCACHE_EXECUTABLE } "-V" OUTPUT_VARIABLE CCACHE_VERSION )
string ( REGEX REPLACE "ccache version ([0-9\\.]+).*" "\\1" CCACHE_VERSION ${ CCACHE_VERSION } )
2022-05-17 18:15:56 +00:00
set ( CCACHE_MINIMUM_VERSION 3.3 )
if ( CCACHE_VERSION VERSION_LESS_EQUAL ${ CCACHE_MINIMUM_VERSION } )
2022-05-18 10:43:43 +00:00
message ( ${ RECONFIGURE_MESSAGE_LEVEL } "Using ccache: no (found ${CCACHE_EXECUTABLE} (version ${CCACHE_VERSION}), the minimum required version is ${CCACHE_MINIMUM_VERSION}" )
return ( )
2022-05-17 18:15:56 +00:00
endif ( )
message ( STATUS "Using ccache: ${CCACHE_EXECUTABLE} (version ${CCACHE_VERSION})" )
set ( LAUNCHER ${ CCACHE_EXECUTABLE } )
# debian (debhelpers) set SOURCE_DATE_EPOCH environment variable, that is
# filled from the debian/changelog or current time.
#
# - 4.0+ ccache always includes this environment variable into the hash
# of the manifest, which do not allow to use previous cache,
# - 4.2+ ccache ignores SOURCE_DATE_EPOCH for every file w/o __DATE__/__TIME__
#
# Exclude SOURCE_DATE_EPOCH env for ccache versions between [4.0, 4.2).
if ( CCACHE_VERSION VERSION_GREATER_EQUAL "4.0" AND CCACHE_VERSION VERSION_LESS "4.2" )
message ( STATUS "Ignore SOURCE_DATE_EPOCH for ccache" )
set ( LAUNCHER env -u SOURCE_DATE_EPOCH ${ CCACHE_EXECUTABLE } )
endif ( )
set ( CMAKE_CXX_COMPILER_LAUNCHER ${ LAUNCHER } ${ CMAKE_CXX_COMPILER_LAUNCHER } )
set ( CMAKE_C_COMPILER_LAUNCHER ${ LAUNCHER } ${ CMAKE_C_COMPILER_LAUNCHER } )