Skip to content

Commit 561934d

Browse files
committed
WIP: visibility example for cmake
1 parent c498779 commit 561934d

File tree

3 files changed

+17
-43
lines changed

3 files changed

+17
-43
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,7 @@ jobs:
615615
run: cmake -E env CFLAGS="/WX ${{ matrix.configuration.cpp_flags }}" cmake -B build -DSECP256K1_ENABLE_MODULE_RECOVERY=ON -DSECP256K1_BUILD_EXAMPLES=ON ${{ matrix.configuration.cmake_options }}
616616

617617
- name: Build
618-
run: cmake --build build --config RelWithDebInfo -- /p:UseMultiToolTask=true /maxCpuCount
618+
run: cmake --build build --config RelWithDebInfo --verbose -- /p:UseMultiToolTask=true /maxCpuCount
619619

620620
- name: Binaries info
621621
# Use the bash shell included with Git for Windows.

include/secp256k1.h

Lines changed: 13 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -121,45 +121,21 @@ typedef int (*secp256k1_nonce_function)(
121121
#endif
122122

123123
/* Symbol visibility. */
124-
#if defined(_WIN32)
125-
/* GCC for Windows (e.g., MinGW) accepts the __declspec syntax
126-
* for MSVC compatibility. A __declspec declaration implies (but is not
127-
* exactly equivalent to) __attribute__ ((visibility("default"))), and so we
128-
* actually want __declspec even on GCC, see "Microsoft Windows Function
129-
* Attributes" in the GCC manual and the recommendations in
130-
* https://gcc.gnu.org/wiki/Visibility. */
131-
# if defined(SECP256K1_BUILD)
132-
# if defined(DLL_EXPORT) || defined(SECP256K1_DLL_EXPORT)
133-
/* Building libsecp256k1 as a DLL.
134-
* 1. If using Libtool, it defines DLL_EXPORT automatically.
135-
* 2. In other cases, SECP256K1_DLL_EXPORT must be defined. */
136-
# define SECP256K1_API extern __declspec (dllexport)
137-
# else
138-
/* Building libsecp256k1 as a static library on Windows.
139-
* No declspec is needed, and so we would want the non-Windows-specific
140-
* logic below take care of this case. However, this may result in setting
141-
* __attribute__ ((visibility("default"))), which is supposed to be a noop
142-
* on Windows but may trigger warnings when compiling with -flto due to a
143-
* bug in GCC, see
144-
* https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116478 . */
145-
# define SECP256K1_API extern
146-
# endif
147-
/* The user must define SECP256K1_STATIC when consuming libsecp256k1 as a static
148-
* library on Windows. */
149-
# elif !defined(SECP256K1_STATIC)
150-
/* Consuming libsecp256k1 as a DLL. */
151-
# define SECP256K1_API extern __declspec (dllimport)
152-
# endif
124+
#if defined(_WIN32) || defined(__CYGWIN__)
125+
# define SECP256K1_EXPORT __declspec(dllexport)
126+
# define SECP256K1_IMPORT __declspec(dllimport)
127+
#else
128+
# define SECP256K1_EXPORT __attribute__((visibility("default")))
129+
# define SECP256K1_IMPORT __attribute__((visibility("default")))
153130
#endif
154131
#ifndef SECP256K1_API
155-
/* All cases not captured by the Windows-specific logic. */
156-
# if defined(__GNUC__) && (__GNUC__ >= 4) && defined(SECP256K1_BUILD)
157-
/* Building libsecp256k1 using GCC or compatible. */
158-
# define SECP256K1_API extern __attribute__ ((visibility ("default")))
159-
# else
160-
/* Fall back to standard C's extern. */
161-
# define SECP256K1_API extern
162-
# endif
132+
# if defined(SECP256K1_STATIC)
133+
# define SECP256K1_API extern
134+
# elif defined(SECP256K1_BUILD)
135+
# define SECP256K1_API extern SECP256K1_EXPORT
136+
# else
137+
# define SECP256K1_API extern SECP256K1_IMPORT
138+
# endif
163139
#endif
164140

165141
/* Warning attributes

src/CMakeLists.txt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,9 @@ if(SECP256K1_ASM STREQUAL "arm32")
7070
target_link_libraries(secp256k1_asm INTERFACE secp256k1_asm_arm)
7171
endif()
7272

73-
if(WIN32)
74-
# Define our export symbol only for shared libs.
75-
set_target_properties(secp256k1 PROPERTIES DEFINE_SYMBOL SECP256K1_DLL_EXPORT)
76-
target_compile_definitions(secp256k1 INTERFACE $<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:SECP256K1_STATIC>)
77-
endif()
73+
# When building a static libary, SECP256K1_STATIC must be defined both for itself and downstream.
74+
target_compile_definitions(secp256k1 PUBLIC $<$<STREQUAL:$<TARGET_PROPERTY:TYPE>,STATIC_LIBRARY>:SECP256K1_STATIC>)
75+
set_target_properties(secp256k1 PROPERTIES C_VISIBILITY_PRESET hidden)
7876

7977
# Object libs don't know if they're being built for a shared or static lib.
8078
# Grab the PIC property from secp256k1 which knows.

0 commit comments

Comments
 (0)