diff --git a/CMakeLists.txt b/CMakeLists.txt index 73eea24e..7b0c558b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,6 +26,9 @@ target_compile_features(project_options INTERFACE cxx_std_17) add_library(project_warnings INTERFACE) +# enable cache system +include(cmake/Cache.cmake) + # standard compiler warnings include(cmake/CompilerWarnings.cmake) # set_project_warnings(project_warnings) @@ -103,4 +106,4 @@ else() set(CPACK_SOURCE_GENERATOR TGZ) endif() -include(CPack) \ No newline at end of file +include(CPack) diff --git a/cmake/Cache.cmake b/cmake/Cache.cmake new file mode 100644 index 00000000..8664491d --- /dev/null +++ b/cmake/Cache.cmake @@ -0,0 +1,30 @@ +option(ENABLE_CACHE "Enable cache if available" ON) +if(NOT ENABLE_CACHE) + return() +endif() + +set(CACHE_OPTION + "ccache" + CACHE STRING "Compiler cache to be used") +set(CACHE_OPTION_VALUES "ccache" "sccache") +set_property(CACHE CACHE_OPTION PROPERTY STRINGS ${CACHE_OPTION_VALUES}) +list( + FIND + CACHE_OPTION_VALUES + ${CACHE_OPTION} + CACHE_OPTION_INDEX) + +if(${CACHE_OPTION_INDEX} EQUAL -1) + message( + STATUS + "Using custom compiler cache system: '${CACHE_OPTION}', explicitly supported entries are ${CACHE_OPTION_VALUES}") +endif() + +find_program(CACHE_BINARY ${CACHE_OPTION}) +if(CACHE_BINARY) + message(STATUS "${CACHE_OPTION} found and enabled") + set(CMAKE_CXX_COMPILER_LAUNCHER ${CACHE_BINARY}) +else() + message(WARNING "${CACHE_OPTION} is enabled but was not found. Not using it") +endif() +