From cbd6d5fca0461a1fbee42d04b337bd5e2cc013a1 Mon Sep 17 00:00:00 2001 From: Luis Michaelis Date: Fri, 2 Aug 2024 16:27:45 +0200 Subject: [PATCH] [#5] fix(build): when building as a static library, don't define `dllexport`/`dllimport` --- CMakeLists.txt | 1 + include/dmusic.h | 32 +++++++++++++++++++------------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 855b3b9..fa9af0b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,6 +48,7 @@ bs_select_cflags(${DM_ENABLE_ASAN} _DM_COMPILE_FLAGS _DM_LINK_FLAGS) if (${DM_BUILD_STATIC}) add_library(dmusic STATIC) + target_compile_definitions(dmusic PUBLIC DM_STATIC=1) else () add_library(dmusic SHARED) endif () diff --git a/include/dmusic.h b/include/dmusic.h index 852a1c0..7165d1e 100644 --- a/include/dmusic.h +++ b/include/dmusic.h @@ -11,25 +11,31 @@ #define DM_EXTERN #endif -#if defined(_WIN32) || defined(__CYGWIN__) - #ifdef DM_BUILD - #ifdef __GNUC__ - #define DMAPI DM_EXTERN __attribute__((dllexport)) +#ifndef DM_STATIC + #if defined(_WIN32) || defined(__CYGWIN__) + #ifdef DM_BUILD + #ifdef __GNUC__ + #define DMAPI DM_EXTERN __attribute__((dllexport)) + #else + #define DMAPI DM_EXTERN __declspec(dllexport) + #endif #else - #define DMAPI DM_EXTERN __declspec(dllexport) + #ifdef __GNUC__ + #define DMAPI DM_EXTERN __attribute__((dllimport)) + #else + #define DMAPI DM_EXTERN __declspec(dllimport) + #endif #endif + #define DMINT #else - #ifdef __GNUC__ - #define DMAPI DM_EXTERN __attribute__((dllimport)) - #else - #define DMAPI DM_EXTERN __declspec(dllimport) - #endif + #define DMAPI DM_EXTERN __attribute__((visibility("default"))) + #define DMINT DM_EXTERN __attribute__((visibility("hidden"))) #endif - #define DMINT #else - #define DMAPI DM_EXTERN __attribute__((visibility("default"))) - #define DMINT DM_EXTERN __attribute__((visibility("hidden"))) + #define DMAPI DM_EXTERN + #define DMINT DM_EXTERN #endif + /// \endcond /// \defgroup DmCommonGroup Common