From 882cc642a3cfe8c999d8f7abe20066b8601345b3 Mon Sep 17 00:00:00 2001 From: Paul-Louis Ageneau Date: Tue, 20 Feb 2024 00:21:53 +0100 Subject: [PATCH] Replace export header with defines in juice.h --- CMakeLists.txt | 19 +++---------------- Makefile | 2 +- include/juice/juice.h | 31 ++++++++++++++++--------------- 3 files changed, 20 insertions(+), 32 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 47354f25..3df0e601 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,6 @@ set(PROJECT_DESCRIPTION "UDP Interactive Connectivity Establishment (ICE) librar option(USE_NETTLE "Use Nettle for hash functions" OFF) option(NO_SERVER "Disable server support" OFF) option(NO_TESTS "Disable tests build" OFF) -option(NO_EXPORT_HEADER "Disable export header" OFF) option(WARNINGS_AS_ERRORS "Treat warnings as errors" OFF) option(FUZZER "Enable oss-fuzz fuzzing" OFF) option(CLANG_TIDY "Enable clang-tidy" OFF) @@ -177,21 +176,9 @@ write_basic_package_version_file( install(FILES ${CMAKE_BINARY_DIR}/LibJuiceConfigVersion.cmake DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/LibJuice) -if(NOT NO_EXPORT_HEADER AND CMAKE_VERSION VERSION_GREATER_EQUAL "3.12") - include(GenerateExportHeader) - generate_export_header(juice - EXPORT_MACRO_NAME JUICE_EXPORT - NO_EXPORT_MACRO_NAME JUICE_NO_EXPORT - DEPRECATED_MACRO_NAME JUICE_DEPRECATED - STATIC_DEFINE JUICE_STATIC) - target_include_directories(juice PUBLIC $) - target_compile_definitions(juice PUBLIC -DJUICE_HAS_EXPORT_HEADER) - set_target_properties(juice PROPERTIES C_VISIBILITY_PRESET hidden) - install(FILES ${PROJECT_BINARY_DIR}/juice_export.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/juice) -else() - target_compile_definitions(juice PRIVATE JUICE_EXPORTS) - target_compile_definitions(juice-static PRIVATE JUICE_EXPORTS) -endif() +set_target_properties(juice PROPERTIES C_VISIBILITY_PRESET hidden) +target_compile_definitions(juice PRIVATE JUICE_EXPORTS) +target_compile_definitions(juice-static PRIVATE JUICE_EXPORTS) if(NOT MSVC) target_compile_options(juice PRIVATE -Wall -Wextra) diff --git a/Makefile b/Makefile index 986f594e..0b24d936 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ NAME=libjuice CC=$(CROSS)gcc AR=$(CROSS)ar RM=rm -f -CFLAGS=-O2 -pthread -fPIC -Wno-address-of-packed-member +CFLAGS=-O2 -pthread -fPIC -fvisibility=hidden -Wno-address-of-packed-member LDFLAGS=-pthread LIBS= diff --git a/include/juice/juice.h b/include/juice/juice.h index 06bcc139..8d09fdd0 100644 --- a/include/juice/juice.h +++ b/include/juice/juice.h @@ -17,22 +17,23 @@ extern "C" { #include #include -#ifdef JUICE_HAS_EXPORT_HEADER -#include "juice_export.h" -#else // no export header -#ifdef JUICE_STATIC -#define JUICE_EXPORT -#else // dynamic library -#ifdef _WIN32 -#if defined(JUICE_EXPORTS) || defined(juice_EXPORTS) -#define JUICE_EXPORT __declspec(dllexport) // building the library -#else -#define JUICE_EXPORT __declspec(dllimport) // using the library -#endif -#else // not WIN32 -#define JUICE_EXPORT -#endif +#ifndef JUICE_STATIC // dynamic library +# ifdef _WIN32 +# ifdef JUICE_EXPORTS +# define JUICE_EXPORT __declspec(dllexport) // building the library +# else +# define JUICE_EXPORT __declspec(dllimport) // using the library +# endif +# else // not WIN32 +# if defined(__has_attribute) +# if __has_attribute(visibility) +# define JUICE_EXPORT __attribute__((visibility("default"))) +# endif +# endif +# endif #endif +#ifndef JUICE_EXPORT +# define JUICE_EXPORT #endif #define JUICE_ERR_SUCCESS 0