Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use an in-tree header for symbol export information #453

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down Expand Up @@ -87,12 +86,15 @@ if (CMARK_SHARED)
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>)
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})
Expand All @@ -113,11 +115,6 @@ if (CMARK_STATIC)
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>)
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()

Expand Down
38 changes: 38 additions & 0 deletions src/cmark_export.h.in
Original file line number Diff line number Diff line change
@@ -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 */