diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 172d08370..81aa51fa3 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -50,7 +50,6 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmark_version.h.in ${CMAKE_CURRENT_BINARY_DIR}/cmark_version.h) include(GNUInstallDirs) -include (GenerateExportHeader) add_executable(${PROGRAM} ${PROGRAM_SOURCES}) cmark_add_compile_options(${PROGRAM}) @@ -87,12 +86,15 @@ if (CMARK_SHARED) $) add_library(cmark::cmark ALIAS ${LIBRARY}) - generate_export_header(${LIBRARY} - BASE_NAME ${PROJECT_NAME}) - list(APPEND CMARK_INSTALL ${LIBRARY}) + set(CMARK_STATIC_DEFINE 0) +else() + set(CMARK_STATIC_DEFINE 1) endif() +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmark_export.h.in + ${CMAKE_CURRENT_BINARY_DIR}/cmark_export.h) + if (CMARK_STATIC) add_library(${STATICLIBRARY} STATIC ${LIBRARY_SOURCES}) cmark_add_compile_options(${STATICLIBRARY}) @@ -113,11 +115,6 @@ if (CMARK_STATIC) $) add_library(cmark::cmark_static ALIAS ${STATICLIBRARY}) - if (NOT CMARK_SHARED) - generate_export_header(${STATICLIBRARY} - BASE_NAME ${PROJECT_NAME}) - endif() - list(APPEND CMARK_INSTALL ${STATICLIBRARY}) endif() diff --git a/src/cmark_export.h.in b/src/cmark_export.h.in new file mode 100644 index 000000000..16eb9c668 --- /dev/null +++ b/src/cmark_export.h.in @@ -0,0 +1,38 @@ +#ifndef CMARK_EXPORT_H +#define CMARK_EXPORT_H + +/* Is this an exclusively static build */ +#if @CMARK_STATIC_DEFINE@ && ! defined CMARK_STATIC_DEFINE +# define CMARK_STATIC_DEFINE +#endif + +/* + * Here is the complicated part. Windows is special -- you cannot just define + * entry points unconditionally. + * */ +#if defined _WIN32 || defined __CYGWIN__ + /* When building static libraries, avoid marking public ones */ +# if defined CMARK_STATIC_DEFINE +# define CMARK_EXPORT + /* We are building this library */ +# elif defined libcmark_EXPORTS +# define CMARK_EXPORT __declspec(dllexport) + /* We are using this library */ +# else +# define CMARK_EXPORT __declspec(dllimport) +# endif + +/* On to the easy part. GCC and lookalikes such as clang just work */ +#elif defined __GNUC__ && __GNUC__ >= 4 +# define CMARK_EXPORT __attribute__((visibility("default"))) + +/* Older solaris support, why not */ +#elif defined __SUNPRO_C && __SUNPRO_C >= 0x550 +# define CMARK_EXPORT __global + +/* All else failed, and we don't know about this compiler. Be conservative. */ +#else +# define CMARK_EXPORT +#endif + +#endif /* CMARK_EXPORT_H */