Skip to content

Commit eb51963

Browse files
committed
Merge bitcoin#31884: cmake: Make implicit libbitcoinkernel dependencies explicit
3b42e05 cmake: Make implicit `libbitcoinkernel` dependencies explicit (Hennadii Stepanov) 3fd64ef cmake: Avoid using `OBJECT` libraries (Hennadii Stepanov) Pull request description: This PR fixes two regressions introduced in bitcoin#30911. For example, on the master branch @ 28dec6c: - first regression: ``` $ cmake -B build -G "Ninja" -DBUILD_UTIL_CHAINSTATE=ON -DBUILD_SHARED_LIBS=OFF -DCMAKE_INSTALL_PREFIX=/home/hebasto/INSTALL $ cmake --build build -j $(nproc) -t libbitcoinkernel $ cmake --install build --component libbitcoinkernel - Install configuration: "RelWithDebInfo" CMake Error at build/src/kernel/cmake_install.cmake:46 (file): file INSTALL cannot find "/home/hebasto/dev/bitcoin/build/src/crypto/libbitcoin_crypto.a": No such file or directory. Call Stack (most recent call first): build/src/cmake_install.cmake:172 (include) build/cmake_install.cmake:57 (include) ``` - second regression: ``` $ cmake -B build -G "Unix Makefiles" -DBUILD_UTIL_CHAINSTATE=ON -DBUILD_SHARED_LIBS=OFF -DCMAKE_INSTALL_PREFIX=/home/hebasto/INSTALL $ cmake --build build -j $(nproc) -t libbitcoinkernel ... gmake[3]: *** No rule to make target 'src/CMakeFiles/bitcoin_clientversion.dir/clientversion.cpp.o', needed by 'src/kernel/libbitcoinkernel.a'. Stop. gmake[2]: *** [CMakeFiles/Makefile2:1360: src/kernel/CMakeFiles/bitcoinkernel.dir/all] Error 2 gmake[1]: *** [CMakeFiles/Makefile2:1367: src/kernel/CMakeFiles/bitcoinkernel.dir/rule] Error 2 gmake: *** [Makefile:647: bitcoinkernel] Error 2 ``` With this PR: ``` $ cmake -B build -G "Ninja" -DBUILD_UTIL_CHAINSTATE=ON -DBUILD_SHARED_LIBS=OFF -DCMAKE_INSTALL_PREFIX=/home/hebasto/INSTALL $ cmake --build build -j $(nproc) -t libbitcoinkernel $ cmake --install build --component libbitcoinkernel ``` and ``` $ cmake -B build -G "Unix Makefiles" -DBUILD_UTIL_CHAINSTATE=ON -DBUILD_SHARED_LIBS=OFF -DCMAKE_INSTALL_PREFIX=/home/hebasto/INSTALL $ cmake --build build -j $(nproc) -t libbitcoinkernel $ cmake --install build --component libbitcoinkernel ``` --- **A note for reviewers:** An alternative approach would be to disable the `OPTIMIZE_DEPENDENCIES` property for the `bitcoinkernel` target. However, I contend that this PR is preferable because (1) it preserves parallel builds for the `libbitcoinkernel` target, and (2) the resulting code has one less workaround for a CMake bug. ACKs for top commit: TheCharlatan: ACK 3b42e05 theuni: utACK 3b42e05 Tree-SHA512: 73e9da845688a02e5d61770b7cfd5e1a17440182eb524c7329a47df8f1daa6fe0f9cbde5274832bf43f52e17de86473881dc876dee4276c9c06b173b1b78b7a2
2 parents 58f15d4 + 3b42e05 commit eb51963

File tree

3 files changed

+6
-8
lines changed

3 files changed

+6
-8
lines changed

src/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ add_custom_target(generate_build_info
1313
COMMENT "Generating bitcoin-build-info.h"
1414
VERBATIM
1515
)
16-
add_library(bitcoin_clientversion OBJECT EXCLUDE_FROM_ALL
16+
add_library(bitcoin_clientversion STATIC EXCLUDE_FROM_ALL
1717
clientversion.cpp
1818
)
1919
target_link_libraries(bitcoin_clientversion

src/kernel/CMakeLists.txt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ set_target_properties(bitcoinkernel PROPERTIES
102102
CXX_VISIBILITY_PRESET default
103103
)
104104

105+
# Add a convenience libbitcoinkernel target as a synonym for bitcoinkernel.
106+
add_custom_target(libbitcoinkernel)
107+
add_dependencies(libbitcoinkernel bitcoinkernel)
108+
105109
# When building the static library, install all static libraries the
106110
# bitcoinkernel depends on.
107111
if(NOT BUILD_SHARED_LIBS)
@@ -110,6 +114,7 @@ if(NOT BUILD_SHARED_LIBS)
110114
get_target_property(linked_libraries ${target} LINK_LIBRARIES)
111115
foreach(dep ${linked_libraries})
112116
if(TARGET ${dep})
117+
add_dependencies(libbitcoinkernel ${dep})
113118
get_target_property(dep_type ${dep} TYPE)
114119
if(dep_type STREQUAL "STATIC_LIBRARY")
115120
list(APPEND ${libs_out} ${dep})
@@ -132,10 +137,6 @@ endif()
132137
configure_file(${PROJECT_SOURCE_DIR}/libbitcoinkernel.pc.in ${PROJECT_BINARY_DIR}/libbitcoinkernel.pc @ONLY)
133138
install(FILES ${PROJECT_BINARY_DIR}/libbitcoinkernel.pc DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig" COMPONENT libbitcoinkernel)
134139

135-
# Add a convenience libbitcoinkernel target as a synonym for bitcoinkernel.
136-
add_custom_target(libbitcoinkernel)
137-
add_dependencies(libbitcoinkernel bitcoinkernel)
138-
139140
install(TARGETS bitcoinkernel
140141
RUNTIME
141142
DESTINATION ${CMAKE_INSTALL_BINDIR}

src/util/CMakeLists.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@ add_library(bitcoin_util STATIC EXCLUDE_FROM_ALL
3636
../sync.cpp
3737
)
3838

39-
# Workaround for https://gitlab.kitware.com/cmake/cmake/-/issues/24058
40-
set_target_properties(bitcoin_util PROPERTIES OPTIMIZE_DEPENDENCIES OFF)
41-
4239
target_link_libraries(bitcoin_util
4340
PRIVATE
4441
core_interface

0 commit comments

Comments
 (0)