From e1a895917c755179a6ba9750a6a683daf5d3001f Mon Sep 17 00:00:00 2001 From: Iwan Paolucci Date: Thu, 18 Apr 2019 13:23:36 +0200 Subject: [PATCH] Problem: libzmq does not build on QNX 6.6 using CMake #3479 Solution: libm and libsocket have to be linked explicitely --- CMakeLists.txt | 23 +++++++++++++++++++++-- tests/CMakeLists.txt | 8 +++++++- unittests/CMakeLists.txt | 5 +++++ 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5aa65c25..9fed7b76 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -350,8 +350,11 @@ if(CMAKE_SYSTEM_NAME STREQUAL "WindowsStore" AND CMAKE_SYSTEM_VERSION STREQUAL " endif() if(NOT MSVC) check_include_files(ifaddrs.h ZMQ_HAVE_IFADDRS) + message("ZMQ_HAVE_IFADDRS: ${ZMQ_HAVE_IFADDRS}") check_include_files(sys/uio.h ZMQ_HAVE_UIO) + message("ZMQ_HAVE_UIO: ${ZMQ_HAVE_UIO}") check_include_files(sys/eventfd.h ZMQ_HAVE_EVENTFD) + message("ZMQ_HAVE_EVENTFD: ${ZMQ_HAVE_EVENTFD}") if(ZMQ_HAVE_EVENTFD AND NOT CMAKE_CROSSCOMPILING) zmq_check_efd_cloexec() endif() @@ -373,7 +376,9 @@ if(ZMQ_HAVE_WINDOWS) check_library_exists(ws2 fopen "" HAVE_WS2) else() check_cxx_symbol_exists(SO_PEERCRED sys/socket.h ZMQ_HAVE_SO_PEERCRED) + message("ZMQ_HAVE_SO_PEERCRED: ${ZMQ_HAVE_SO_PEERCRED}") check_cxx_symbol_exists(LOCAL_PEERCRED sys/socket.h ZMQ_HAVE_LOCAL_PEERCRED) + message("ZMQ_HAVE_LOCAL_PEERCRED: ${ZMQ_HAVE_LOCAL_PEERCRED}") endif() find_library(RT_LIBRARY rt) @@ -401,26 +406,33 @@ if(NOT MSVC) set(CMAKE_REQUIRED_LIBRARIES rt) check_function_exists(clock_gettime HAVE_CLOCK_GETTIME) set(CMAKE_REQUIRED_LIBRARIES) + message("HAVE_CLOCK_GETTIME: ${HAVE_CLOCK_GETTIME}") set(CMAKE_REQUIRED_INCLUDES unistd.h) check_function_exists(fork HAVE_FORK) set(CMAKE_REQUIRED_INCLUDES) + message("HAVE_FORK: ${HAVE_FORK}") set(CMAKE_REQUIRED_INCLUDES sys/time.h) check_function_exists(gethrtime HAVE_GETHRTIME) set(CMAKE_REQUIRED_INCLUDES) + message("HAVE_GETHRTIME: ${HAVE_GETHRTIME}") set(CMAKE_REQUIRED_INCLUDES stdlib.h) check_function_exists(mkdtemp HAVE_MKDTEMP) set(CMAKE_REQUIRED_INCLUDES) + message("HAVE_MKDTEMP: ${HAVE_MKDTEMP}") set(CMAKE_REQUIRED_INCLUDES sys/socket.h) check_function_exists(accept4 HAVE_ACCEPT4) set(CMAKE_REQUIRED_INCLUDES) + message("HAVE_ACCEPT4: ${HAVE_ACCEPT4}") set(CMAKE_REQUIRED_INCLUDES string.h) check_function_exists(strnlen HAVE_STRNLEN) set(CMAKE_REQUIRED_INCLUDES) + message("HAVE_STRNLEN: ${HAVE_STRNLEN}") + endif() add_definitions(-D_REENTRANT -D_THREAD_SAFE) @@ -516,7 +528,7 @@ if(${CMAKE_CXX_COMPILER_ID} MATCHES "SunPro") zmq_check_cxx_flag_prepend("-features=zla") endif() -if(CMAKE_SYSTEM_NAME MATCHES "SunOS" OR CMAKE_SYSTEM_NAME MATCHES "NetBSD") +if(CMAKE_SYSTEM_NAME MATCHES "SunOS" OR CMAKE_SYSTEM_NAME MATCHES "NetBSD" OR CMAKE_SYSTEM_NAME MATCHES "QNX") message(STATUS "Checking whether atomic operations can be used") check_c_source_compiles( "\ @@ -530,7 +542,7 @@ if(CMAKE_SYSTEM_NAME MATCHES "SunOS" OR CMAKE_SYSTEM_NAME MATCHES "NetBSD") } \ " HAVE_ATOMIC_H) - + message("HAVE_ATOMIC_H: ${HAVE_ATOMIC_H}") if(NOT HAVE_ATOMIC_H) set(ZMQ_FORCE_MUTEXES 1) endif() @@ -1209,6 +1221,9 @@ else() add_library(libzmq-static STATIC $ ${public_headers} ${html-docs} ${readme-docs} ${zmq-pkgconfig} ${CMAKE_CURRENT_BINARY_DIR}/version.rc) endif() + if(CMAKE_SYSTEM_NAME MATCHES "QNX") + target_link_libraries(libzmq-static m) + endif() set_target_properties(libzmq-static PROPERTIES PUBLIC_HEADER "${public_headers}" OUTPUT_NAME "zmq" @@ -1287,6 +1302,10 @@ if(BUILD_STATIC) if(RT_LIBRARY) target_link_libraries(libzmq-static -lrt) endif() + + if(CMAKE_SYSTEM_NAME MATCHES "QNX") + add_definitions(-DUNITY_EXCLUDE_MATH_H) + endif() endif() if(BUILD_SHARED) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 7106bdaf..ccae3977 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -238,10 +238,16 @@ foreach(test ${tests}) link_directories(${test} PRIVATE "${ZeroMQ_SOURCE_DIR}/../lib") endif() endif() - + if(RT_LIBRARY) target_link_libraries(${test} ${RT_LIBRARY}) endif() + + if(CMAKE_SYSTEM_NAME MATCHES "QNX") + target_link_libraries(${test} socket) + target_link_libraries(${test} m) + endif() + if(WIN32) add_test(NAME ${test} WORKING_DIRECTORY ${LIBRARY_OUTPUT_PATH} COMMAND ${test}) else() diff --git a/unittests/CMakeLists.txt b/unittests/CMakeLists.txt index d688ae3f..18e2436a 100644 --- a/unittests/CMakeLists.txt +++ b/unittests/CMakeLists.txt @@ -41,6 +41,11 @@ foreach(test ${unittests}) target_link_libraries(${test} ${RT_LIBRARY}) endif() + if(CMAKE_SYSTEM_NAME MATCHES "QNX") + target_link_libraries(${test} socket) + target_link_libraries(${test} m) + endif() + if(WIN32) add_test(NAME ${test} WORKING_DIRECTORY ${LIBRARY_OUTPUT_PATH} COMMAND ${test}) else()