Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmake: Set POSITION_INDEPENDENT_CODE property properly #1232

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,17 @@ message("secp256k1 configure summary")
message("===========================")
message("Build artifacts:")
message(" shared library ...................... ${SECP256K1_BUILD_SHARED}")
message(" static library ...................... ${SECP256K1_BUILD_STATIC}")
if(TARGET secp256k1_static)
get_target_property(use_pic secp256k1_static POSITION_INDEPENDENT_CODE)
if(use_pic)
set(pic_status ", PIC")
else()
set(pic_status ", no PIC")
endif()
else()
set(pic_status "")
endif()
message(" static library ...................... ${SECP256K1_BUILD_STATIC}${pic_status}")
message("Optional modules:")
message(" ECDH ................................ ${SECP256K1_ENABLE_MODULE_ECDH}")
message(" ECDSA pubkey recovery ............... ${SECP256K1_ENABLE_MODULE_RECOVERY}")
Expand Down
19 changes: 13 additions & 6 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,21 @@ else()
set(common_obj "")
endif()

add_library(precomputed OBJECT
add_library(precomputed_for_shared OBJECT EXCLUDE_FROM_ALL
precomputed_ecmult.c
precomputed_ecmult_gen.c
)
set_target_properties(precomputed_for_shared PROPERTIES POSITION_INDEPENDENT_CODE TRUE)

add_library(precomputed_for_static OBJECT EXCLUDE_FROM_ALL
precomputed_ecmult.c
precomputed_ecmult_gen.c
)
set(internal_obj "$<TARGET_OBJECTS:precomputed>" "${common_obj}")

add_library(secp256k1 SHARED EXCLUDE_FROM_ALL
secp256k1.c
${internal_obj}
${common_obj}
$<TARGET_OBJECTS:precomputed_for_shared>
)
target_include_directories(secp256k1 INTERFACE
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
Expand All @@ -32,15 +38,14 @@ set_target_properties(secp256k1 PROPERTIES
SOVERSION "${${PROJECT_NAME}_LIB_VERSION_CURRENT}"
)
if(SECP256K1_BUILD_SHARED)
get_target_property(use_pic secp256k1 POSITION_INDEPENDENT_CODE)
set_target_properties(precomputed PROPERTIES POSITION_INDEPENDENT_CODE ${use_pic})
set_target_properties(secp256k1 PROPERTIES EXCLUDE_FROM_ALL FALSE)
list(APPEND ${PROJECT_NAME}_installables secp256k1)
endif()

add_library(secp256k1_static STATIC EXCLUDE_FROM_ALL
secp256k1.c
${internal_obj}
${common_obj}
$<TARGET_OBJECTS:precomputed_for_static>
)
target_include_directories(secp256k1_static INTERFACE
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
Expand All @@ -63,8 +68,10 @@ target_compile_definitions(binary_interface INTERFACE
add_library(link_library INTERFACE)
if(SECP256K1_BUILD_SHARED)
target_link_libraries(link_library INTERFACE secp256k1)
set(internal_obj "$<TARGET_OBJECTS:precomputed_for_shared>" "${common_obj}")
elseif(SECP256K1_BUILD_STATIC)
target_link_libraries(link_library INTERFACE secp256k1_static)
set(internal_obj "$<TARGET_OBJECTS:precomputed_for_static>" "${common_obj}")
endif()

if(SECP256K1_BUILD_BENCHMARK)
Expand Down