summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2017-01-15 14:48:09 -0800
committerGarrett D'Amore <garrett@damore.org>2017-01-15 14:48:09 -0800
commit573e08a643bac0af91df90582638f1f765dab429 (patch)
treead745bb81608147304b1bb92aeb682353feedcbd
parent694ad48a9c3b4c3d3a91d323a1601c2c4ebacba9 (diff)
downloadnng-573e08a643bac0af91df90582638f1f765dab429.tar.gz
nng-573e08a643bac0af91df90582638f1f765dab429.tar.bz2
nng-573e08a643bac0af91df90582638f1f765dab429.zip
Compile static *and* shared libraries.
Test code needs to use the static libraries so that they can get access to the entire set of symbols, including private ones that are not exported.
-rw-r--r--CMakeLists.txt41
-rw-r--r--src/CMakeLists.txt22
-rw-r--r--src/platform/posix/posix_alloc.c5
-rw-r--r--src/platform/posix/posix_clock.c5
-rw-r--r--src/platform/posix/posix_debug.c5
-rw-r--r--src/platform/posix/posix_ipc.c5
-rw-r--r--src/platform/posix/posix_net.c5
-rw-r--r--src/platform/posix/posix_rand.c5
-rw-r--r--src/platform/posix/posix_thread.c5
-rw-r--r--src/platform/windows/win_clock.c5
-rw-r--r--src/platform/windows/win_debug.c5
-rw-r--r--src/platform/windows/win_ipc.c5
-rw-r--r--src/platform/windows/win_net.c5
-rw-r--r--src/platform/windows/win_rand.c5
-rw-r--r--src/platform/windows/win_thread.c5
-rw-r--r--tests/CMakeLists.txt19
16 files changed, 112 insertions, 35 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index aca10b92..68bb949d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -85,7 +85,7 @@ endif()
# User-defined options.
-option (NNG_STATIC_LIB "Build static library instead of shared library." OFF)
+#option (NNG_STATIC_LIB "Build static library instead of shared library." OFF)
option (NNG_ENABLE_DOC "Enable building documentation." ON)
option (NNG_TESTS "Build and run nanomsg tests" ON)
option (NNG_TOOLS "Build nanomsg tools" OFF)
@@ -175,33 +175,28 @@ else ()
nng_check_lib (nsl gethostbyname NNG_HAVE_LIBNSL)
nng_check_lib (socket socket NNG_HAVE_LIBSOCKET)
- nng_check_sym (atomic_cas_32 atomic.h NNG_HAVE_ATOMIC_SOLARIS)
+# nng_check_sym (atomic_cas_32 atomic.h NNG_HAVE_ATOMIC_SOLARIS)
nng_check_sym (AF_UNIX sys/socket.h NNG_HAVE_UNIX_SOCKETS)
nng_check_sym (backtrace_symbols_fd execinfo.h NNG_HAVE_BACKTRACE)
nng_check_struct_member(msghdr msg_control sys/socket.h NNG_HAVE_MSG_CONTROL)
- if (NNG_HAVE_SEMAPHORE_RT OR NNG_HAVE_SEMAPHORE_PTHREAD)
- add_definitions (-DNNG_HAVE_SEMAPHORE)
- endif ()
+# if (NNG_HAVE_SEMAPHORE_RT OR NNG_HAVE_SEMAPHORE_PTHREAD)
+# add_definitions (-DNNG_HAVE_SEMAPHORE)
+# endif ()
endif ()
-
-if (NOT NNG_ENABLE_GETADDRINFO_A)
- add_definitions (-DNNG_DISABLE_GETADDRINFO_A)
-endif ()
-
-check_c_source_compiles ("
- #include <stdint.h>
- int main()
- {
- volatile uint32_t n = 0;
- __sync_fetch_and_add (&n, 1);
- __sync_fetch_and_sub (&n, 1);
- return 0;
- }
-" NNG_HAVE_GCC_ATOMIC_BUILTINS)
-if (NNG_HAVE_GCC_ATOMIC_BUILTINS)
- add_definitions (-DNNG_HAVE_GCC_ATOMIC_BUILTINS)
-endif ()
+#check_c_source_compiles ("
+# #include <stdint.h>
+# int main()
+# {
+# volatile uint32_t n = 0;
+# __sync_fetch_and_add (&n, 1);
+# __sync_fetch_and_sub (&n, 1);
+# return 0;
+# }
+#" NNG_HAVE_GCC_ATOMIC_BUILTINS)
+#if (NNG_HAVE_GCC_ATOMIC_BUILTINS)
+# add_definitions (-DNNG_HAVE_GCC_ATOMIC_BUILTINS)
+#endif ()
add_subdirectory (src)
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 48294b35..c8168d76 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -2,7 +2,7 @@
# Copyright (c) 2012-2013 Martin Sustrik All rights reserved.
# Copyright (c) 2013 GoPivotal, Inc. All rights reserved.
# Copyright (c) 2015-2016 Jack R. Dunaway. All rights reserved.
-# Copyright 2016 Garrett D'Amore <garrett@damore.org>
+# Copyright 2017 Garrett D'Amore <garrett@damore.org>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"),
@@ -121,19 +121,23 @@ foreach (f ${NNG_SOURCES})
source_group ("${SRC_GROUP}" FILES ${f})
endforeach ()
-if (NNG_STATIC_LIB)
- add_library (${PROJECT_NAME} STATIC ${NNG_SOURCES})
-else ()
- add_library (${PROJECT_NAME} SHARED ${NNG_SOURCES})
- add_definitions (-DNNG_SHARED_LIB)
- #set_target_properties (${PROJECT_NAME} PROPERTIES SOVERSION "${NNG_ABI_VERSION}")
-endif ()
+# Static libary
+add_library (${PROJECT_NAME}_static STATIC ${NNG_SOURCES})
+
+# Shared library
+add_library (${PROJECT_NAME} SHARED ${NNG_SOURCES})
+target_compile_definitions(${PROJECT_NAME} PRIVATE -DNNG_SHARED_LIB)
+#set_target_properties (${PROJECT_NAME} PROPERTIES SOVERSION "${NNG_ABI_VERSION}")
# Set library outputs same as top-level project binary outputs
set_target_properties (${PROJECT_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
set_target_properties (${PROJECT_NAME} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
set_target_properties (${PROJECT_NAME} PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
+set_target_properties (${PROJECT_NAME}_static PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
+set_target_properties (${PROJECT_NAME}_static PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
+set_target_properties (${PROJECT_NAME}_static PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
+
target_link_libraries (${PROJECT_NAME} ${NNG_REQUIRED_LIBRARIES})
if( THREADS_HAVE_PTHREAD_ARG)
add_definitions (-pthread)
@@ -152,7 +156,7 @@ endif()
#install (
# FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc
# DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
-install (TARGETS ${PROJECT_NAME}
+install (TARGETS ${PROJECT_NAME} ${PROJECT_NAME}_static
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
diff --git a/src/platform/posix/posix_alloc.c b/src/platform/posix/posix_alloc.c
index cce348f3..aef5bbfc 100644
--- a/src/platform/posix/posix_alloc.c
+++ b/src/platform/posix/posix_alloc.c
@@ -29,4 +29,9 @@ nni_free(void *ptr, size_t size)
}
+#else
+
+// Suppress empty symbols warnings in ranlib.
+int nni_posix_alloc_not_used = 0;
+
#endif
diff --git a/src/platform/posix/posix_clock.c b/src/platform/posix/posix_clock.c
index 6b452cbf..c87fb890 100644
--- a/src/platform/posix/posix_clock.c
+++ b/src/platform/posix/posix_clock.c
@@ -125,4 +125,9 @@ nni_plat_usleep(nni_duration usec)
#endif // NNG_USE_GETTIMEOFDAY
+#else
+
+// Suppress empty symbols warnings in ranlib.
+int nni_posix_clock_not_used = 0;
+
#endif // PLATFORM_POSIX_CLOCK
diff --git a/src/platform/posix/posix_debug.c b/src/platform/posix/posix_debug.c
index 6199df1d..aa7afaea 100644
--- a/src/platform/posix/posix_debug.c
+++ b/src/platform/posix/posix_debug.c
@@ -106,4 +106,9 @@ nni_plat_errno(int errnum)
}
+#else
+
+// Suppress empty symbols warnings in ranlib.
+int nni_posix_debug_not_used = 0;
+
#endif // PLATFORM_POSIX_DEBUG
diff --git a/src/platform/posix/posix_ipc.c b/src/platform/posix/posix_ipc.c
index 6044280e..584dc4a9 100644
--- a/src/platform/posix/posix_ipc.c
+++ b/src/platform/posix/posix_ipc.c
@@ -340,4 +340,9 @@ nni_plat_ipc_accept(nni_plat_ipcsock *s, nni_plat_ipcsock *server)
}
+#else
+
+// Suppress empty symbols warnings in ranlib.
+int nni_posix_ipc_not_used = 0;
+
#endif // PLATFORM_POSIX_IPC
diff --git a/src/platform/posix/posix_net.c b/src/platform/posix/posix_net.c
index f9720b66..b89e7c49 100644
--- a/src/platform/posix/posix_net.c
+++ b/src/platform/posix/posix_net.c
@@ -391,4 +391,9 @@ nni_plat_tcp_accept(nni_plat_tcpsock *s, nni_plat_tcpsock *server)
}
+#else
+
+// Suppress empty symbols warnings in ranlib.
+int nni_posix_net_not_used = 0;
+
#endif // PLATFORM_POSIX_NET
diff --git a/src/platform/posix/posix_rand.c b/src/platform/posix/posix_rand.c
index 2576a444..76b2ee46 100644
--- a/src/platform/posix/posix_rand.c
+++ b/src/platform/posix/posix_rand.c
@@ -83,4 +83,9 @@ nni_plat_seed_prng(void *buf, size_t bufsz)
}
+#else
+
+// Suppress empty symbols warnings in ranlib.
+int nni_posix_rand_not_used = 0;
+
#endif // PLATFORM_POSIX_RANDOM
diff --git a/src/platform/posix/posix_thread.c b/src/platform/posix/posix_thread.c
index 7b4dbbdc..91fbdff7 100644
--- a/src/platform/posix/posix_thread.c
+++ b/src/platform/posix/posix_thread.c
@@ -313,4 +313,9 @@ nni_plat_fini(void)
}
+#else
+
+// Suppress empty symbols warnings in ranlib.
+int nni_posix_thread_not_used = 0;
+
#endif
diff --git a/src/platform/windows/win_clock.c b/src/platform/windows/win_clock.c
index bdb2f550..9a2546ae 100644
--- a/src/platform/windows/win_clock.c
+++ b/src/platform/windows/win_clock.c
@@ -26,4 +26,9 @@ nni_plat_usleep(nni_duration usec)
}
+#else
+
+// Suppress empty symbols warnings in ranlib.
+int nni_win_clock_not_used = 0;
+
#endif // PLATFORM_WINDOWS
diff --git a/src/platform/windows/win_debug.c b/src/platform/windows/win_debug.c
index 00fd6493..cf8ad9eb 100644
--- a/src/platform/windows/win_debug.c
+++ b/src/platform/windows/win_debug.c
@@ -78,4 +78,9 @@ nni_plat_errno(int errnum)
}
+#else
+
+// Suppress empty symbols warnings in ranlib.
+int nni_win_debug_not_used = 0;
+
#endif // PLATFORM_WINDOWS
diff --git a/src/platform/windows/win_ipc.c b/src/platform/windows/win_ipc.c
index feef6942..42590ee9 100644
--- a/src/platform/windows/win_ipc.c
+++ b/src/platform/windows/win_ipc.c
@@ -345,4 +345,9 @@ nni_plat_ipc_connect(nni_plat_ipcsock *s, const char *path)
}
+#else
+
+// Suppress empty symbols warnings in ranlib.
+int nni_win_ipc_not_used = 0;
+
#endif // PLATFORM_WINDOWS
diff --git a/src/platform/windows/win_net.c b/src/platform/windows/win_net.c
index 65f986bd..48be1781 100644
--- a/src/platform/windows/win_net.c
+++ b/src/platform/windows/win_net.c
@@ -557,4 +557,9 @@ nni_plat_tcp_accept(nni_plat_tcpsock *s, nni_plat_tcpsock *server)
}
+#else
+
+// Suppress empty symbols warnings in ranlib.
+int nni_win_net_not_used = 0;
+
#endif // PLATFORM_WINDOWS
diff --git a/src/platform/windows/win_rand.c b/src/platform/windows/win_rand.c
index 8bca5927..a1e381d8 100644
--- a/src/platform/windows/win_rand.c
+++ b/src/platform/windows/win_rand.c
@@ -30,4 +30,9 @@ nni_plat_seed_prng(void *buf, size_t bufsz)
}
+#else
+
+// Suppress empty symbols warnings in ranlib.
+int nni_win_rand_not_used = 0;
+
#endif // PLATFORM_WINDOWS
diff --git a/src/platform/windows/win_thread.c b/src/platform/windows/win_thread.c
index 4d47f18e..2dcb62fe 100644
--- a/src/platform/windows/win_thread.c
+++ b/src/platform/windows/win_thread.c
@@ -196,4 +196,9 @@ nni_plat_fini(void)
}
+#else
+
+// Suppress empty symbols warnings in ranlib.
+int nni_win_thread_not_used = 0;
+
#endif
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 5f8dc7f9..066865e3 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -2,7 +2,7 @@
# Copyright (c) 2012 Martin Sustrik All rights reserved.
# Copyright (c) 2013 GoPivotal, Inc. All rights reserved.
# Copyright (c) 2015-2016 Jack R. Dunaway. All rights reserved.
-# Copyright 2016 Garrett D'Amore <garrett@damore.org>
+# Copyright 2017 Garrett D'Amore <garrett@damore.org>
# Copyright 2016 Franklin "Snaipe" Mathieu <franklinmathieu@gmail.com>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -30,11 +30,20 @@ include_directories(AFTER SYSTEM ${PROJECT_SOURCE_DIR}/src)
if (NNG_TESTS)
+ if (THREADS_HAVE_PTHREAD_ARG)
+ add_definitions (-pthread)
+ endif()
+
set (TEST_PORT 12100)
macro (add_nng_test NAME TIMEOUT)
list (APPEND all_tests ${NAME})
add_executable (${NAME} ${NAME}.c convey.c)
- target_link_libraries (${NAME} ${PROJECT_NAME})
+ target_link_libraries (${NAME} ${PROJECT_NAME}_static)
+ target_link_libraries (${NAME} ${NNG_REQUIRED_LIBRARIES})
+ if (CMAKE_THREAD_LIBS_INIT)
+ target_link_libraries (${NAME} "${CMAKE_THREAD_LIBS_INIT}")
+ endif()
+
add_test (NAME ${NAME} COMMAND ${NAME} -v ${TEST_PORT})
set_tests_properties (${NAME} PROPERTIES TIMEOUT ${TIMEOUT})
math (EXPR TEST_PORT "${TEST_PORT}+10")
@@ -42,7 +51,11 @@ if (NNG_TESTS)
macro (add_nng_perf NAME)
add_executable (${NAME} perf/${NAME}.c)
- target_link_libraries (${NAME} ${PROJECT_NAME})
+ target_link_libraries (${NAME} ${PROJECT_NAME}_static)
+ target_link_libraries (${NAME} ${NNG_REQUIRED_LIBRARIES})
+ if (CMAKE_THREAD_LIBS_INIT)
+ target_link_libraries (${NAME} "${CMAKE_THREAD_LIBS_INIT}")
+ endif()
endmacro (add_nng_perf)
else ()