diff --git a/CMakeLists.txt b/CMakeLists.txt index 915912af5..9deb22a2a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -76,26 +76,16 @@ option(SRB2_CONFIG_ZDEBUG "Compile with ZDEBUG defined." OFF) option(SRB2_CONFIG_PROFILEMODE "Compile for profiling (GCC only)." OFF) set(SRB2_CONFIG_ASSET_DIRECTORY "" CACHE PATH "Path to directory that contains all asset files for the installer. If set, assets will be part of installation and cpack.") -# Enable CCache -# (Set USE_CCACHE=ON to use, CCACHE_OPTIONS for options) -if("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL Windows) - option(USE_CCACHE "Enable ccache support" OFF) - - if(USE_CCACHE) - find_program(CCACHE_TOOL_PATH ccache) - if(CCACHE_TOOL_PATH) - set(CMAKE_C_COMPILER_LAUNCHER ${CCACHE_TOOL_PATH} CACHE STRING "" FORCE) - set(CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE_TOOL_PATH} CACHE STRING "" FORCE) - else() - message(WARNING "USE_CCACHE was set but ccache is not found (set CCACHE_TOOL_PATH)") - endif() +# Enable CCache early +set(SRB2_USE_CCACHE OFF CACHE BOOL "Use CCache") +if (${SRB2_USE_CCACHE}) + find_program(CCACHE_PROGRAM ccache) + if(CCACHE_PROGRAM) + message(STATUS "Found CCache: ${CCACHE_PROGRAM}") + set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_PROGRAM}") + else() + message(WARNING "You have specified to use CCACHE but it was not found. Object files will not be cached.") endif() -else() - CPMAddPackage( - NAME Ccache.cmake - GITHUB_REPOSITORY TheLartians/Ccache.cmake - VERSION 1.2 - ) endif() # Dependencies diff --git a/cmake/launch-c.in b/cmake/launch-c.in new file mode 100644 index 000000000..c60558232 --- /dev/null +++ b/cmake/launch-c.in @@ -0,0 +1,3 @@ +#!/bin/sh +export CCACHE_CPP2=true +exec "${RULE_LAUNCH_COMPILE}" "${CMAKE_C_COMPILER}" "$@" diff --git a/cmake/launch-cxx.in b/cmake/launch-cxx.in new file mode 100644 index 000000000..c60558232 --- /dev/null +++ b/cmake/launch-cxx.in @@ -0,0 +1,3 @@ +#!/bin/sh +export CCACHE_CPP2=true +exec "${RULE_LAUNCH_COMPILE}" "${CMAKE_C_COMPILER}" "$@" -- 2.40.1