Skip to content

Commit

Permalink
Merge pull request #236 from paullouisageneau/remove-export-header
Browse files Browse the repository at this point in the history
Replace export header with defines in juice.h
  • Loading branch information
paullouisageneau authored Mar 12, 2024
2 parents f1d12c8 + 882cc64 commit a5023e3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 32 deletions.
19 changes: 3 additions & 16 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>)
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)
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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=

Expand Down
31 changes: 16 additions & 15 deletions include/juice/juice.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,23 @@ extern "C" {
#include <stddef.h>
#include <stdint.h>

#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
Expand Down

0 comments on commit a5023e3

Please sign in to comment.