aboutsummaryrefslogtreecommitdiff
path: root/CMakeLists.txt
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2018-05-24 14:59:39 -0700
committerGarrett D'Amore <garrett@damore.org>2018-05-25 08:11:26 -0700
commit301de3ac5c7cf8a5eaaf3c58157251db781841d6 (patch)
treed0a19062d01de0df130a59613134330809b2a5ae /CMakeLists.txt
parentb36dadf267842fb2fad7596f90f8f0cd78ac4af5 (diff)
downloadnng-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 'CMakeLists.txt')
-rw-r--r--CMakeLists.txt22
1 files changed, 22 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index ee50ce0d..60b1726c 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -33,6 +33,7 @@ include (CheckSymbolExists)
include (CheckStructHasMember)
include (CheckLibraryExists)
include (CheckCSourceCompiles)
+include (CheckCCompilerFlag)
include (CMakeDependentOption)
include (GNUInstallDirs)
include (TestBigEndian)
@@ -55,6 +56,7 @@ set (NNG_DESCRIPTION "High-Performance Scalability Protocols NextGen")
set (ISSUE_REPORT_MSG "Please consider opening an issue at https://github.com/nanomsg/nng")
# Determine library versions.
+set (NNG_ABI_SOVERSION 1)
set (NNG_ABI_VERSION "1.0.0")
# Determine package version.
@@ -86,6 +88,8 @@ endif()
# User-defined options.
+option(BUILD_SHARED_LIBS "Build shared library" ${BUILD_SHARED_LIBS})
+
option (NNG_TESTS "Build and run tests" ON)
option (NNG_TOOLS "Build extra tools" ON)
option (NNG_ENABLE_NNGCAT "Enable building nngcat utility." ${NNG_TOOLS})
@@ -267,6 +271,14 @@ else()
add_definitions (-DNNG_LITTLE_ENDIAN)
endif()
+# If the compiler is not on Windows, does it support hiding the
+# symbols by default? For shared libraries we would like to do this.
+if (NOT WIN32 AND NOT CYGWIN)
+ check_c_compiler_flag(-fvisibility=hidden NNG_HIDDEN_VISIBILITY)
+ if (NNG_HIDDEN_VISIBILITY)
+ add_definitions (-DNNG_HIDDEN_VISIBILITY)
+ endif()
+endif()
find_package (Threads REQUIRED)
@@ -408,6 +420,16 @@ nng_check_sym (strnlen string.h NNG_HAVE_STRNLEN)
nng_check_sym (strcasecmp string.h NNG_HAVE_STRCASECMP)
nng_check_sym (strncasecmp string.h NNG_HAVE_STRNCASECMP)
+# Set a static symbol. We do this for testing, so that tests can
+# be skipped if they would rely on symbols that might not be exported.
+# For example, idhash depends on private symbols, so don't test it
+# when using a shared library on Windows because the symbols won't
+# resolve.
+if (NOT(BUILD_SHARED_LIBS))
+ set (NNG_STATIC_LIB ON)
+ message(STATUS "Building static libs")
+endif()
+
add_subdirectory (src)
if (NNG_TESTS)