Skip to content

Commit 24817e8

Browse files
committed
Merge bitcoin/bitcoin#30814: kernel: Create usable static kernel library
0dd16d7 build: Add a pkg-config file for libbitcoinkernel (TheCharlatan) 45be32f build: Produce a usable static kernel library (TheCharlatan) Pull request description: Since the move to cmake, the kernel static library that is installed after a cmake --install build is unusable. It lacks symbols for the internal libraries, besides those defined in the kernel library target. Fix this by explicitly installing all the required internal static libraries. To make usage of these installed libraries easy, add a pkg-config file that can be used during linking. This patch can be tested with: ``` cmake -B build -DBUILD_SHARED_LIBS=OFF -DBUILD_KERNEL_LIB=ON cmake --build build cmake --install build g++ -std=c++20 -o test_chainstate src/bitcoin-chainstate.cpp -I/home/drgrid/bitcoin/src $(pkg-config --libs --static libbitcoinkernel) ``` Attempts to solve #30801 ACKs for top commit: hebasto: ACK 0dd16d7. fanquake: ACK 0dd16d7 - this looks like a good place to start. ryanofsky: Code review ACK 0dd16d7 Tree-SHA512: 92f7bc959584bdc595f4aa6d0ab133355481075fe8564224fd7ac122fd7bdd75f98cf26ef0a6a7d84fd552d2258ddca1b674eca91122469a58bacc5f0a0ec2ef
2 parents 7d43bca + 0dd16d7 commit 24817e8

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

libbitcoinkernel.pc.in

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
prefix=@CMAKE_INSTALL_PREFIX@
2+
exec_prefix=${prefix}
3+
libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@
4+
includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@
5+
6+
Name: @PACKAGE_NAME@ kernel library
7+
Description: Experimental library for the Bitcoin Core validation engine.
8+
Version: @PACKAGE_VERSION@
9+
Libs: -L${libdir} -lbitcoinkernel
10+
Libs.private: -L${libdir} @LIBS_PRIVATE@
11+
Cflags: -I${includedir}

src/kernel/CMakeLists.txt

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,40 @@ set_target_properties(bitcoinkernel PROPERTIES
9898
CXX_VISIBILITY_PRESET default
9999
)
100100

101+
# When building the static library, install all static libraries the
102+
# bitcoinkernel depends on.
103+
if(NOT BUILD_SHARED_LIBS)
104+
# Recursively get all the static libraries a target depends on and put them in libs_out
105+
function(get_target_static_link_libs target libs_out)
106+
get_target_property(linked_libraries ${target} LINK_LIBRARIES)
107+
foreach(dep ${linked_libraries})
108+
if(TARGET ${dep})
109+
get_target_property(dep_type ${dep} TYPE)
110+
if(dep_type STREQUAL "STATIC_LIBRARY")
111+
list(APPEND ${libs_out} ${dep})
112+
get_target_static_link_libs(${dep} ${libs_out})
113+
endif()
114+
endif()
115+
endforeach()
116+
set(${libs_out} ${${libs_out}} PARENT_SCOPE)
117+
endfunction()
118+
119+
set(all_kernel_static_link_libs "")
120+
get_target_static_link_libs(bitcoinkernel all_kernel_static_link_libs)
121+
122+
# LIBS_PRIVATE is substituted in the pkg-config file.
123+
set(LIBS_PRIVATE "")
124+
foreach(lib ${all_kernel_static_link_libs})
125+
install(TARGETS ${lib} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
126+
string(APPEND LIBS_PRIVATE " -l${lib}")
127+
endforeach()
128+
129+
string(STRIP "${LIBS_PRIVATE}" LIBS_PRIVATE)
130+
endif()
131+
132+
configure_file(${PROJECT_SOURCE_DIR}/libbitcoinkernel.pc.in ${PROJECT_BINARY_DIR}/libbitcoinkernel.pc @ONLY)
133+
install(FILES ${PROJECT_BINARY_DIR}/libbitcoinkernel.pc DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
134+
101135
include(GNUInstallDirs)
102136
install(TARGETS bitcoinkernel
103137
RUNTIME

0 commit comments

Comments
 (0)