Skip to content

Commit e2ff2e5

Browse files
committed
cmake: add a helper for linking into static libs
Parent projects (Bitcoin Core in this case) may wish to include secp256k1 in another static library (libbitcoinkernel) so that users are not forced to bring their own static libsecp256k1. Unfortunately, CMake lacks the machinery to link (combine) one static lib into another. To work around this, secp256k1_objs is exposed as an interface library which parent projects can "link" into static libs..
1 parent 9239447 commit e2ff2e5

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/CMakeLists.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,19 @@ add_library(secp256k1_precomputed OBJECT EXCLUDE_FROM_ALL
1010
# from being exported.
1111
add_library(secp256k1 secp256k1.c $<TARGET_OBJECTS:secp256k1_precomputed>)
1212

13+
# Create a helper lib that parent projects can use to link secp256k1 into a
14+
# static lib.
15+
add_library(secp256k1_objs INTERFACE EXCLUDE_FROM_ALL)
16+
target_sources(secp256k1_objs INTERFACE $<TARGET_OBJECTS:secp256k1> $<TARGET_OBJECTS:secp256k1_precomputed>)
17+
1318
add_library(secp256k1_asm INTERFACE)
1419
if(SECP256K1_ASM STREQUAL "arm32")
1520
add_library(secp256k1_asm_arm OBJECT EXCLUDE_FROM_ALL)
1621
target_sources(secp256k1_asm_arm PUBLIC
1722
asm/field_10x26_arm.s
1823
)
1924
target_sources(secp256k1 PRIVATE $<TARGET_OBJECTS:secp256k1_asm_arm>)
25+
target_sources(secp256k1_objs INTERFACE $<TARGET_OBJECTS:secp256k1_asm_arm>)
2026
target_link_libraries(secp256k1_asm INTERFACE secp256k1_asm_arm)
2127
endif()
2228

@@ -37,6 +43,11 @@ target_include_directories(secp256k1 INTERFACE
3743
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
3844
)
3945

46+
target_include_directories(secp256k1_objs INTERFACE
47+
# Add the include path for parent projects so that they don't have to manually add it.
48+
$<BUILD_INTERFACE:$<$<NOT:$<BOOL:${PROJECT_IS_TOP_LEVEL}>>:${PROJECT_SOURCE_DIR}/include>>
49+
)
50+
4051
# This emulates Libtool to make sure Libtool and CMake agree on the ABI version,
4152
# see below "Calculate the version variables" in build-aux/ltmain.sh.
4253
math(EXPR ${PROJECT_NAME}_soversion "${${PROJECT_NAME}_LIB_VERSION_CURRENT} - ${${PROJECT_NAME}_LIB_VERSION_AGE}")

0 commit comments

Comments
 (0)