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 Apr 13, 2023
1 parent 480c8cb commit 15bcb8e
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ option(ASM "Use assembly routines." ON)
cmake_dependent_option(CXX20 "Enable compilation in C++20 mode." OFF "NOT MSVC" ON)
option(THREADLOCAL "Enable features that depend on the C++ thread_local keyword (currently just thread names in debug logs)." ON)

# TODO: These tri-state options will be removed and most features
# will become opt-in by default before merging into master.
include(TristateOption)
tristate_option(CCACHE "Use ccache for compiling." "if ccache is found." AUTO)

if(CXX20)
set(CMAKE_CXX_STANDARD 20)
else()
Expand Down Expand Up @@ -113,6 +118,8 @@ include(cmake/secp256k1.cmake)
include(CheckStdFilesystem)
check_std_filesystem()

include(cmake/optional.cmake)

if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.14)
include(CheckPIESupported)
check_pie_supported(OUTPUT_VARIABLE check_pie_output LANGUAGES CXX)
Expand Down Expand Up @@ -175,6 +182,7 @@ else()
message(" - LDFLAGS for shared libraries ....... ${CMAKE_SHARED_LINKER_FLAGS_RELEASE}")
endif()
message("Use assembly routines ................. ${ASM}")
message("Use ccache for compiling .............. ${CCACHE}")
message("\n")
if(configure_warnings)
message(" ******\n")
Expand Down
33 changes: 33 additions & 0 deletions cmake/optional.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright (c) 2023 The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.

# Optional features and packages.

if(CCACHE)
find_program(CCACHE_EXECUTABLE ccache)
if(CCACHE_EXECUTABLE)
set(CCACHE ON)
if(MSVC)
# See https://github.com/ccache/ccache/wiki/MS-Visual-Studio
set(MSVC_CCACHE_WRAPPER_CONTENT "\"${CCACHE_EXECUTABLE}\" \"${CMAKE_CXX_COMPILER}\"")
set(MSVC_CCACHE_WRAPPER_FILENAME wrapped-cl.bat)
file(WRITE ${CMAKE_BINARY_DIR}/${MSVC_CCACHE_WRAPPER_FILENAME} "${MSVC_CCACHE_WRAPPER_CONTENT} %*")
set(CMAKE_VS_GLOBALS
"CLToolExe=${MSVC_CCACHE_WRAPPER_FILENAME}"
"CLToolPath=${CMAKE_BINARY_DIR}"
"TrackFileAccess=false"
"UseMultiToolTask=true"
"DebugInformationFormat=OldStyle"
)
else()
list(APPEND CMAKE_C_COMPILER_LAUNCHER ${CCACHE_EXECUTABLE})
list(APPEND CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE_EXECUTABLE})
endif()
elseif(CCACHE STREQUAL "AUTO")
set(CCACHE OFF)
else()
message(FATAL_ERROR "ccache requested, but not found.")
endif()
mark_as_advanced(CCACHE_EXECUTABLE)
endif()

0 comments on commit 15bcb8e

Please sign in to comment.