Skip to content

Commit

Permalink
Static library support improvements (#123)
Browse files Browse the repository at this point in the history
* `#define UTF8PROC_STATIC` to disable DLLEXPORT

`#define UTF8PROC_STATIC` to disable DLLEXPORT

* [CMake] Automatically define UTF8PROC_STATIC if BUILD_SHARED_LIBS is off

* [Makefile] Support additional UTF8PROC_DEFINES, which can be used to specify flags like `-DUTF8PROC_STATIC`
  • Loading branch information
past-due authored and stevengj committed Apr 30, 2018
1 parent fe3f6bd commit 48949bd
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ add_library (utf8proc
utf8proc.h
)

if (BUILD_SHARED_LIBS)
# Building shared library
else()
# Building static library
target_compile_definitions(utf8proc PUBLIC "UTF8PROC_STATIC")
endif()

target_compile_definitions(utf8proc PRIVATE "UTF8PROC_EXPORTS")

set_target_properties (utf8proc PROPERTIES
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ CFLAGS ?= -O2
PICFLAG = -fPIC
C99FLAG = -std=c99
WCFLAGS = -Wall -pedantic
UCFLAGS = $(CFLAGS) $(PICFLAG) $(C99FLAG) $(WCFLAGS) -DUTF8PROC_EXPORTS
UCFLAGS = $(CFLAGS) $(PICFLAG) $(C99FLAG) $(WCFLAGS) -DUTF8PROC_EXPORTS $(UTF8PROC_DEFINES)

# shared-library version MAJOR.MINOR.PATCH ... this may be *different*
# from the utf8proc version number because it indicates ABI compatibility,
Expand Down
20 changes: 12 additions & 8 deletions utf8proc.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,20 @@ typedef bool utf8proc_bool;
#endif
#include <limits.h>

#ifdef _WIN32
# ifdef UTF8PROC_EXPORTS
# define UTF8PROC_DLLEXPORT __declspec(dllexport)
#ifdef UTF8PROC_STATIC
# define UTF8PROC_DLLEXPORT
#else
# ifdef _WIN32
# ifdef UTF8PROC_EXPORTS
# define UTF8PROC_DLLEXPORT __declspec(dllexport)
# else
# define UTF8PROC_DLLEXPORT __declspec(dllimport)
# endif
# elif __GNUC__ >= 4
# define UTF8PROC_DLLEXPORT __attribute__ ((visibility("default")))
# else
# define UTF8PROC_DLLEXPORT __declspec(dllimport)
# define UTF8PROC_DLLEXPORT
# endif
#elif __GNUC__ >= 4
# define UTF8PROC_DLLEXPORT __attribute__ ((visibility("default")))
#else
# define UTF8PROC_DLLEXPORT
#endif

#ifdef __cplusplus
Expand Down

0 comments on commit 48949bd

Please sign in to comment.