Add CMake option to build with CCache

This speeds up CMake recompilation significantly. The default behaviour is
to search for CCache and use it if available; this can be disabled explicitly
by setting OPENLOCO_USE_CCACHE=OFF in CMake.

Ported from OpenRCT2.
This commit is contained in:
ceeac 2020-08-14 09:18:52 +02:00 committed by Aaron van Geffen
parent 51001b8806
commit 6bc1794660
2 changed files with 38 additions and 0 deletions

View File

@ -3,6 +3,21 @@ cmake_policy(VERSION 3.9)
set (PROJECT openloco)
# Note: Searching for CCache must be before project() so project() can use CCache too
# if it is available
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
find_package(CCache)
if (CCache_FOUND)
option(OPENLOCO_USE_CCACHE "Use CCache to improve recompilation speed (optional)" ON)
if (OPENLOCO_USE_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 (OPENLOCO_USE_CCACHE)
endif (CCache_FOUND)
project(${PROJECT} CXX)
if (APPLE)

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)