Skip to content

Commit 746e36b

Browse files
Merge #1678: cmake: add a helper for linking into static libs
145ae3e cmake: add a helper for linking into static libs (Cory Fields) Pull request description: As discussed here: #1674 (comment) 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. ACKs for top commit: hebasto: ACK 145ae3e, tested on Ubuntu 24.04 using cmake 3.22.6 and the default cmake 3.28.3. stickies-v: Light ACK 145ae3e Tree-SHA512: bfe72e3f337eadce8bdbe613e4ce2f2cd92046f811c447311e5670af9d52dbf5b9dc91866f69251f52a7632ad66d6df102fb6f4c1de2688bb7611b7b42e969a3
2 parents a28c2ff + 145ae3e commit 746e36b

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/CMakeLists.txt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,19 @@ add_library(secp256k1_precomputed OBJECT EXCLUDE_FROM_ALL
5454
# from being exported.
5555
target_sources(secp256k1 PRIVATE secp256k1.c $<TARGET_OBJECTS:secp256k1_precomputed>)
5656

57+
# Create a helper lib that parent projects can use to link secp256k1 into a
58+
# static lib.
59+
add_library(secp256k1_objs INTERFACE)
60+
target_sources(secp256k1_objs INTERFACE $<TARGET_OBJECTS:secp256k1> $<TARGET_OBJECTS:secp256k1_precomputed>)
61+
5762
add_library(secp256k1_asm INTERFACE)
5863
if(SECP256K1_ASM STREQUAL "arm32")
5964
add_library(secp256k1_asm_arm OBJECT EXCLUDE_FROM_ALL)
6065
target_sources(secp256k1_asm_arm PUBLIC
6166
asm/field_10x26_arm.s
6267
)
6368
target_sources(secp256k1 PRIVATE $<TARGET_OBJECTS:secp256k1_asm_arm>)
69+
target_sources(secp256k1_objs INTERFACE $<TARGET_OBJECTS:secp256k1_asm_arm>)
6470
target_link_libraries(secp256k1_asm INTERFACE secp256k1_asm_arm)
6571
endif()
6672

@@ -75,10 +81,13 @@ endif()
7581
get_target_property(use_pic secp256k1 POSITION_INDEPENDENT_CODE)
7682
set_target_properties(secp256k1_precomputed PROPERTIES POSITION_INDEPENDENT_CODE ${use_pic})
7783

84+
# Add the include path for parent projects so that they don't have to manually add it.
7885
target_include_directories(secp256k1 INTERFACE
79-
# Add the include path for parent projects so that they don't have to manually add it.
8086
$<BUILD_INTERFACE:$<$<NOT:$<BOOL:${PROJECT_IS_TOP_LEVEL}>>:${PROJECT_SOURCE_DIR}/include>>
8187
)
88+
set_target_properties(secp256k1_objs PROPERTIES
89+
INTERFACE_INCLUDE_DIRECTORIES "$<TARGET_PROPERTY:secp256k1,INTERFACE_INCLUDE_DIRECTORIES>"
90+
)
8291

8392
# This emulates Libtool to make sure Libtool and CMake agree on the ABI version,
8493
# see below "Calculate the version variables" in build-aux/ltmain.sh.

0 commit comments

Comments
 (0)