Skip to content

Commit 51d2ecd

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 201b2b8 commit 51d2ecd

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/CMakeLists.txt

Lines changed: 17 additions & 2 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)
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

@@ -31,12 +37,21 @@ endif()
3137
get_target_property(use_pic secp256k1 POSITION_INDEPENDENT_CODE)
3238
set_target_properties(secp256k1_precomputed PROPERTIES POSITION_INDEPENDENT_CODE ${use_pic})
3339

34-
target_include_directories(secp256k1 INTERFACE
35-
# Add the include path for parent projects so that they don't have to manually add it.
40+
# Add the include path for parent projects so that they don't have to manually add it.
41+
set(_include_directory_for_parent_projects
3642
$<BUILD_INTERFACE:$<$<NOT:$<BOOL:${PROJECT_IS_TOP_LEVEL}>>:${PROJECT_SOURCE_DIR}/include>>
43+
)
44+
45+
target_include_directories(secp256k1 INTERFACE
46+
${_include_directory_for_parent_projects}
3747
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
3848
)
3949

50+
target_include_directories(secp256k1_objs INTERFACE
51+
${_include_directory_for_parent_projects}
52+
)
53+
unset(_include_directory_for_parent_projects)
54+
4055
# This emulates Libtool to make sure Libtool and CMake agree on the ABI version,
4156
# see below "Calculate the version variables" in build-aux/ltmain.sh.
4257
math(EXPR ${PROJECT_NAME}_soversion "${${PROJECT_NAME}_LIB_VERSION_CURRENT} - ${${PROJECT_NAME}_LIB_VERSION_AGE}")

0 commit comments

Comments
 (0)