Skip to content

Commit

Permalink
cmake: Add ccache support
Browse files Browse the repository at this point in the history
  • Loading branch information
hebasto committed Jul 31, 2024
1 parent ab9f7aa commit db3ebf4
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
9 changes: 9 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ set(CMAKE_CXX_EXTENSIONS OFF)

list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/module)

#=============================
# Configurable options
#=============================
# When adding a new option, end the <help_text> with a full stop for consistency.
option(WITH_CCACHE "Attempt to use ccache for compiling." ON)

set(configure_warnings)

include(CheckPIESupported)
Expand Down Expand Up @@ -178,6 +184,8 @@ target_link_libraries(core_interface INTERFACE

include(cmake/introspection.cmake)

include(cmake/ccache.cmake)

include(ProcessConfigurations)
set_default_config(RelWithDebInfo)

Expand Down Expand Up @@ -250,6 +258,7 @@ message("=================")
message("C++ compiler .......................... ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}, ${CMAKE_CXX_COMPILER}")
include(FlagsSummary)
flags_summary()
message("Use ccache for compiling .............. ${WITH_CCACHE}")
message("\n")
if(configure_warnings)
message(" ******\n")
Expand Down
25 changes: 25 additions & 0 deletions cmake/ccache.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright (c) 2023-present The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or https://opensource.org/license/mit/.

if(NOT MSVC)
find_program(CCACHE_EXECUTABLE ccache)
if(CCACHE_EXECUTABLE)
execute_process(
COMMAND readlink -f ${CMAKE_CXX_COMPILER}
OUTPUT_VARIABLE compiler_resolved_link
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(CCACHE_EXECUTABLE STREQUAL compiler_resolved_link)
set(WITH_CCACHE "ccache masquerades as the compiler")
elseif(WITH_CCACHE)
list(APPEND CMAKE_C_COMPILER_LAUNCHER ${CCACHE_EXECUTABLE})
list(APPEND CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE_EXECUTABLE})
endif()
else()
set(WITH_CCACHE OFF)
endif()
endif()

mark_as_advanced(CCACHE_EXECUTABLE)

0 comments on commit db3ebf4

Please sign in to comment.