Add CCache discovery to CMake

This commit is contained in:
Michał Janiszewski 2021-04-15 11:51:42 +02:00
parent a035f64d8d
commit 593bc8db0e
2 changed files with 32 additions and 0 deletions

View File

@ -78,6 +78,7 @@ option(ENABLE_DEVMODE "Compile vesion for developers" off)
option(ENABLE_UI "Compile UI (turn off to compile CLI-only version)" on) option(ENABLE_UI "Compile UI (turn off to compile CLI-only version)" on)
option(FULLSCREEN_PLATFORM "Enable fullscreen by default" off) option(FULLSCREEN_PLATFORM "Enable fullscreen by default" off)
option(ENABLE_CLANG_TIDY "Enable static analysis" off) option(ENABLE_CLANG_TIDY "Enable static analysis" off)
option(ENABLE_CCACHE "Use CCache to improve recompilation speed (optional)" ON)
set(CUSTOM_WEBSITE_URL "" CACHE STRING "Enable custom local webserver to check updates") set(CUSTOM_WEBSITE_URL "" CACHE STRING "Enable custom local webserver to check updates")
if(ENABLE_NEWS OR ENABLE_UPDATER) if(ENABLE_NEWS OR ENABLE_UPDATER)
@ -169,6 +170,14 @@ set(ZLIB_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party/zlib)
# Search in the "cmake" directory for additional CMake modules. # Search in the "cmake" directory for additional CMake modules.
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
find_package(CCache)
if (CCache_FOUND AND ENABLE_CCACHE)
# Use e.g. "ccache clang++" instead of "clang++"
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCache_EXECUTABLE}")
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK "${CCache_EXECUTABLE}")
endif (CCache_FOUND AND ENABLE_CCACHE)
# Put libraries into "lib". # Put libraries into "lib".
set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib) set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib)

23
cmake/FindCCache.cmake Normal file
View File

@ -0,0 +1,23 @@
# To find CCache compiler cache
include(FindPackageHandleStandardArgs)
find_program(CCache_EXECUTABLE ccache)
if (CCache_EXECUTABLE)
execute_process(COMMAND "${CCache_EXECUTABLE}" --version
OUTPUT_VARIABLE CCache_VERSION_OUTPUT
)
if (CCache_VERSION_OUTPUT MATCHES "version ([0-9]+\\.[0-9]+\\.[0-9]+)")
set(CCache_VERSION "${CMAKE_MATCH_1}")
endif ()
endif (CCache_EXECUTABLE)
find_package_handle_standard_args(CCache
FOUND_VAR CCache_FOUND
REQUIRED_VARS CCache_EXECUTABLE
VERSION_VAR CCache_VERSION
)
mark_as_advanced(CCache_EXECUTABLE)