Skip to content

Commit a3a4587

Browse files
committed
cmake: Set POSITION_INDEPENDENT_CODE property properly
1 parent 5658209 commit a3a4587

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

CMakeLists.txt

+11-1
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,17 @@ message("secp256k1 configure summary")
231231
message("===========================")
232232
message("Build artifacts:")
233233
message(" shared library ...................... ${SECP256K1_BUILD_SHARED}")
234-
message(" static library ...................... ${SECP256K1_BUILD_STATIC}")
234+
if(TARGET secp256k1_static)
235+
get_target_property(use_pic secp256k1_static POSITION_INDEPENDENT_CODE)
236+
if(use_pic)
237+
set(pic_status ", PIC")
238+
else()
239+
set(pic_status ", no PIC")
240+
endif()
241+
else()
242+
set(pic_status "")
243+
endif()
244+
message(" static library ...................... ${SECP256K1_BUILD_STATIC}${pic_status}")
235245
message("Optional modules:")
236246
message(" ECDH ................................ ${SECP256K1_ENABLE_MODULE_ECDH}")
237247
message(" ECDSA pubkey recovery ............... ${SECP256K1_ENABLE_MODULE_RECOVERY}")

src/CMakeLists.txt

+13-6
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,21 @@ else()
1111
set(common_obj "")
1212
endif()
1313

14-
add_library(precomputed OBJECT
14+
add_library(precomputed_for_shared OBJECT EXCLUDE_FROM_ALL
15+
precomputed_ecmult.c
16+
precomputed_ecmult_gen.c
17+
)
18+
set_target_properties(precomputed_for_shared PROPERTIES POSITION_INDEPENDENT_CODE TRUE)
19+
20+
add_library(precomputed_for_static OBJECT EXCLUDE_FROM_ALL
1521
precomputed_ecmult.c
1622
precomputed_ecmult_gen.c
1723
)
18-
set(internal_obj "$<TARGET_OBJECTS:precomputed>" "${common_obj}")
1924

2025
add_library(secp256k1 SHARED EXCLUDE_FROM_ALL
2126
secp256k1.c
22-
${internal_obj}
27+
${common_obj}
28+
$<TARGET_OBJECTS:precomputed_for_shared>
2329
)
2430
target_include_directories(secp256k1 INTERFACE
2531
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
@@ -32,15 +38,14 @@ set_target_properties(secp256k1 PROPERTIES
3238
SOVERSION "${${PROJECT_NAME}_LIB_VERSION_CURRENT}"
3339
)
3440
if(SECP256K1_BUILD_SHARED)
35-
get_target_property(use_pic secp256k1 POSITION_INDEPENDENT_CODE)
36-
set_target_properties(precomputed PROPERTIES POSITION_INDEPENDENT_CODE ${use_pic})
3741
set_target_properties(secp256k1 PROPERTIES EXCLUDE_FROM_ALL FALSE)
3842
list(APPEND ${PROJECT_NAME}_installables secp256k1)
3943
endif()
4044

4145
add_library(secp256k1_static STATIC EXCLUDE_FROM_ALL
4246
secp256k1.c
43-
${internal_obj}
47+
${common_obj}
48+
$<TARGET_OBJECTS:precomputed_for_static>
4449
)
4550
target_include_directories(secp256k1_static INTERFACE
4651
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
@@ -63,8 +68,10 @@ target_compile_definitions(binary_interface INTERFACE
6368
add_library(link_library INTERFACE)
6469
if(SECP256K1_BUILD_SHARED)
6570
target_link_libraries(link_library INTERFACE secp256k1)
71+
set(internal_obj "$<TARGET_OBJECTS:precomputed_for_shared>" "${common_obj}")
6672
elseif(SECP256K1_BUILD_STATIC)
6773
target_link_libraries(link_library INTERFACE secp256k1_static)
74+
set(internal_obj "$<TARGET_OBJECTS:precomputed_for_static>" "${common_obj}")
6875
endif()
6976

7077
if(SECP256K1_BUILD_BENCHMARK)

0 commit comments

Comments
 (0)