Skip to content

Commit cb2ed66

Browse files
committed
use an in-tree header for symbol export information
Relying on CMake's GenerateExportHeader produces a file that is longer than the one being added here, which for all that is just mostly defining macros not used here. And after all that, it only contains macros specific to a single compiler, while failing to consistently handle GNUC (that always supports symbol visibility even for static libraries). Replace this with a more targeted header that is easy to read or include into external build systems, and which is also more robust than the one that only exists inside CMake.
1 parent cd5b2f6 commit cb2ed66

File tree

2 files changed

+44
-9
lines changed

2 files changed

+44
-9
lines changed

src/CMakeLists.txt

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmark_version.h.in
5050
${CMAKE_CURRENT_BINARY_DIR}/cmark_version.h)
5151

5252
include(GNUInstallDirs)
53-
include (GenerateExportHeader)
5453

5554
add_executable(${PROGRAM} ${PROGRAM_SOURCES})
5655
cmark_add_compile_options(${PROGRAM})
@@ -87,12 +86,15 @@ if (CMARK_SHARED)
8786
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>)
8887
add_library(cmark::cmark ALIAS ${LIBRARY})
8988

90-
generate_export_header(${LIBRARY}
91-
BASE_NAME ${PROJECT_NAME})
92-
9389
list(APPEND CMARK_INSTALL ${LIBRARY})
90+
set(CMARK_STATIC_DEFINE 0)
91+
else()
92+
set(CMARK_STATIC_DEFINE 1)
9493
endif()
9594

95+
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmark_export.h.in
96+
${CMAKE_CURRENT_BINARY_DIR}/cmark_export.h)
97+
9698
if (CMARK_STATIC)
9799
add_library(${STATICLIBRARY} STATIC ${LIBRARY_SOURCES})
98100
cmark_add_compile_options(${STATICLIBRARY})
@@ -113,11 +115,6 @@ if (CMARK_STATIC)
113115
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>)
114116
add_library(cmark::cmark_static ALIAS ${STATICLIBRARY})
115117

116-
if (NOT CMARK_SHARED)
117-
generate_export_header(${STATICLIBRARY}
118-
BASE_NAME ${PROJECT_NAME})
119-
endif()
120-
121118
list(APPEND CMARK_INSTALL ${STATICLIBRARY})
122119
endif()
123120

src/cmark_export.h.in

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#ifndef CMARK_EXPORT_H
2+
#define CMARK_EXPORT_H
3+
4+
/* Is this an exclusively static build */
5+
#if @CMARK_STATIC_DEFINE@ && ! defined CMARK_STATIC_DEFINE
6+
# define CMARK_STATIC_DEFINE
7+
#endif
8+
9+
/*
10+
* Here is the complicated part. Windows is special -- you cannot just define
11+
* entry points unconditionally.
12+
* */
13+
#if defined _WIN32 || defined __CYGWIN__
14+
/* When building static libraries, avoid marking public ones */
15+
# if defined CMARK_STATIC_DEFINE
16+
# define CMARK_EXPORT
17+
/* We are building this library */
18+
# elif defined libcmark_gfm_EXPORTS
19+
# define CMARK_EXPORT __declspec(dllexport)
20+
/* We are using this library */
21+
# else
22+
# define CMARK_EXPORT __declspec(dllimport)
23+
# endif
24+
25+
/* On to the easy part. GCC and lookalikes such as clang just work */
26+
#elif defined __GNUC__ && __GNUC__ >= 4
27+
# define CMARK_EXPORT __attribute__((visibility("default")))
28+
29+
/* Older solaris support, why not */
30+
#elif defined __SUNPRO_C && __SUNPRO_C >= 0x550
31+
# define CMARK_EXPORT __global
32+
33+
/* All else failed, and we don't know about this compiler. Be conservative. */
34+
#else
35+
# define CMARK_EXPORT
36+
#endif
37+
38+
#endif /* CMARK_EXPORT_H */

0 commit comments

Comments
 (0)