Skip to content

Commit 45be32f

Browse files
committed
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.
1 parent f640b32 commit 45be32f

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/kernel/CMakeLists.txt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,32 @@ 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+
foreach(lib ${all_kernel_static_link_libs})
123+
install(TARGETS ${lib} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
124+
endforeach()
125+
endif()
126+
101127
include(GNUInstallDirs)
102128
install(TARGETS bitcoinkernel
103129
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}

0 commit comments

Comments
 (0)