diff options
| -rw-r--r-- | CMakeLists.txt | 263 | ||||
| -rw-r--r-- | cmake/NNGHelpers.cmake | 155 | ||||
| -rw-r--r-- | perf/CMakeLists.txt | 46 | ||||
| -rw-r--r-- | src/CMakeLists.txt | 205 | ||||
| -rw-r--r-- | src/compat/nanomsg/CMakeLists.txt | 3 | ||||
| -rw-r--r-- | src/core/CMakeLists.txt | 77 | ||||
| -rw-r--r-- | src/platform/posix/CMakeLists.txt | 108 | ||||
| -rw-r--r-- | src/platform/windows/CMakeLists.txt | 58 | ||||
| -rw-r--r-- | src/supplemental/http/CMakeLists.txt | 27 | ||||
| -rw-r--r-- | src/supplemental/tls/CMakeLists.txt | 11 | ||||
| -rw-r--r-- | src/supplemental/tls/mbedtls/CMakeLists.txt | 12 | ||||
| -rw-r--r-- | src/supplemental/tls/wolfssl/CMakeLists.txt | 8 | ||||
| -rw-r--r-- | src/transport/zerotier/CMakeLists.txt | 20 | ||||
| -rw-r--r-- | tests/CMakeLists.txt | 18 | ||||
| -rw-r--r-- | tests/stubs.h | 7 | ||||
| -rw-r--r-- | tests/testutil.c | 22 | ||||
| -rw-r--r-- | tools/nngcat/CMakeLists.txt | 49 |
17 files changed, 507 insertions, 582 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index d46c42b9..a2c10644 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,31 +28,13 @@ cmake_minimum_required(VERSION 3.13) project(nng C) -include(CheckFunctionExists) -include(CheckSymbolExists) -include(CheckStructHasMember) -include(CheckLibraryExists) -include(CheckCSourceCompiles) include(CheckCCompilerFlag) include(CMakeDependentOption) include(GNUInstallDirs) -include(TestBigEndian) -include(FindUnixCommands) set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake) -if (POLICY CMP0042) - # Newer cmake on MacOS should use @rpath - cmake_policy(SET CMP0042 NEW) -endif () -if (POLICY CMP0079) - cmake_policy(SET CMP0079 NEW) -endif () - -if (POLICY CMP0028) - # Double colon targets are only alias or imports. - cmake_policy(SET CMP0028 NEW) -endif () +include(NNGHelpers) set(CMAKE_C_STANDARD 99) set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) @@ -105,6 +87,28 @@ option(NNG_ENABLE_COVERAGE "Enable coverage reporting." OFF) # Enable access to private APIs for our own use. add_definitions(-DNNG_PRIVATE) +if (NOT (BUILD_SHARED_LIBS)) + set(NNG_STATIC_LIB ON) + message(STATUS "Building static libs") +endif () + +# These are library targets. The "nng" library is the main public library. +# The "nng_testing" is a full build of the library for test cases +# only, which is done statically and includes even portions of the code +# that are not part of the public library (things that may have been elided.) +# The "nng_private" library is an interface that allows some internal tools +# to obtain details about how the public library was built, so that we can +# include or not include code based on what's actually present. +add_library(nng) + +add_library(nng_testing STATIC EXCLUDE_FROM_ALL + ${PROJECT_SOURCE_DIR}/tests/testutil.c + ${PROJECT_SOURCE_DIR}/tests/testutil.h) +target_compile_definitions(nng_testing PUBLIC NNG_STATIC_LIB NNG_TEST_LIB NNG_PRIVATE) + +add_library(nng_private INTERFACE) +target_compile_definitions(nng_private INTERFACE NNG_PRIVATE) + # We can use rlimit to configure the stack size for systems # that have too small defaults. This is not used for Windows, # which can grow thread stacks sensibly. (Note that NNG can get @@ -173,13 +177,6 @@ endif () set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${NNG_WARN_FLAGS} ${NNG_COVERAGE_C_FLAGS} ${NNG_SANITIZER_FLAGS}") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${NNG_WARN_FLAGS} ${NNG_COVERAGE_C_FLAGS} ${NNG_SANITIZER_FLAGS}") -TEST_BIG_ENDIAN(NNG_BIG_ENDIAN) -if (NNG_BIG_ENDIAN) - add_definitions(-DNNG_BIG_ENDIAN) -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) @@ -255,228 +252,16 @@ else () message(AUTHOR_WARNING "${ISSUE_REPORT_MSG}") # blithely hope for POSIX to work add_definitions(-DNNG_PLATFORM_POSIX) + set(NNG_PLATFORM_POSIX ON) endif () -macro(nng_check_func SYM DEF) - check_function_exists(${SYM} ${DEF}) - if (${DEF}) - add_definitions(-D${DEF}=1) - endif () -endmacro(nng_check_func) - -macro(nng_check_sym SYM HDR DEF) - check_symbol_exists(${SYM} ${HDR} ${DEF}) - if (${DEF}) - add_definitions(-D${DEF}=1) - endif () -endmacro(nng_check_sym) - -macro(nng_check_lib LIB SYM DEF) - check_library_exists(${LIB} ${SYM} "" ${DEF}) - if (${DEF}) - add_definitions(-D${DEF}=1) - list(APPEND NNG_LIBS ${LIB}) - endif () -endmacro(nng_check_lib) - -macro(nng_check_struct_member STR MEM HDR DEF) - check_struct_has_member("struct ${STR}" ${MEM} ${HDR} ${DEF}) - if (${DEF}) - add_definitions(-D${DEF}=1) - endif () -endmacro(nng_check_struct_member) - -if (WIN32) - # Windows is a special snowflake. - list(APPEND NNG_LIBS ws2_32 mswsock advapi32) - nng_check_sym(InitializeConditionVariable windows.h NNG_HAVE_CONDVAR) - nng_check_sym(snprintf stdio.h NNG_HAVE_SNPRINTF) - if (NOT NNG_HAVE_CONDVAR OR NOT NNG_HAVE_SNPRINTF) - message(FATAL_ERROR - "Modern Windows API support is missing. " - "Versions of Windows prior to Vista are not supported. " - "Further, the 32-bit MinGW environment is not supported. " - "Ensure you have at least Windows Vista or newer, and are " - "using either Visual Studio 2013 or newer or MinGW-W64.") - endif () -else () - # Unconditionally declare the following feature test macros. These are - # needed for some platforms (glibc and SunOS/illumos) and are harmless - # on the others. - add_definitions(-D_GNU_SOURCE) - add_definitions(-D_REENTRANT) - add_definitions(-D_THREAD_SAFE) - add_definitions(-D_POSIX_PTHREAD_SEMANTICS) - list(APPEND NNG_PKGS Threads) - find_package(Threads REQUIRED) - - nng_check_func(lockf NNG_HAVE_LOCKF) - nng_check_func(flock NNG_HAVE_FLOCK) - nng_check_func(getrandom NNG_HAVE_GETRANDOM) - nng_check_func(arc4random_buf NNG_HAVE_ARC4RANDOM) - - nng_check_lib(rt clock_gettime NNG_HAVE_CLOCK_GETTIME) - nng_check_lib(pthread sem_wait NNG_HAVE_SEMAPHORE_PTHREAD) - nng_check_lib(pthread pthread_atfork NNG_HAVE_PTHREAD_ATFORK_PTHREAD) - nng_check_lib(pthread pthread_set_name_np NNG_HAVE_PTHREAD_SET_NAME_NP) - nng_check_lib(pthread pthread_setname_np NNG_HAVE_PTHREAD_SETNAME_NP) - nng_check_lib(nsl gethostbyname NNG_HAVE_LIBNSL) - nng_check_lib(socket socket NNG_HAVE_LIBSOCKET) - - # GCC needs libatomic on some architectures (e.g. ARM) because the - # underlying architecture may lack the necessary atomic primitives. - # One hopes that the libatomic implementation is superior to just using - # a pthread mutex. The symbol chosen here was identified from GCC's - # libatomic map file. - # - # Arguably when using clang, compiler-rt might be better. - nng_check_lib(atomic __atomic_load_1 NNG_HAVE_LIBATOMIC) - - 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) - nng_check_sym(eventfd sys/eventfd.h NNG_HAVE_EVENTFD) - nng_check_sym(kqueue sys/event.h NNG_HAVE_KQUEUE) - nng_check_sym(port_create port.h NNG_HAVE_PORT_CREATE) - nng_check_sym(epoll_create sys/epoll.h NNG_HAVE_EPOLL) - nng_check_sym(epoll_create1 sys/epoll.h NNG_HAVE_EPOLL_CREATE1) - nng_check_sym(getpeereid unistd.h NNG_HAVE_GETPEEREID) - nng_check_sym(SO_PEERCRED sys/socket.h NNG_HAVE_SOPEERCRED) - nng_check_struct_member(sockpeercred uid sys/socket.h NNG_HAVE_SOCKPEERCRED) - nng_check_sym(LOCAL_PEERCRED sys/un.h NNG_HAVE_LOCALPEERCRED) - nng_check_sym(LOCAL_PEERPID sys/un.h NNG_HAVE_LOCALPEERPID) - nng_check_sym(getpeerucred ucred.h NNG_HAVE_GETPEERUCRED) - nng_check_sym(atomic_flag_test_and_set stdatomic.h NNG_HAVE_STDATOMIC) - -endif () - -nng_check_sym(strlcpy string.h NNG_HAVE_STRLCPY) -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 () - -# In order to facilitate testing, we want to add a library that includes -# our common test code. We do this before iterating everywhere else so -# that we can locate our tests inside the directories where we want. if (NNG_TESTS) enable_testing() set(all_tests, "") endif () -macro(nng_test NAME) - if (NNG_TESTS) - add_executable(${NAME} ${NAME}.c ${ARGN}) - target_link_libraries(${NAME} ${PROJECT_NAME}_testlib) - target_include_directories(${NAME} PRIVATE - ${PROJECT_SOURCE_DIR}/tests - ${PROJECT_SOURCE_DIR}/src - ${PROJECT_SOURCE_DIR}/include) - add_test(NAME ${PROJECT_NAME}.${NAME} COMMAND ${NAME} -t) - set_tests_properties(${PROJECT_NAME}.${NAME} PROPERTIES TIMEOUT 180) - endif () -endmacro() - -macro(nng_test_if COND NAME) - if (${COND} AND NNG_TESTS) - add_executable(${NAME} ${NAME}.c ${ARGN}) - target_link_libraries(${NAME} ${PROJECT_NAME}_testlib) - target_include_directories(${NAME} PRIVATE - ${PROJECT_SOURCE_DIR}/tests - ${PROJECT_SOURCE_DIR}/src - ${PROJECT_SOURCE_DIR}/include) - add_test(NAME ${PROJECT_NAME}.${NAME} COMMAND ${NAME} -t) - set_tests_properties(${PROJECT_NAME}.${NAME} PROPERTIES TIMEOUT 180) - endif () -endmacro() - - -function(nng_sources_testlib) - if (NNG_TESTS) - foreach (f ${ARGN}) - target_sources(${PROJECT_NAME}_testlib PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/${f}) - endforeach () - endif () -endfunction() - -function(nng_headers_testlib) - if (NNG_TESTS) - foreach (f ${ARGN}) - target_sources(${PROJECT_NAME}_testlib PRIVATE ${PROJECT_SOURCE_DIR}/include/${f}) - endforeach () - endif () -endfunction() - -function(nng_defines_testlib) - if (NNG_TESTS) - target_compile_definitions(${PROJECT_NAME}_testlib PRIVATE ${ARGN}) - endif () -endfunction() - -function(nng_sources) - foreach (f ${ARGN}) - target_sources(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/${f}) - endforeach () - nng_sources_testlib(${ARGN}) -endfunction() - -function(nng_headers) - foreach (f ${ARGN}) - target_sources(${PROJECT_NAME} PRIVATE ${PROJECT_SOURCE_DIR}/include/${f}) - endforeach () - nng_headers_testlib(${ARGN}) -endfunction() - -function(nng_defines) - target_compile_definitions(${PROJECT_NAME} PRIVATE ${ARGN}) - nng_defines_testlib(${ARGN}) -endfunction() - -# nng_sources_if adds the sources unconditionally to the test library, -# but conditionally to the production library. This allows us to get -# full test coverage while allowing a minimized delivery. -function(nng_sources_if COND) - if (${COND}) - foreach (f ${ARGN}) - target_sources(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/${f}) - endforeach () - endif () - nng_sources_testlib(${ARGN}) -endfunction() - -function(nng_headers_if COND) - if (COND) - foreach (f ${ARGN}) - target_sources(${PROJECT_NAME} PRIVATE ${PROJECT_SOURCE_DIR}/include/${f}) - endforeach () - endif () - nng_headers_testlib(${ARGN}) -endfunction() - -function(nng_defines_if COND) - if (${COND}) - # Revisit this one - target_compile_definitions(${PROJECT_NAME} PUBLIC ${ARGN}) - endif () - nng_defines_testlib(${ARGN}) -endfunction() - add_subdirectory(src) -foreach (_PKG IN ITEMS ${NNG_PKGS}) - find_package(${_PKG} REQUIRED) -endforeach () -add_definitions(${NNG_DEFS}) - if (NNG_TESTS) add_subdirectory(tests) add_subdirectory(perf) diff --git a/cmake/NNGHelpers.cmake b/cmake/NNGHelpers.cmake new file mode 100644 index 00000000..6544a97b --- /dev/null +++ b/cmake/NNGHelpers.cmake @@ -0,0 +1,155 @@ +# +# Copyright 2020 Staysail Systems, Inc. <info@staysail.tech> +# +# This software is supplied under the terms of the MIT License, a +# copy of which should be located in the distribution where this +# file was obtained (LICENSE.txt). A copy of the license may also be +# found online at https://opensource.org/licenses/MIT. +# + +# Some NNG helper functions. + +include(CheckFunctionExists) +include(CheckSymbolExists) +include(CheckStructHasMember) +include(CheckLibraryExists) +include(CheckCSourceCompiles) + +# nng_sources adds library sources using files in the current directory. +function(nng_sources) + foreach (f ${ARGN}) + target_sources(nng PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/${f}) + target_sources(nng_testing PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/${f}) + endforeach () +endfunction() + +# nng_headers adds library sources as public headers taken rooted at the include/ directory. +function(nng_headers) + foreach (f ${ARGN}) + target_sources(nng PRIVATE ${PROJECT_SOURCE_DIR}/include/${f}) + target_sources(nng_testing PRIVATE ${PROJECT_SOURCE_DIR}/include/${f}) + endforeach () +endfunction() + +# nng_defines adds defines unconditionally. +# The public library keeps these defines private, but the test library exposes these definitions +# as some of our test cases would like to know details about how the library was compiled +# as that may modify the tests themselves. +function(nng_defines) + target_compile_definitions(nng PRIVATE ${ARGN}) + target_compile_definitions(nng_testing PUBLIC ${ARGN}) + target_compile_definitions(nng_private INTERFACE ${ARGN}) +endfunction() + +# nng_link_libraries adds link dependencies to the libraries. +function(nng_link_libraries) + target_link_libraries(nng PRIVATE ${ARGN}) + target_link_libraries(nng_testing PRIVATE ${ARGN}) +endfunction() + +# nng_include_directories adds include directories. +function(nng_include_directories) + target_include_directories(nng PRIVATE ${ARGN}) + target_include_directories(nng_testing PRIVATE ${ARGN}) +endfunction() + + +# nng_sources_if adds the sources unconditionally to the test library, +# but conditionally to the production library. This allows us to get +# full test coverage while allowing a minimized delivery. +function(nng_sources_if COND) + foreach (f ${ARGN}) + if (${COND}) + target_sources(nng PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/${f}) + endif () + target_sources(nng_testing PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/${f}) + endforeach () +endfunction() + +function(nng_headers_if COND) + foreach (f ${ARGN}) + if (COND) + target_sources(nng PRIVATE ${PROJECT_SOURCE_DIR}/include/${f}) + endif () + target_sources(nng_testing PRIVATE ${PROJECT_SOURCE_DIR}/include/${f}) + endforeach () +endfunction() + +function(nng_defines_if COND) + if (${COND}) + target_compile_definitions(nng PRIVATE ${ARGN}) + target_compile_definitions(nng_private INTERFACE ${ARGN}) + endif () + target_compile_definitions(nng_testing PUBLIC ${ARGN}) +endfunction() + +function(nng_link_libraries_if COND) + if (${COND}) + target_link_libraries(nng PRIVATE ${ARGN}) + endif () + target_link_libraries(nng_testing PRIVATE ${ARGN}) +endfunction() + +function(nng_test NAME) + if (NNG_TESTS) + add_executable(${NAME} ${NAME}.c ${ARGN}) + target_link_libraries(${NAME} nng_testing) + target_include_directories(${NAME} PRIVATE + ${PROJECT_SOURCE_DIR}/tests + ${PROJECT_SOURCE_DIR}/src + ${PROJECT_SOURCE_DIR}/include) + add_test(NAME ${PROJECT_NAME}.${NAME} COMMAND ${NAME} -t) + set_tests_properties(${PROJECT_NAME}.${NAME} PROPERTIES TIMEOUT 180) + endif () +endfunction() + +function(nng_test_if COND NAME) + if (${COND} AND NNG_TESTS) + add_executable(${NAME} ${NAME}.c ${ARGN}) + target_link_libraries(${NAME} nng_testing) + target_include_directories(${NAME} PRIVATE + ${PROJECT_SOURCE_DIR}/tests + ${PROJECT_SOURCE_DIR}/src + ${PROJECT_SOURCE_DIR}/include) + add_test(NAME ${PROJECT_NAME}.${NAME} COMMAND ${NAME} -t) + set_tests_properties(${PROJECT_NAME}.${NAME} PROPERTIES TIMEOUT 180) + endif () +endfunction() + +function(nng_check_func SYM DEF) + check_function_exists(${SYM} ${DEF}) + if (${DEF}) + target_compile_definitions(nng PRIVATE ${DEF}=1) + target_compile_definitions(nng_testing PUBLIC ${DEF}=1) + target_compile_definitions(nng_private INTERFACE ${DEF}=1) + endif () +endfunction(nng_check_func) + +function(nng_check_sym SYM HDR DEF) + check_symbol_exists(${SYM} ${HDR} ${DEF}) + if (${DEF}) + target_compile_definitions(nng PRIVATE ${DEF}=1) + target_compile_definitions(nng_testing PUBLIC ${DEF}=1) + target_compile_definitions(nng_private INTERFACE ${DEF}=1) + endif () +endfunction(nng_check_sym) + +function(nng_check_lib LIB SYM DEF) + check_library_exists(${LIB} ${SYM} "" ${DEF}) + if (${DEF}) + target_compile_definitions(nng PRIVATE ${DEF}=1) + target_compile_definitions(nng_testing PUBLIC ${DEF}=1) + target_compile_definitions(nng_private INTERFACE ${DEF}=1) + target_link_libraries(nng PRIVATE ${LIB}) + target_link_libraries(nng_testing PRIVATE ${LIB}) + endif () +endfunction(nng_check_lib) + +function(nng_check_struct_member STR MEM HDR DEF) + check_struct_has_member("struct ${STR}" ${MEM} ${HDR} ${DEF}) + if (${DEF}) + target_compile_definitions(nng PRIVATE ${DEF}=1) + target_compile_definitions(nng_testing PUBLIC ${DEF}=1) + target_compile_definitions(nng_private INTERFACE ${DEF}=1) + endif () +endfunction(nng_check_struct_member) diff --git a/perf/CMakeLists.txt b/perf/CMakeLists.txt index 5d780f2f..778e583b 100644 --- a/perf/CMakeLists.txt +++ b/perf/CMakeLists.txt @@ -1,39 +1,18 @@ # -# 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 2016 Franklin "Snaipe" Mathieu <franklinmathieu@gmail.com> -# Copyright 2018 Staysail Systems, Inc. <info@staysail.tech> +# Copyright 2020 Staysail Systems, Inc. <info@staysail.tech> # -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), -# to deal in the Software without restriction, including without limitation -# the rights to use, copy, modify, merge, publish, distribute, sublicense, -# and/or sell copies of the Software, and to permit persons to whom -# the Software is furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included -# in all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS -# IN THE SOFTWARE. +# This software is supplied under the terms of the MIT License, a +# copy of which should be located in the distribution where this +# file was obtained (LICENSE.txt). A copy of the license may also be +# found online at https://opensource.org/licenses/MIT. # # Build performance tests. -include_directories(AFTER SYSTEM ${PROJECT_SOURCE_DIR}/src) - if (NNG_TESTS) macro (add_nng_perf NAME) add_executable (${NAME} perf.c) - target_link_libraries (${NAME} ${PROJECT_NAME}) - target_compile_definitions(${NAME} PUBLIC) + target_link_libraries (${NAME} nng nng_private) endmacro (add_nng_perf) add_nng_perf(remote_lat) @@ -43,15 +22,12 @@ if (NNG_TESTS) add_nng_perf(inproc_thr) add_nng_perf(inproc_lat) - add_test (NAME ${PROJECT_NAME}.inproc_lat COMMAND inproc_lat 64 10000) - set_tests_properties (${PROJECT_NAME}.inproc_lat PROPERTIES TIMEOUT 30) - - add_test (NAME ${PROJECT_NAME}.inproc_thr COMMAND inproc_thr 1400 10000) - set_tests_properties (${PROJECT_NAME}.inproc_thr PROPERTIES TIMEOUT 30) + add_test (NAME nng.inproc_lat COMMAND inproc_lat 64 10000) + set_tests_properties (nng.inproc_lat PROPERTIES TIMEOUT 30) + add_test (NAME nng.inproc_thr COMMAND inproc_thr 1400 10000) + set_tests_properties (nng.inproc_thr PROPERTIES TIMEOUT 30) add_executable (pubdrop pubdrop.c) - target_link_libraries(pubdrop ${PROJECT_NAME}) - target_compile_definitions(pubdrop PUBLIC) - + target_link_libraries(pubdrop nng nng_private) endif () diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 568ea7d0..889b770d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,154 +1,24 @@ # # Copyright 2020 Staysail Systems, Inc. <info@staysail.tech> # Copyright 2018 Capitar IT Group BV <info@capitar.com> -# 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. # -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), -# to deal in the Software without restriction, including without limitation -# the rights to use, copy, modify, merge, publish, distribute, sublicense, -# and/or sell copies of the Software, and to permit persons to whom -# the Software is furnished to do so, subject to the following conditions: +# This software is supplied under the terms of the MIT License, a +# copy of which should be located in the distribution where this +# file was obtained (LICENSE.txt). A copy of the license may also be +# found online at https://opensource.org/licenses/MIT. # -# The above copyright notice and this permission notice shall be included -# in all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS -# IN THE SOFTWARE. -# - -add_library(${PROJECT_NAME} - nng.c - ${PROJECT_SOURCE_DIR}/include/nng/nng.h) -if (NNG_TESTS) - add_library(${PROJECT_NAME}_testlib STATIC - nng.c - ${PROJECT_SOURCE_DIR}/tests/testutil.c - ${PROJECT_SOURCE_DIR}/tests/testutil.h - ${PROJECT_SOURCE_DIR}/include/nng/nng.h) -endif () - -set(NNG_SRCS +nng_sources(nng.c) +nng_headers(nng/nng.h) - core/defs.h - core/aio.c - core/aio.h - core/clock.c - core/clock.h - core/device.c - core/device.h - core/dialer.c - core/dialer.h - core/file.c - core/file.h - core/idhash.c - core/idhash.h - core/init.c - core/init.h - core/list.c - core/list.h - core/listener.c - core/listener.h - core/lmq.c - core/lmq.h - core/message.c - core/message.h - core/msgqueue.c - core/msgqueue.h - core/nng_impl.h - core/options.c - core/options.h - core/pollable.c - core/pollable.h - core/panic.c - core/panic.h - core/pipe.c - core/pipe.h - core/platform.h - core/protocol.c - core/protocol.h - core/reap.c - core/reap.h - core/socket.c - core/socket.h - core/sockimpl.h - core/stats.c - core/stats.h - core/stream.c - core/stream.h - core/strs.c - core/strs.h - core/taskq.c - core/taskq.h - core/thread.c - core/thread.h - core/timer.c - core/timer.h - core/transport.c - core/transport.h - core/url.c - core/url.h - ) - -if (NNG_PLATFORM_POSIX) - find_package(Threads REQUIRED) - list(APPEND NNG_LIBS Threads::Threads) - - set(NNG_SRCS ${NNG_SRCS} - platform/posix/posix_impl.h - platform/posix/posix_aio.h - platform/posix/posix_ipc.h - platform/posix/posix_config.h - platform/posix/posix_pollq.h - platform/posix/posix_tcp.h - - platform/posix/posix_alloc.c - platform/posix/posix_atomic.c - platform/posix/posix_clock.c - platform/posix/posix_debug.c - platform/posix/posix_file.c - platform/posix/posix_ipcconn.c - platform/posix/posix_ipcdial.c - platform/posix/posix_ipclisten.c - platform/posix/posix_pipe.c - platform/posix/posix_resolv_gai.c - platform/posix/posix_sockaddr.c - platform/posix/posix_tcpconn.c - platform/posix/posix_tcpdial.c - platform/posix/posix_tcplisten.c - platform/posix/posix_thread.c - platform/posix/posix_udp.c - ) - - if (NNG_HAVE_PORT_CREATE) - set(NNG_SRCS ${NNG_SRCS} platform/posix/posix_pollq_port.c) - elseif (NNG_HAVE_KQUEUE) - set(NNG_SRCS ${NNG_SRCS} platform/posix/posix_pollq_kqueue.c) - elseif (NNG_HAVE_EPOLL AND NNG_HAVE_EVENTFD) - set(NNG_SRCS ${NNG_SRCS} platform/posix/posix_pollq_epoll.c) - else () - set(NNG_SRCS ${NNG_SRCS} platform/posix/posix_pollq_poll.c) - endif () +target_include_directories(nng PRIVATE ${PROJECT_SOURCE_DIR}/src) +target_include_directories(nng_testing PRIVATE ${PROJECT_SOURCE_DIR}/src) - if (NNG_HAVE_ARC4RANDOM) - set(NNG_SRCS ${NNG_SRCS} platform/posix/posix_rand_arc4random.c) - elseif (NNG_HAVE_GETRANDOM) - set(NNG_SRCS ${NNG_SRCS} platform/posix/posix_rand_getrandom.c) - else () - set(NNG_SRCS ${NNG_SRCS} platform/posix/posix_rand_urandom.c) - endif () -endif () +add_subdirectory(core) add_subdirectory(platform/windows) +add_subdirectory(platform/posix) add_subdirectory(compat/nanomsg) add_subdirectory(protocol/bus0) @@ -174,57 +44,31 @@ add_subdirectory(supplemental/tls) add_subdirectory(supplemental/util) add_subdirectory(supplemental/websocket) -include_directories(AFTER SYSTEM ${PROJECT_SOURCE_DIR}/src ${NNG_INCS}) - -add_definitions(${NNG_DEFS}) - -foreach (_PKG IN ITEMS ${NNG_PKGS}) - find_package(${_PKG} REQUIRED) -endforeach () - -# Library -target_sources(${PROJECT_NAME} PRIVATE ${NNG_SRCS}) - -if (NNG_TESTS) - target_sources(${PROJECT_NAME}_testlib PRIVATE ${NNG_SRCS}) - target_link_libraries(${PROJECT_NAME}_testlib PUBLIC ${NNG_LIBS}) - target_compile_definitions(${PROJECT_NAME}_testlib PUBLIC NNG_STATIC_LIB NNG_TEST_LIB) - target_include_directories(${PROJECT_NAME}_testlib PUBLIC ${PROJECT_SOURCE_DIR}/include) -endif () - # 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) + target_compile_definitions(nng PRIVATE NNG_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) + target_compile_definitions(nng PRIVATE NNG_HIDDEN_VISIBILITY) + set_target_properties(nng PROPERTIES C_VISIBILITY_PRESET hidden) endif () else () - target_compile_definitions(${PROJECT_NAME} PUBLIC -DNNG_STATIC_LIB) + target_compile_definitions(nng PUBLIC NNG_STATIC_LIB) endif () -set_target_properties(${PROJECT_NAME} - PROPERTIES SOVERSION ${NNG_ABI_SOVERSION} VERSION "${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(nng PROPERTIES SOVERSION ${NNG_ABI_SOVERSION} VERSION "${NNG_ABI_VERSION}") -set_target_properties(${PROJECT_NAME} ${PROJECT_NAME} - PROPERTIES FRAMEWORK OFF) +set_target_properties(nng PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}) +set_target_properties(nng PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}) +set_target_properties(nng PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}) +set_target_properties(nng PROPERTIES FRAMEWORK OFF) -target_link_libraries(${PROJECT_NAME} PRIVATE ${NNG_LIBS}) - -target_include_directories(${PROJECT_NAME} INTERFACE $<INSTALL_INTERFACE:include> +target_include_directories(nng INTERFACE $<INSTALL_INTERFACE:include> $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>) -target_include_directories(${PROJECT_NAME} PRIVATE ${PROJECT_SOURCE_DIR}/include) +target_include_directories(nng PRIVATE ${PROJECT_SOURCE_DIR}/include) +target_include_directories(nng_testing PUBLIC ${PROJECT_SOURCE_DIR}/include) install(TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME}-target @@ -250,11 +94,6 @@ install(DIRECTORY ../include/nng DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} COMPONENT Headers) -# Promote settings to parent -set(NNG_LIBS ${NNG_LIBS} PARENT_SCOPE) -set(NNG_PKGS ${NNG_PKGS} PARENT_SCOPE) -set(NNG_DEFS ${NNG_DEFS} PARENT_SCOPE) - # These are promoted for testing set(NNG_SUPP_BASE64 ${NNG_SUPP_BASE64} PARENT_SCOPE) set(NNG_SUPP_HTTP ${NNG_SUPP_HTTP} PARENT_SCOPE) diff --git a/src/compat/nanomsg/CMakeLists.txt b/src/compat/nanomsg/CMakeLists.txt index b2d99c3c..5e70e749 100644 --- a/src/compat/nanomsg/CMakeLists.txt +++ b/src/compat/nanomsg/CMakeLists.txt @@ -7,9 +7,6 @@ # found online at https://opensource.org/licenses/MIT. # -#set(COMPAT_SOURCES compat/nanomsg/nn.c) nng_sources(nn.c) -#set(NNG_SRCS ${NNG_SRCS} ${COMPAT_SOURCES} PARENT_SCOPE) - nng_test(compat_tcp_test)
\ No newline at end of file diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt new file mode 100644 index 00000000..9ecc46f8 --- /dev/null +++ b/src/core/CMakeLists.txt @@ -0,0 +1,77 @@ +# +# Copyright 2020 Staysail Systems, Inc. <info@staystail.tech> +# +# This software is supplied under the terms of the MIT License, a +# copy of which should be located in the distribution where this +# file was obtained (LICENSE.txt). A copy of the license may also be +# found online at https://opensource.org/licenses/MIT. +# + +# Core. + +nng_check_sym(strlcpy string.h NNG_HAVE_STRLCPY) +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) + +nng_sources( + defs.h + + aio.c + aio.h + clock.c + clock.h + device.c + device.h + dialer.c + dialer.h + file.c + file.h + idhash.c + idhash.h + init.c + init.h + list.c + list.h + listener.c + listener.h + lmq.c + lmq.h + message.c + message.h + msgqueue.c + msgqueue.h + nng_impl.h + options.c + options.h + pollable.c + pollable.h + panic.c + panic.h + pipe.c + pipe.h + platform.h + protocol.c + protocol.h + reap.c + reap.h + socket.c + socket.h + sockimpl.h + stats.c + stats.h + stream.c + stream.h + strs.c + strs.h + taskq.c + taskq.h + thread.c + thread.h + timer.c + timer.h + transport.c + transport.h + url.c + url.h +) diff --git a/src/platform/posix/CMakeLists.txt b/src/platform/posix/CMakeLists.txt new file mode 100644 index 00000000..02a8cb53 --- /dev/null +++ b/src/platform/posix/CMakeLists.txt @@ -0,0 +1,108 @@ +# +# Copyright 2020 Staysail Systems, Inc. <info@staystail.tech> +# +# This software is supplied under the terms of the MIT License, a +# copy of which should be located in the distribution where this +# file was obtained (LICENSE.txt). A copy of the license may also be +# found online at https://opensource.org/licenses/MIT. +# + +# POSIX. + +# We cannot use nng_sources_if because these tests don't go into +# the static library unless they also go into the dynamic. +if (NNG_PLATFORM_POSIX) + + find_package(Threads REQUIRED) + nng_link_libraries(Threads::Threads) + + # Unconditionally declare the following feature test macros. These are + # needed for some platforms (glibc and SunOS/illumos) and are harmless + # on the others. + nng_defines(_GNU_SOURCE) + nng_defines(_REENTRANT) + nng_defines(_THREAD_SAFE) + nng_defines(_POSIX_PTHREAD_SEMANTICS) + + nng_check_func(lockf NNG_HAVE_LOCKF) + nng_check_func(flock NNG_HAVE_FLOCK) + nng_check_func(getrandom NNG_HAVE_GETRANDOM) + nng_check_func(arc4random_buf NNG_HAVE_ARC4RANDOM) + + nng_check_lib(rt clock_gettime NNG_HAVE_CLOCK_GETTIME) + nng_check_lib(pthread sem_wait NNG_HAVE_SEMAPHORE_PTHREAD) + nng_check_lib(pthread pthread_atfork NNG_HAVE_PTHREAD_ATFORK_PTHREAD) + nng_check_lib(pthread pthread_set_name_np NNG_HAVE_PTHREAD_SET_NAME_NP) + nng_check_lib(pthread pthread_setname_np NNG_HAVE_PTHREAD_SETNAME_NP) + nng_check_lib(nsl gethostbyname NNG_HAVE_LIBNSL) + nng_check_lib(socket socket NNG_HAVE_LIBSOCKET) + + # GCC needs libatomic on some architectures (e.g. ARM) because the + # underlying architecture may lack the necessary atomic primitives. + # One hopes that the libatomic implementation is superior to just using + # a pthread mutex. The symbol chosen here was identified from GCC's + # libatomic map file. + # + # Arguably when using clang, compiler-rt might be better. + nng_check_lib(atomic __atomic_load_1 NNG_HAVE_LIBATOMIC) + + 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) + nng_check_sym(eventfd sys/eventfd.h NNG_HAVE_EVENTFD) + nng_check_sym(kqueue sys/event.h NNG_HAVE_KQUEUE) + nng_check_sym(port_create port.h NNG_HAVE_PORT_CREATE) + nng_check_sym(epoll_create sys/epoll.h NNG_HAVE_EPOLL) + nng_check_sym(epoll_create1 sys/epoll.h NNG_HAVE_EPOLL_CREATE1) + nng_check_sym(getpeereid unistd.h NNG_HAVE_GETPEEREID) + nng_check_sym(SO_PEERCRED sys/socket.h NNG_HAVE_SOPEERCRED) + nng_check_struct_member(sockpeercred uid sys/socket.h NNG_HAVE_SOCKPEERCRED) + nng_check_sym(LOCAL_PEERCRED sys/un.h NNG_HAVE_LOCALPEERCRED) + nng_check_sym(LOCAL_PEERPID sys/un.h NNG_HAVE_LOCALPEERPID) + nng_check_sym(getpeerucred ucred.h NNG_HAVE_GETPEERUCRED) + nng_check_sym(atomic_flag_test_and_set stdatomic.h NNG_HAVE_STDATOMIC) + + nng_sources( + posix_impl.h + posix_aio.h + posix_ipc.h + posix_config.h + posix_pollq.h + posix_tcp.h + + posix_alloc.c + posix_atomic.c + posix_clock.c + posix_debug.c + posix_file.c + posix_ipcconn.c + posix_ipcdial.c + posix_ipclisten.c + posix_pipe.c + posix_resolv_gai.c + posix_sockaddr.c + posix_tcpconn.c + posix_tcpdial.c + posix_tcplisten.c + posix_thread.c + posix_udp.c + ) + + if (NNG_HAVE_PORT_CREATE) + nng_sources(posix_pollq_port.c) + elseif (NNG_HAVE_KQUEUE) + nng_sources(posix_pollq_kqueue.c) + elseif (NNG_HAVE_EPOLL AND NNG_HAVE_EVENTFD) + nng_sources(posix_pollq_epoll.c) + else () + nng_sources(posix_pollq_poll.c) + endif () + + if (NNG_HAVE_ARC4RANDOM) + nng_sources(posix_rand_arc4random.c) + elseif (NNG_HAVE_GETRANDOM) + nng_sources(posix_rand_getrandom.c) + else () + nng_sources(posix_rand_urandom.c) + endif () +endif ()
\ No newline at end of file diff --git a/src/platform/windows/CMakeLists.txt b/src/platform/windows/CMakeLists.txt index d6607a64..174e77f8 100644 --- a/src/platform/windows/CMakeLists.txt +++ b/src/platform/windows/CMakeLists.txt @@ -12,26 +12,38 @@ # We cannot use nng_sources_if because these tests don't go into # the static library unless they also go into the dynamic. if (NNG_PLATFORM_WINDOWS) -nng_sources( - win_impl.h - win_ipc.h - win_tcp.h - win_clock.c - win_debug.c - win_file.c - win_io.c - win_ipcconn.c - win_ipcdial.c - win_ipclisten.c - win_pipe.c - win_rand.c - win_resolv.c - win_sockaddr.c - win_tcp.c - win_tcpconn.c - win_tcpdial.c - win_tcplisten.c - win_thread.c - win_udp.c - ) -endif()
\ No newline at end of file + nng_check_sym(InitializeConditionVariable windows.h NNG_HAVE_CONDVAR) + nng_check_sym(snprintf stdio.h NNG_HAVE_SNPRINTF) + if (NOT NNG_HAVE_CONDVAR OR NOT NNG_HAVE_SNPRINTF) + message(FATAL_ERROR + "Modern Windows API support is missing. " + "Versions of Windows prior to Vista are not supported. " + "Further, the 32-bit MinGW environment is not supported. " + "Ensure you have at least Windows Vista or newer, and are " + "using either Visual Studio 2013 or newer or MinGW-W64.") + endif () + nng_link_libraries(ws2_32 mswsock advapi32) + + nng_sources( + win_impl.h + win_ipc.h + win_tcp.h + win_clock.c + win_debug.c + win_file.c + win_io.c + win_ipcconn.c + win_ipcdial.c + win_ipclisten.c + win_pipe.c + win_rand.c + win_resolv.c + win_sockaddr.c + win_tcp.c + win_tcpconn.c + win_tcpdial.c + win_tcplisten.c + win_thread.c + win_udp.c + ) +endif ()
\ No newline at end of file diff --git a/src/supplemental/http/CMakeLists.txt b/src/supplemental/http/CMakeLists.txt index 2b8696b6..324484d8 100644 --- a/src/supplemental/http/CMakeLists.txt +++ b/src/supplemental/http/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright 2018 Staysail Systems, Inc. <info@staysail.tech> +# Copyright 2020 Staysail Systems, Inc. <info@staysail.tech> # Copyright 2018 Capitar IT Group BV <info@capitar.com> # # This software is supplied under the terms of the MIT License, a @@ -13,20 +13,15 @@ if (NNG_ENABLE_HTTP) set(NNG_SUPP_HTTP ON) endif() mark_as_advanced(NNG_ENABLE_HTTP) -set(_SRCS supplemental/http/http_public.c - ${PROJECT_SOURCE_DIR}/include/nng/supplemental/http/http.h - supplemental/http/http_api.h) -if (NNG_SUPP_HTTP) - set(_DEFS -DNNG_SUPP_HTTP) - list(APPEND _SRCS - supplemental/http/http_client.c - supplemental/http/http_chunk.c - supplemental/http/http_conn.c - supplemental/http/http_msg.c - supplemental/http/http_public.c - supplemental/http/http_server.c) -endif() +nng_sources(http_public.c http_api.h) +nng_headers(nng/supplemental/http/http.h) -set(NNG_DEFS ${NNG_DEFS} ${_DEFS} PARENT_SCOPE) -set(NNG_SRCS ${NNG_SRCS} ${_SRCS} PARENT_SCOPE) +nng_defines_if(NNG_SUPP_HTTP NNG_SUPP_HTTP) +nng_sources_if(NNG_SUPP_HTTP + http_client.c + http_chunk.c + http_conn.c + http_msg.c + http_public.c + http_server.c) diff --git a/src/supplemental/tls/CMakeLists.txt b/src/supplemental/tls/CMakeLists.txt index 61d9f2fb..17d957ff 100644 --- a/src/supplemental/tls/CMakeLists.txt +++ b/src/supplemental/tls/CMakeLists.txt @@ -11,7 +11,6 @@ # found online at https://opensource.org/licenses/MIT. # - if (NNG_ENABLE_TLS) set(NNG_TLS_ENGINES mbed wolf none) # We assume Mbed for now. (Someday replaced perhaps with Bear.) @@ -34,13 +33,3 @@ add_subdirectory(wolfssl) nng_sources(tls_common.c) nng_sources(tls_api.h) - -list(APPEND NNG_DEFS ${_DEFS}) -list(APPEND NNG_SRCS ${_SRCS}) -list(APPEND NNG_LIBS ${_LIBS}) -list(APPEND NNG_INCS ${_INCS}) - -set(NNG_DEFS ${NNG_DEFS} PARENT_SCOPE) -set(NNG_SRCS ${NNG_SRCS} PARENT_SCOPE) -set(NNG_LIBS ${NNG_LIBS} PARENT_SCOPE) -set(NNG_INCS ${NNG_INCS} PARENT_SCOPE) diff --git a/src/supplemental/tls/mbedtls/CMakeLists.txt b/src/supplemental/tls/mbedtls/CMakeLists.txt index 22c8e1c6..a0af30c3 100644 --- a/src/supplemental/tls/mbedtls/CMakeLists.txt +++ b/src/supplemental/tls/mbedtls/CMakeLists.txt @@ -21,16 +21,10 @@ if (NNG_TLS_ENGINE STREQUAL "mbed") # If Mbed TLS was added by a consuming project, then we should use that # instance of it, instead of configuring our own. if (TARGET mbedtls) - set(_LIBS mbedtls) + nng_link_libraries(mbedtls) else() find_package(mbedTLS REQUIRED) - set(_LIBS ${MBEDTLS_LIBRARIES}) - set(_INCS ${MBEDTLS_INCLUDE_DIR}) + nng_link_libraries(${MBEDTLS_LIBRARIES}) + nng_include_directories(${MBEDTLS_INCLUDE_DIR}) endif() - - list(APPEND NNG_LIBS ${_LIBS}) - list(APPEND NNG_INCS ${_INCS}) - - set(NNG_LIBS ${NNG_LIBS} PARENT_SCOPE) - set(NNG_INCS ${NNG_INCS} PARENT_SCOPE) endif() diff --git a/src/supplemental/tls/wolfssl/CMakeLists.txt b/src/supplemental/tls/wolfssl/CMakeLists.txt index f0b48d9a..f38f5dbe 100644 --- a/src/supplemental/tls/wolfssl/CMakeLists.txt +++ b/src/supplemental/tls/wolfssl/CMakeLists.txt @@ -13,14 +13,10 @@ if (NNG_TLS_ENGINE STREQUAL "wolf") add_subdirectory(${PROJECT_SOURCE_DIR}/extern/nng-wolfssl nng-wolfssl) - target_include_directories(nng-wolfssl PRIVATE ) - target_link_libraries(nng PRIVATE nng-wolfssl) - if (TARGET nng_testlib) - target_link_libraries(nng_testlib PRIVATE nng-wolfssl) - endif () + target_include_directories(nng-wolfssl PRIVATE) + nng_check_lib(nng-wolfssl) nng_defines(NNG_TLS_ENGINE_INIT=nng_tls_engine_init_wolf) nng_defines(NNG_TLS_ENGINE_FINI=nng_tls_engine_fini_wolf) nng_defines(NNG_SUPP_TLS) - endif () diff --git a/src/transport/zerotier/CMakeLists.txt b/src/transport/zerotier/CMakeLists.txt index bc8673c5..167a98c0 100644 --- a/src/transport/zerotier/CMakeLists.txt +++ b/src/transport/zerotier/CMakeLists.txt @@ -15,10 +15,6 @@ mark_as_advanced(NNG_TRANSPORT_ZEROTIER) if (NNG_TRANSPORT_ZEROTIER) - # The zerotiercore project will have been found at the top level - # of the package. This is necessary because import libraries cannot - # percolate back to the parent tree. - # NB: As we wind up linking libzerotiercore.a into the application, # this means that your application will *also* need to either be licensed # under the GPLv3, or you will need to have a commercial license from @@ -31,17 +27,9 @@ if (NNG_TRANSPORT_ZEROTIER) ************************************************************") find_package(zerotiercore REQUIRED) - set(_PKGS zerotiercore) - set(_LIBS zerotiercore::zerotiercore) - set(_DEFS -DNNG_TRANSPORT_ZEROTIER) - - set(_SRCS transport/zerotier/zerotier.c - transport/zerotier/zthash.c - ${PROJECT_SOURCE_DIR}/include/nng/transport/zerotier/zerotier.h) - - set(NNG_DEFS ${NNG_DEFS} ${_DEFS} PARENT_SCOPE) - set(NNG_LIBS ${NNG_LIBS} ${_LIBS} PARENT_SCOPE) - set(NNG_PKGS ${NNG_PKGS} ${_PKGS} PARENT_SCOPE) - set(NNG_SRCS ${NNG_SRCS} ${_SRCS} PARENT_SCOPE) + nng_link_libraries(zerotiercore::zerotiercore) + nng_defines(NNG_TRANSPORT_ZEROTIER) + nng_sources(zerotier.c zthash.c) + nng_headers(nng/transport/zerotier/zerotier.h) endif() diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index a7835826..aa7260ac 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -53,10 +53,10 @@ if (NNG_TESTS) set(NNG_TEST_PORT 13000) macro(add_nng_test NAME TIMEOUT) add_executable(${NAME} ${NAME}.c convey.c) - target_link_libraries(${NAME} ${PROJECT_NAME}_testlib ${THRLIB}) - add_test(NAME ${PROJECT_NAME}.${NAME} COMMAND ${NAME} -v -p TEST_PORT=${NNG_TEST_PORT}) + target_link_libraries(${NAME} nng_testing ${THRLIB}) + add_test(NAME nng.${NAME} COMMAND ${NAME} -v -p TEST_PORT=${NNG_TEST_PORT}) math(EXPR TIMEOUT ${TIMEOUT}*${TIMEOUT_FACTOR}) - set_tests_properties(${PROJECT_NAME}.${NAME} PROPERTIES TIMEOUT ${TIMEOUT}) + set_tests_properties(nng.${NAME} PROPERTIES TIMEOUT ${TIMEOUT}) math(EXPR NNG_TEST_PORT "${NNG_TEST_PORT}+20") endmacro(add_nng_test) @@ -65,12 +65,12 @@ if (NNG_TESTS) # should work and which shouldn't. macro(add_nng_compat_test NAME TIMEOUT) add_executable(${NAME} ${NAME}.c compat_testutil.c) - target_link_libraries(${NAME} ${PROJECT_NAME}_testlib) + target_link_libraries(${NAME} nng_testing) target_include_directories(${NAME} PRIVATE ${PROJECT_SOURCE_DIR}/src/compat ${PROJECT_SOURCE_DIR}/include) - add_test(NAME ${PROJECT_NAME}.${NAME} COMMAND ${NAME} ${NNG_TEST_PORT}) - set_tests_properties(${PROJECT_NAME}.${NAME} PROPERTIES TIMEOUT ${TIMEOUT}) + add_test(NAME nng.${NAME} COMMAND ${NAME} ${NNG_TEST_PORT}) + set_tests_properties(nng.${NAME} PROPERTIES TIMEOUT ${TIMEOUT}) math(EXPR NNG_TEST_PORT "${NNG_TEST_PORT}+20") endmacro(add_nng_compat_test) @@ -78,9 +78,9 @@ if (NNG_TESTS) if (NOT NNG_ENABLE_COVERAGE) enable_language(CXX) add_executable(${NAME} ${NAME}.cc) - target_link_libraries(${NAME} ${PROJECT_NAME}_testlib) - add_test(NAME ${PROJECT_NAME}.${NAME} COMMAND ${NAME} ${TEST_PORT}) - set_tests_properties(${PROJECT_NAME}.${NAME} PROPERTIES TIMEOUT ${TIMEOUT}) + target_link_libraries(${NAME} nng_testing) + add_test(NAME nng.${NAME} COMMAND ${NAME} ${TEST_PORT}) + set_tests_properties(nng.${NAME} PROPERTIES TIMEOUT ${TIMEOUT}) math(EXPR TEST_PORT "${NNG_TEST_PORT}+20") endif () endmacro(add_nng_cpp_test) diff --git a/tests/stubs.h b/tests/stubs.h index 56193cb3..8b230705 100644 --- a/tests/stubs.h +++ b/tests/stubs.h @@ -84,9 +84,10 @@ fdready(int fd) uint16_t test_htons(uint16_t in) { -#ifdef NNG_LITTLE_ENDIAN - in = ((in >> 8) & 0xff) | ((in & 0xff) << 8); -#endif + short one = 1; + if (*((char *)(void *)&one) == 1) { + in = ((in / 256) + ((in % 256) * 256)); + } return (in); } diff --git a/tests/testutil.c b/tests/testutil.c index ce9978ce..ea8386b1 100644 --- a/tests/testutil.c +++ b/tests/testutil.c @@ -114,22 +114,30 @@ testutil_pollfd(int fd) return (false); } +bool +testutil_is_little_endian(void) +{ + uint16_t num = 0x1; + uint8_t *ptr = (uint8_t *) (void *) (&num); + return (ptr[0] == 1); +} + uint16_t testutil_htons(uint16_t in) { -#ifdef NNG_LITTLE_ENDIAN - in = ((in >> 8u) & 0xffu) | ((in & 0xffu) << 8u); -#endif + if (testutil_is_little_endian()) { + in = ((in / 0x100) + ((in % 0x100) * 0x100)); + } return (in); } uint32_t testutil_htonl(uint32_t in) { -#ifdef NNG_LITTLE_ENDIAN - in = ((in >> 24u) & 0xffu) | ((in >> 8u) & 0xff00u) | - ((in << 8u) & 0xff0000u) | ((in << 24u) & 0xff000000u); -#endif + if (testutil_is_little_endian()) { + in = ((in >> 24u) & 0xffu) | ((in >> 8u) & 0xff00u) | + ((in << 8u) & 0xff0000u) | ((in << 24u) & 0xff000000u); + } return (in); } diff --git a/tools/nngcat/CMakeLists.txt b/tools/nngcat/CMakeLists.txt index 209d545e..bd7327ac 100644 --- a/tools/nngcat/CMakeLists.txt +++ b/tools/nngcat/CMakeLists.txt @@ -9,26 +9,31 @@ # if (NNG_ENABLE_NNGCAT) - add_executable (nngcat nngcat.c) - target_include_directories (nngcat PUBLIC ${PROJECT_SOURCE_DIR}/src) - target_link_libraries (nngcat ${PROJECT_NAME}) - install (TARGETS nngcat RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} - COMPONENT Tools) + add_executable(nngcat nngcat.c) + target_include_directories(nngcat PUBLIC ${PROJECT_SOURCE_DIR}/src) + target_link_libraries(nngcat nng nng_private) + install(TARGETS nngcat RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + COMPONENT Tools) - if (NNG_TESTS AND NNG_PLATFORM_POSIX AND BASH) - macro(add_nngcat_test NAME TIMEOUT) - add_test (NAME ${PROJECT_NAME}.${NAME} COMMAND ${BASH} ${CMAKE_CURRENT_SOURCE_DIR}/${NAME}_test.sh $<TARGET_FILE:nngcat>) - set_tests_properties (${PROJECT_NAME}.${NAME} PROPERTIES TIMEOUT ${TIMEOUT}) - endmacro() - add_nngcat_test (nngcat_async 10) - add_nngcat_test (nngcat_ambiguous 10) - add_nngcat_test (nngcat_need_proto 10) - add_nngcat_test (nngcat_dup_proto 10) - add_nngcat_test (nngcat_help 10) - add_nngcat_test (nngcat_incompat 10) - add_nngcat_test (nngcat_pubsub 20) - add_nngcat_test (nngcat_recvmaxsz 20) - add_nngcat_test (nngcat_unlimited 20) - add_nngcat_test (nngcat_stdin_pipe 20) - endif() -endif() + if (NNG_TESTS AND CMAKE_SYSTEM_NAME MATCHES "Linux") + include(FindUnixCommands) + endif () + # TODO: This should be refactored to use a test driver. + # We only run the tests on Linux for now, because the Darwin CI/CD is too brittle. + if (NNG_TESTS AND BASH AND CMAKE_SYSTEM_NAME MATCHES "Linux") + macro(add_nngcat_test NAME TIMEOUT) + add_test(NAME nng.${NAME} COMMAND ${BASH} ${CMAKE_CURRENT_SOURCE_DIR}/${NAME}_test.sh $<TARGET_FILE:nngcat>) + set_tests_properties(nng.${NAME} PROPERTIES TIMEOUT ${TIMEOUT}) + endmacro() + add_nngcat_test(nngcat_async 10) + add_nngcat_test(nngcat_ambiguous 10) + add_nngcat_test(nngcat_need_proto 10) + add_nngcat_test(nngcat_dup_proto 10) + add_nngcat_test(nngcat_help 10) + add_nngcat_test(nngcat_incompat 10) + add_nngcat_test(nngcat_pubsub 20) + add_nngcat_test(nngcat_recvmaxsz 20) + add_nngcat_test(nngcat_unlimited 20) + add_nngcat_test(nngcat_stdin_pipe 20) + endif () +endif () |
