Skip to content

Commit 46da0cf

Browse files
committed
Merge #19: build: Add CMake-based build system (9 of N)
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
2 parents e592ad1 + ac7bc5b commit 46da0cf

File tree

2 files changed

+29
-17
lines changed

2 files changed

+29
-17
lines changed

CMakeLists.txt

+3
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ if(WIN32)
102102
if(MSVC)
103103
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
104104
add_compile_options(/utf-8 /Zc:__cplusplus)
105+
# Improve parallelism in MSBuild.
106+
# See: https://devblogs.microsoft.com/cppblog/improved-parallelism-in-msbuild/.
107+
list(APPEND CMAKE_VS_GLOBALS "UseMultiToolTask=true")
105108
endif()
106109

107110
if(MINGW)

cmake/optional.cmake

+26-17
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,40 @@
55
# Optional features and packages.
66

77
if(CCACHE)
8-
find_program(CCACHE_EXECUTABLE ccache)
9-
if(CCACHE_EXECUTABLE)
10-
set(CCACHE ON)
8+
find_program(CCACHE_COMMAND ccache)
9+
if(CCACHE_COMMAND)
1110
if(MSVC)
12-
# See https://github.com/ccache/ccache/wiki/MS-Visual-Studio
13-
set(MSVC_CCACHE_WRAPPER_CONTENT "\"${CCACHE_EXECUTABLE}\" \"${CMAKE_CXX_COMPILER}\"")
14-
set(MSVC_CCACHE_WRAPPER_FILENAME wrapped-cl.bat)
15-
file(WRITE ${CMAKE_BINARY_DIR}/${MSVC_CCACHE_WRAPPER_FILENAME} "${MSVC_CCACHE_WRAPPER_CONTENT} %*")
16-
set(CMAKE_VS_GLOBALS
17-
"CLToolExe=${MSVC_CCACHE_WRAPPER_FILENAME}"
18-
"CLToolPath=${CMAKE_BINARY_DIR}"
19-
"TrackFileAccess=false"
20-
"UseMultiToolTask=true"
21-
"DebugInformationFormat=OldStyle"
22-
)
11+
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.24)
12+
# ccache >= 4.8 requires compile batching turned off that is available since CMake 3.24.
13+
# See https://github.com/ccache/ccache/wiki/MS-Visual-Studio
14+
set(CCACHE ON)
15+
set(MSVC_CCACHE_WRAPPER_CONTENT "\"${CCACHE_COMMAND}\" \"${CMAKE_CXX_COMPILER}\"")
16+
set(MSVC_CCACHE_WRAPPER_FILENAME wrapped-cl.bat)
17+
file(WRITE ${CMAKE_BINARY_DIR}/${MSVC_CCACHE_WRAPPER_FILENAME} "${MSVC_CCACHE_WRAPPER_CONTENT} %*")
18+
list(APPEND CMAKE_VS_GLOBALS
19+
"CLToolExe=${MSVC_CCACHE_WRAPPER_FILENAME}"
20+
"CLToolPath=${CMAKE_BINARY_DIR}"
21+
"DebugInformationFormat=OldStyle"
22+
)
23+
set(CMAKE_VS_NO_COMPILE_BATCHING ON)
24+
elseif(CCACHE STREQUAL "AUTO")
25+
message(WARNING "ccache requested and found, but CMake >= 3.24 is required to use it properly. Disabling.\n"
26+
"To skip ccache check, use \"-DCCACHE=OFF\".\n")
27+
set(CCACHE OFF)
28+
else()
29+
message(FATAL_ERROR "ccache requested and found, but CMake >= 3.24 is required to use it properly.")
30+
endif()
2331
else()
24-
list(APPEND CMAKE_C_COMPILER_LAUNCHER ${CCACHE_EXECUTABLE})
25-
list(APPEND CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE_EXECUTABLE})
32+
set(CCACHE ON)
33+
list(APPEND CMAKE_C_COMPILER_LAUNCHER ${CCACHE_COMMAND})
34+
list(APPEND CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE_COMMAND})
2635
endif()
2736
elseif(CCACHE STREQUAL "AUTO")
2837
set(CCACHE OFF)
2938
else()
3039
message(FATAL_ERROR "ccache requested, but not found.")
3140
endif()
32-
mark_as_advanced(CCACHE_EXECUTABLE)
41+
mark_as_advanced(CCACHE_COMMAND)
3342
endif()
3443

3544
if(WITH_NATPMP)

0 commit comments

Comments
 (0)