diff options
| author | Garrett D'Amore <garrett@damore.org> | 2018-05-24 14:59:39 -0700 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2018-05-25 08:11:26 -0700 |
| commit | 301de3ac5c7cf8a5eaaf3c58157251db781841d6 (patch) | |
| tree | d0a19062d01de0df130a59613134330809b2a5ae /src/CMakeLists.txt | |
| parent | b36dadf267842fb2fad7596f90f8f0cd78ac4af5 (diff) | |
| download | nng-301de3ac5c7cf8a5eaaf3c58157251db781841d6.tar.gz nng-301de3ac5c7cf8a5eaaf3c58157251db781841d6.tar.bz2 nng-301de3ac5c7cf8a5eaaf3c58157251db781841d6.zip | |
fixes #486 Revisit SOVERSION and VERSION
fixes #485 Honor BUILD_SHARED_LIBS
fixes #483 Don't expose private symbols in shared library
fixes #481 Export CMake target
This is a "large" commit involving changes that don't affect the
code directly, but which have an impact on how we package and build
our project.
The most significant of these changes is that we now build only
either a shared or a static library, depending on the setting of
the BUILD_SHARED_LIBS option. We also suppress private symbols
from being exposed when the underlying toolchain lets us do so.
Minor updates to the way we version the ABI are used, and we now
have a nice exported CMake project.
To import this project in another, simply do find_package(nng)
and you can add target_link_libraries(nng::nng) to your targets.
CMake does the rest for you.
Diffstat (limited to 'src/CMakeLists.txt')
| -rw-r--r-- | src/CMakeLists.txt | 45 |
1 files changed, 30 insertions, 15 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}) |
