build: Introduce SECP256k1_DLL_EXPORT macro

This change provides a way to build a shared library that is not tired
to the Libtool-specific `DLL_EXPORT` macro.
This commit is contained in:
Hennadii Stepanov 2023-06-29 17:14:03 +01:00
parent 9f1b1904a3
commit 0196e8ade1
No known key found for this signature in database
GPG Key ID: 410108112E7EA81F
2 changed files with 7 additions and 6 deletions

View File

@ -134,10 +134,12 @@ typedef int (*secp256k1_nonce_function)(
#endif #endif
/* Symbol visibility. See https://gcc.gnu.org/wiki/Visibility */ /* Symbol visibility. See https://gcc.gnu.org/wiki/Visibility */
/* DLL_EXPORT is defined internally for shared builds */
#if defined(_WIN32) #if defined(_WIN32)
# ifdef SECP256K1_BUILD # if defined(SECP256K1_BUILD)
# ifdef DLL_EXPORT # if defined(DLL_EXPORT) || defined(SECP256K1_DLL_EXPORT)
/* Building libsecp256k1 as a DLL.
* 1. If using Libtool, it defines DLL_EXPORT automatically.
* 2. In other cases, SECP256K1_DLL_EXPORT must be defined. */
# define SECP256K1_API extern __declspec (dllexport) # define SECP256K1_API extern __declspec (dllexport)
# endif # endif
/* The user must define SECP256K1_STATIC when consuming libsecp256k1 as a static /* The user must define SECP256K1_STATIC when consuming libsecp256k1 as a static

View File

@ -20,10 +20,9 @@ if(SECP256K1_ASM STREQUAL "arm32")
target_link_libraries(secp256k1_asm INTERFACE secp256k1_asm_arm) target_link_libraries(secp256k1_asm INTERFACE secp256k1_asm_arm)
endif() endif()
# Define our export symbol only for Win32 and only for shared libs.
# This matches libtool's usage of DLL_EXPORT
if(WIN32) if(WIN32)
set_target_properties(secp256k1 PROPERTIES DEFINE_SYMBOL "DLL_EXPORT") # Define our export symbol only for shared libs.
set_target_properties(secp256k1 PROPERTIES DEFINE_SYMBOL SECP256K1_DLL_EXPORT)
target_compile_definitions(secp256k1 INTERFACE $<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:SECP256K1_STATIC>) target_compile_definitions(secp256k1 INTERFACE $<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:SECP256K1_STATIC>)
endif() endif()