Skip to content

Commit

Permalink
Merge #19: build: Add CMake-based build system (9 of N)
Browse files Browse the repository at this point in the history
ac7bc5b [FIXUP] Rename CCACHE_EXECUTABLE --> CCACHE_COMMAND for consistency (Hennadii Stepanov)
0476509 [FIXUP] Learn to work with recent ccache in MSVC builds (Hennadii Stepanov)
2fd67c7 [FIXUP] Do not disable `TrackFileAccess` in MSVC builds (Hennadii Stepanov)
a53ae12 [FIXUP] Use Multi-ToolTask in MSVC builds by default (Hennadii Stepanov)

Pull request description:

  The parent PR: bitcoin#25797.
  The previous PRs in the staging branch: #5, #6, #7, #10, #13, #15, #17, #18.

  This PR consists of fixups related to using [Ccache](https://ccache.dev/) in MSVC builds.

Top commit has no ACKs.

Tree-SHA512: dc01202b054aaeb5b46607bc93126bee0df523df3b4f2df54b566b2e2d6306d784a723fd4a999d0d84fdf31e926a72304790f94b9d57034db0c112ee9f52070e
  • Loading branch information
hebasto committed Jul 20, 2023
2 parents e592ad1 + ac7bc5b commit 46da0cf
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 17 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ if(WIN32)
if(MSVC)
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
add_compile_options(/utf-8 /Zc:__cplusplus)
# Improve parallelism in MSBuild.
# See: https://devblogs.microsoft.com/cppblog/improved-parallelism-in-msbuild/.
list(APPEND CMAKE_VS_GLOBALS "UseMultiToolTask=true")
endif()

if(MINGW)
Expand Down
43 changes: 26 additions & 17 deletions cmake/optional.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,40 @@
# Optional features and packages.

if(CCACHE)
find_program(CCACHE_EXECUTABLE ccache)
if(CCACHE_EXECUTABLE)
set(CCACHE ON)
find_program(CCACHE_COMMAND ccache)
if(CCACHE_COMMAND)
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"
)
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.24)
# ccache >= 4.8 requires compile batching turned off that is available since CMake 3.24.
# See https://github.com/ccache/ccache/wiki/MS-Visual-Studio
set(CCACHE ON)
set(MSVC_CCACHE_WRAPPER_CONTENT "\"${CCACHE_COMMAND}\" \"${CMAKE_CXX_COMPILER}\"")
set(MSVC_CCACHE_WRAPPER_FILENAME wrapped-cl.bat)
file(WRITE ${CMAKE_BINARY_DIR}/${MSVC_CCACHE_WRAPPER_FILENAME} "${MSVC_CCACHE_WRAPPER_CONTENT} %*")
list(APPEND CMAKE_VS_GLOBALS
"CLToolExe=${MSVC_CCACHE_WRAPPER_FILENAME}"
"CLToolPath=${CMAKE_BINARY_DIR}"
"DebugInformationFormat=OldStyle"
)
set(CMAKE_VS_NO_COMPILE_BATCHING ON)
elseif(CCACHE STREQUAL "AUTO")
message(WARNING "ccache requested and found, but CMake >= 3.24 is required to use it properly. Disabling.\n"
"To skip ccache check, use \"-DCCACHE=OFF\".\n")
set(CCACHE OFF)
else()
message(FATAL_ERROR "ccache requested and found, but CMake >= 3.24 is required to use it properly.")
endif()
else()
list(APPEND CMAKE_C_COMPILER_LAUNCHER ${CCACHE_EXECUTABLE})
list(APPEND CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE_EXECUTABLE})
set(CCACHE ON)
list(APPEND CMAKE_C_COMPILER_LAUNCHER ${CCACHE_COMMAND})
list(APPEND CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE_COMMAND})
endif()
elseif(CCACHE STREQUAL "AUTO")
set(CCACHE OFF)
else()
message(FATAL_ERROR "ccache requested, but not found.")
endif()
mark_as_advanced(CCACHE_EXECUTABLE)
mark_as_advanced(CCACHE_COMMAND)
endif()

if(WITH_NATPMP)
Expand Down

0 comments on commit 46da0cf

Please sign in to comment.