diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/CMakeLists.txt | 45 | ||||
| -rw-r--r-- | src/compat/nanomsg/nn.h | 15 | ||||
| -rw-r--r-- | src/nng.h | 9 |
3 files changed, 45 insertions, 24 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2db46c60..cfb6ff16 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -191,38 +191,53 @@ foreach (f ${NNG_SOURCES}) source_group ("${SRC_GROUP}" FILES ${f}) endforeach () -# Static libary -add_library (${PROJECT_NAME}_static STATIC ${NNG_SOURCES}) -target_compile_definitions(${PROJECT_NAME}_static PUBLIC -DNNG_STATIC_LIB) - -# Shared library -add_library (${PROJECT_NAME} SHARED ${NNG_SOURCES}) -target_compile_definitions(${PROJECT_NAME} PRIVATE -DNNG_SHARED_LIB) +# Library +add_library (${PROJECT_NAME} ${NNG_SOURCES}) + +# When building shared libraries we prefer to suppress default symbol +# visibility, so that only the symbols that should be exposed in the +# resulting library are. This is the default with Windows. +if (BUILD_SHARED_LIBS) + target_compile_definitions(${PROJECT_NAME} PRIVATE -DNNG_SHARED_LIB) + if (NNG_HIDDEN_VISIBILITY) + target_compile_definitions(${PROJECT_NAME} PRIVATE -DNNG_HIDDEN_VISIBILITY) + set_target_properties(${PROJECT_NAME} PROPERTIES C_VISIBILITY_PRESET hidden) + endif() +else() + target_compile_definitions(${PROJECT_NAME} PUBLIC -DNNG_STATIC_LIB) +endif() set_target_properties (${PROJECT_NAME} - PROPERTIES SOVERSION "${NNG_ABI_VERSION}") + PROPERTIES SOVERSION ${NNG_ABI_SOVERSION} VERSION "${NNG_ABI_VERSION}") # Set library outputs same as top-level project binary outputs -set_target_properties (${PROJECT_NAME} ${PROJECT_NAME}_static +set_target_properties (${PROJECT_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}) -set_target_properties (${PROJECT_NAME} ${PROJECT_NAME}_static +set_target_properties (${PROJECT_NAME} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}) -set_target_properties (${PROJECT_NAME} ${PROJECT_NAME}_static +set_target_properties (${PROJECT_NAME} PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}) -set_target_properties (${PROJECT_NAME} ${PROJECT_NAME}_static +set_target_properties (${PROJECT_NAME} ${PROJECT_NAME} PROPERTIES FRAMEWORK OFF) -target_link_libraries (${PROJECT_NAME} ${NNG_REQUIRED_LIBRARIES}) -target_link_libraries (${PROJECT_NAME} Threads::Threads) +target_link_libraries (${PROJECT_NAME} PRIVATE ${NNG_REQUIRED_LIBRARIES}) +target_link_libraries (${PROJECT_NAME} PRIVATE Threads::Threads) -install (TARGETS ${PROJECT_NAME} ${PROJECT_NAME}_static +install (TARGETS ${PROJECT_NAME} + EXPORT ${PROJECT_NAME}-target FRAMEWORK DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT library ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT library LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT library RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT tools ) +install (EXPORT ${PROJECT_NAME}-target + FILE ${PROJECT_NAME}-config.cmake + NAMESPACE nng:: + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} +) + # Install the header files. It would be much better if we could use # the PUBLIC_HEADER facility, but it stupidly flattens the directories. foreach (f ${NNG_HEADERS}) diff --git a/src/compat/nanomsg/nn.h b/src/compat/nanomsg/nn.h index 789aed3e..63431728 100644 --- a/src/compat/nanomsg/nn.h +++ b/src/compat/nanomsg/nn.h @@ -44,10 +44,9 @@ extern "C" { // clang-format off // NNG_DECL is used on declarations to deal with scope. -// For building Windows DLLs, it should be the appropriate -// __declspec(). (We recommend *not* building this library -// as a DLL, but instead linking it statically for your projects -// to minimize questions about link dependencies later.) +// For building Windows DLLs, it should be the appropriate __declspec(). +// For shared libraries with platforms that support hidden visibility, +// it should evaluate to __attribute__((visibility("default"))). #ifndef NN_DECL #if defined(_WIN32) && !defined(NNG_STATIC_LIB) #if defined(NNG_SHARED_LIB) @@ -56,8 +55,12 @@ extern "C" { #define NN_DECL __declspec(dllimport) #endif // NNG_SHARED_LIB #else -#define NN_DECL extern -#endif // _WIN32 && !NNG_STATIC_LIB +#if defined(NNG_SHARED_LIB) && defined(NNG_HIDDEN_VISIBILITY) +#define NN_DECL __attribute__((visibility("default"))) +#else +#define NN_DECL extern +#endif +#endif // _WIN32 && !NNG_STATIC_LIB #endif // NN_DECL #define AF_SP 1 @@ -27,9 +27,8 @@ extern "C" { // NNG_DECL is used on declarations to deal with scope. // For building Windows DLLs, it should be the appropriate __declspec(). -// (We recommend *not* building this library as a DLL, but instead linking -// it statically for your project to minimize concerns about link -// dependencies later.) +// For shared libraries with platforms that support hidden visibility, +// it should evaluate to __attribute__((visibility("default"))). #ifndef NNG_DECL #if defined(_WIN32) && !defined(NNG_STATIC_LIB) #if defined(NNG_SHARED_LIB) @@ -38,7 +37,11 @@ extern "C" { #define NNG_DECL __declspec(dllimport) #endif // NNG_SHARED_LIB #else +#if defined(NNG_SHARED_LIB) && defined(NNG_HIDDEN_VISIBILITY) +#define NNG_DECL __attribute__((visibility("default"))) +#else #define NNG_DECL extern +#endif #endif // _WIN32 && !NNG_STATIC_LIB #endif // NNG_DECL |
