From 45be32f8384398ad8d590137d05a6373aa827b75 Mon Sep 17 00:00:00 2001 From: TheCharlatan Date: Wed, 4 Sep 2024 21:46:31 +0200 Subject: [PATCH 1/2] build: Produce a usable static kernel library 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. This is because cmake, unlike the libtool archiver, does not combine multiple static libraries into a single static library on installation. This is likely an intentional design choice, since there were a bunch of caveats to the way libtool calculated these libraries. Fix this problem by installing all the required libraries. The user must then link all of them along with the bitcoin kernel library. --- src/kernel/CMakeLists.txt | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/kernel/CMakeLists.txt b/src/kernel/CMakeLists.txt index ffb1a857ac17e..a7475feb7f051 100644 --- a/src/kernel/CMakeLists.txt +++ b/src/kernel/CMakeLists.txt @@ -98,6 +98,32 @@ set_target_properties(bitcoinkernel PROPERTIES CXX_VISIBILITY_PRESET default ) +# When building the static library, install all static libraries the +# bitcoinkernel depends on. +if(NOT BUILD_SHARED_LIBS) + # Recursively get all the static libraries a target depends on and put them in libs_out + function(get_target_static_link_libs target libs_out) + get_target_property(linked_libraries ${target} LINK_LIBRARIES) + foreach(dep ${linked_libraries}) + if(TARGET ${dep}) + get_target_property(dep_type ${dep} TYPE) + if(dep_type STREQUAL "STATIC_LIBRARY") + list(APPEND ${libs_out} ${dep}) + get_target_static_link_libs(${dep} ${libs_out}) + endif() + endif() + endforeach() + set(${libs_out} ${${libs_out}} PARENT_SCOPE) + endfunction() + + set(all_kernel_static_link_libs "") + get_target_static_link_libs(bitcoinkernel all_kernel_static_link_libs) + + foreach(lib ${all_kernel_static_link_libs}) + install(TARGETS ${lib} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) + endforeach() +endif() + include(GNUInstallDirs) install(TARGETS bitcoinkernel RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} From 0dd16d7118f10ac291a45644769121cbdfd2352f Mon Sep 17 00:00:00 2001 From: TheCharlatan Date: Wed, 4 Sep 2024 22:02:34 +0200 Subject: [PATCH 2/2] build: Add a pkg-config file for libbitcoinkernel --- libbitcoinkernel.pc.in | 11 +++++++++++ src/kernel/CMakeLists.txt | 8 ++++++++ 2 files changed, 19 insertions(+) create mode 100644 libbitcoinkernel.pc.in diff --git a/libbitcoinkernel.pc.in b/libbitcoinkernel.pc.in new file mode 100644 index 0000000000000..a2cb7d3692e97 --- /dev/null +++ b/libbitcoinkernel.pc.in @@ -0,0 +1,11 @@ +prefix=@CMAKE_INSTALL_PREFIX@ +exec_prefix=${prefix} +libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@ +includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@ + +Name: @PACKAGE_NAME@ kernel library +Description: Experimental library for the Bitcoin Core validation engine. +Version: @PACKAGE_VERSION@ +Libs: -L${libdir} -lbitcoinkernel +Libs.private: -L${libdir} @LIBS_PRIVATE@ +Cflags: -I${includedir} diff --git a/src/kernel/CMakeLists.txt b/src/kernel/CMakeLists.txt index a7475feb7f051..5b62bba1c013d 100644 --- a/src/kernel/CMakeLists.txt +++ b/src/kernel/CMakeLists.txt @@ -119,11 +119,19 @@ if(NOT BUILD_SHARED_LIBS) set(all_kernel_static_link_libs "") get_target_static_link_libs(bitcoinkernel all_kernel_static_link_libs) + # LIBS_PRIVATE is substituted in the pkg-config file. + set(LIBS_PRIVATE "") foreach(lib ${all_kernel_static_link_libs}) install(TARGETS ${lib} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) + string(APPEND LIBS_PRIVATE " -l${lib}") endforeach() + + string(STRIP "${LIBS_PRIVATE}" LIBS_PRIVATE) endif() +configure_file(${PROJECT_SOURCE_DIR}/libbitcoinkernel.pc.in ${PROJECT_BINARY_DIR}/libbitcoinkernel.pc @ONLY) +install(FILES ${PROJECT_BINARY_DIR}/libbitcoinkernel.pc DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") + include(GNUInstallDirs) install(TARGETS bitcoinkernel RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}