From 8487860a8c634bdbaee6056c2081d147041c3b06 Mon Sep 17 00:00:00 2001 From: Ozkan Sezer Date: Wed, 6 Mar 2024 01:11:55 +0300 Subject: [PATCH] windows exports: use dllexport attribute, instead of visibility. With older toolchains, at the least, visibility attributes don't work and all symbols are exported along with lots of unsupported warnings. Change-Id: I6ffe220b7589a6bda00f42c17ead35592de7cc5a --- CMakeLists.txt | 4 +++- configure.ac | 3 ++- sharpyuv/sharpyuv.h | 10 ++++------ src/webp/types.h | 12 +++++------- 4 files changed, 14 insertions(+), 15 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cfc625ed..bce1a7f3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -135,7 +135,7 @@ if(WEBP_UNICODE) add_definitions(-DUNICODE -D_UNICODE) endif() -if(MSVC AND BUILD_SHARED_LIBS) +if(WIN32 AND BUILD_SHARED_LIBS) add_definitions(-DWEBP_DLL) endif() @@ -163,7 +163,9 @@ if(MSVC) set(CMAKE_STATIC_LIBRARY_PREFIX "${webp_libname_prefix}") endif() +if(NOT WIN32) set(CMAKE_C_VISIBILITY_PRESET hidden) +endif() if(WEBP_ENABLE_WUNUSED_RESULT) if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.21.0) diff --git a/configure.ac b/configure.ac index 128c3633..53753a67 100644 --- a/configure.ac +++ b/configure.ac @@ -763,7 +763,8 @@ AC_CONFIG_FILES([Makefile src/Makefile man/Makefile \ src/libwebp.pc src/libwebpdecoder.pc \ src/demux/libwebpdemux.pc src/mux/libwebpmux.pc]) - +dnl fix exports from MinGW builds +AC_CONFIG_COMMANDS_POST([$SED -i 's/-DDLL_EXPORT/-DWEBP_DLL/' config.status]) AC_OUTPUT AC_MSG_NOTICE([ diff --git a/sharpyuv/sharpyuv.h b/sharpyuv/sharpyuv.h index 23a69ce3..fe958915 100644 --- a/sharpyuv/sharpyuv.h +++ b/sharpyuv/sharpyuv.h @@ -22,15 +22,13 @@ extern "C" { #else // This explicitly marks library functions and allows for changing the // signature for e.g., Windows DLL builds. -#if defined(__GNUC__) && __GNUC__ >= 4 +#if defined(_WIN32) && defined(WEBP_DLL) +#define SHARPYUV_EXTERN __declspec(dllexport) +#elif defined(__GNUC__) && __GNUC__ >= 4 #define SHARPYUV_EXTERN extern __attribute__((visibility("default"))) #else -#if defined(_MSC_VER) && defined(WEBP_DLL) -#define SHARPYUV_EXTERN __declspec(dllexport) -#else #define SHARPYUV_EXTERN extern -#endif /* _MSC_VER && WEBP_DLL */ -#endif /* __GNUC__ >= 4 */ +#endif /* defined(_WIN32) && defined(WEBP_DLL) */ #endif /* WEBP_EXTERN */ #endif /* SHARPYUV_EXTERN */ diff --git a/src/webp/types.h b/src/webp/types.h index f1727491..0e7ef129 100644 --- a/src/webp/types.h +++ b/src/webp/types.h @@ -56,15 +56,13 @@ typedef long long int int64_t; #ifndef WEBP_EXTERN // This explicitly marks library functions and allows for changing the // signature for e.g., Windows DLL builds. -# if defined(__GNUC__) && __GNUC__ >= 4 +# if defined(_WIN32) && defined(WEBP_DLL) +# define WEBP_EXTERN __declspec(dllexport) +# elif defined(__GNUC__) && __GNUC__ >= 4 # define WEBP_EXTERN extern __attribute__ ((visibility ("default"))) # else -# if defined(_MSC_VER) && defined(WEBP_DLL) -# define WEBP_EXTERN __declspec(dllexport) -# else -# define WEBP_EXTERN extern -# endif -# endif /* __GNUC__ >= 4 */ +# define WEBP_EXTERN extern +# endif /* defined(_WIN32) && defined(WEBP_DLL) */ #endif /* WEBP_EXTERN */ // Macro to check ABI compatibility (same major revision number)