1
0
Fork 0
forked from lthn/blockchain

Refactor ccache usage in CMake to enable it for all platforms and simplify usability checks

This commit is contained in:
snider 2025-10-06 21:45:00 +01:00
parent 34d465e583
commit 8fab38662c
2 changed files with 4 additions and 24 deletions

View file

@ -30,7 +30,7 @@ endif()
include(DocBuilder)
option (USE_CCACHE "Use ccache if a usable instance is found" ON)
if (USE_CCACHE AND NOT WIN32)
if (USE_CCACHE)
include(FindCcache)
else()
message(STATUS "ccache deselected")

View file

@ -1,28 +1,8 @@
find_program(CCACHE_FOUND ccache)
if (CCACHE_FOUND)
# Try to compile a test program with ccache, in order to verify if it really works. (needed on exotic setups)
set(TEST_PROJECT "${CMAKE_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/CMakeTmp")
file(WRITE "${TEST_PROJECT}/CMakeLists.txt" [=[
cmake_minimum_required(VERSION 3.10)
project(test)
option (CCACHE "")
cmake_policy(SET CMP0091 NEW)
file(WRITE "${CMAKE_SOURCE_DIR}/test.cpp" "int main() { return 0; }")
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE} cache_dir=${CMAKE_SOURCE_DIR}/build/.ccache")
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK "${CCACHE} cache_dir=${CMAKE_SOURCE_DIR}/build/.ccache")
add_executable(main test.cpp)
]=])
cmake_policy(SET CMP0091 NEW)
try_compile(RET "${TEST_PROJECT}/build" "${TEST_PROJECT}" "test" CMAKE_FLAGS -DCCACHE="${CCACHE_FOUND} -DCMAKE_POLICY_DEFAULT_CMP0091=NEW")
unset(TEST_PROJECT)
if (${RET})
# Success
message(STATUS "Found usable ccache: ${CCACHE_FOUND}")
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_FOUND} cache_dir=${CMAKE_SOURCE_DIR}/build/.ccache")
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK "${CCACHE_FOUND} cache_dir=${CMAKE_SOURCE_DIR}/build/.ccache")
else()
message(STATUS "Found ccache ${CCACHE_FOUND}, but is UNUSABLE! Return code: ${RET}")
endif()
message(STATUS "Found usable ccache: ${CCACHE_FOUND}")
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_FOUND} cache_dir=${CMAKE_SOURCE_DIR}/build/.ccache")
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK "${CCACHE_FOUND} cache_dir=${CMAKE_SOURCE_DIR}/build/.ccache")
else()
message(STATUS "ccache NOT found! Please install it for faster rebuilds.")
endif()