CMakeLists.txt 7.69 KB
Newer Older
1
# CMake build script for ZeroMQ tests
2
cmake_minimum_required(VERSION "2.8.1")
3

4
# On Windows: solution file will be called tests.sln
5
project(tests)
6 7

set(tests
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
  test_ancillaries
  test_system
  test_pair_inproc
  test_pair_tcp
  test_reqrep_inproc
  test_reqrep_tcp
  test_hwm
  test_hwm_pubsub
  test_reqrep_device
  test_sub_forward
  test_invalid_rep
  test_msg_flags
  test_msg_ffn
  test_connect_resolve
  test_immediate
  test_last_endpoint
  test_term_endpoint
  test_router_mandatory
  test_probe_router
  test_stream
  test_stream_empty
  test_stream_disconnect
  test_disconnect_inproc
  test_unbind_wildcard
  test_ctx_options
  test_ctx_destroy
34
  test_security_no_zap_handler
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
  test_security_null
  test_security_plain
  test_security_zap
  test_iov
  test_spec_req
  test_spec_rep
  test_spec_dealer
  test_spec_router
  test_spec_pushpull
  test_req_correlate
  test_req_relaxed
  test_conflate
  test_inproc_connect
  test_issue_566
  test_shutdown_stress
  test_timeo
  test_many_sockets
  test_diffserv
  test_connect_rid
  test_xpub_nodrop
  test_pub_invert_matching
  test_setsockopt
  test_sockopt_hwm
  test_heartbeats
  test_atomics
  test_bind_src_address
  test_capabilities
  test_metadata
  test_router_handover
  test_srcfd
  test_stream_timeout
  test_xpub_manual
  test_xpub_welcome_msg
  test_xpub_verbose
  test_base85
  test_bind_after_connect_tcp
  test_sodium
  test_monitor
  test_socket_null
  test_reconnect_ivl
  test_mock_pub_sub
76
)
77

78 79 80 81 82
if(NOT WIN32)
  list(APPEND tests
    test_security_gssapi)
endif()

83
if(ZMQ_HAVE_CURVE)
84 85
  list(APPEND tests
    test_security_curve)
86
endif()
87

88 89 90 91 92 93 94 95 96 97
find_program(CAPSH_PROGRAM NAMES capsh)

if (CAPSH_PROGRAM)
    list(APPEND tests
        test_pair_tcp_cap_net_admin
        )
else()
    message(STATUS "capsh not found, skipping tests that require CAP_NET_ADMIN")
endif()

98 99
if(NOT WIN32)
  list(APPEND tests
100 101 102 103 104
    test_ipc_wildcard
    test_pair_ipc
    test_rebind_ipc
    test_reqrep_ipc
    test_proxy
105
    test_proxy_hwm
106 107 108 109 110 111 112 113
    test_proxy_single_socket
    test_proxy_terminate
    test_getsockopt_memset
    test_filter_ipc
    test_stream_exceeds_buffer
    test_router_mandatory_hwm
    test_use_fd
    test_zmq_poll_fd
114 115 116 117
  )
  if(HAVE_FORK)
    list(APPEND tests test_fork)
  endif()
118 119
  if(CMAKE_SYSTEM_NAME MATCHES "Linux")
    list(APPEND tests
120 121
      test_abstract_ipc
      )
122 123
    if(ZMQ_HAVE_TIPC)
      list(APPEND tests
124 125 126 127 128 129 130 131 132
        test_address_tipc
        test_pair_tipc
        test_reqrep_device_tipc
        test_reqrep_tipc
        test_router_mandatory_tipc
        test_sub_forward_tipc
        test_connect_delay_tipc
        test_shutdown_stress_tipc
        test_term_endpoint_tipc
133 134
      )
    endif()
135
  endif()
136
endif()
Ilya Kulakov's avatar
Ilya Kulakov committed
137 138 139

if(WITH_VMCI)
  list(APPEND tests
140 141
    test_pair_vmci
    test_reqrep_vmci
Ilya Kulakov's avatar
Ilya Kulakov committed
142 143
  )
endif()
144

145 146 147 148 149 150 151 152 153 154 155
if(ENABLE_DRAFTS)
  list(APPEND tests
    test_poller
    test_thread_safe
    test_client_server
    test_timers
    test_radio_dish
    test_scatter_gather
    test_dgram
    test_app_meta
    test_router_notify
156
    test_xpub_manual_last_value
157 158
  )
endif()
159

160 161
# add location of platform.hpp for Windows builds
if(WIN32)
162 163 164 165
  add_definitions(-DZMQ_CUSTOM_PLATFORM_HPP)
  add_definitions(-D_WINSOCK_DEPRECATED_NO_WARNINGS)
  # Same name on 64bit systems
  link_libraries(ws2_32.lib)
166 167
endif()

168 169 170 171 172 173
add_library(unity STATIC
  "${CMAKE_CURRENT_LIST_DIR}/../external/unity/unity.c"
  "${CMAKE_CURRENT_LIST_DIR}/../external/unity/unity.h"
  "${CMAKE_CURRENT_LIST_DIR}/../external/unity/unity_internals.h")
set_target_properties(unity PROPERTIES
  PUBLIC_HEADER "${CMAKE_CURRENT_LIST_DIR}/../external/unity/unity.h")
174
target_compile_definitions(unity PUBLIC "UNITY_USE_COMMAND_LINE_ARGS" "UNITY_EXCLUDE_FLOAT")
175 176
target_include_directories(unity PUBLIC "${CMAKE_CURRENT_LIST_DIR}/../external/unity")

177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202
set(TESTUTIL_SOURCES
    testutil.cpp
    testutil.hpp
    testutil_monitoring.cpp
    testutil_monitoring.hpp
    testutil_security.cpp
    testutil_security.hpp
    testutil_unity.cpp
    testutil_unity.hpp
    )
if(BUILD_STATIC)
    add_library(testutil-static STATIC ${TESTUTIL_SOURCES})
    target_link_libraries(testutil-static libzmq-static ${OPTIONAL_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} unity)
endif()
if(BUILD_SHARED)
    add_library(testutil STATIC ${TESTUTIL_SOURCES})
    target_link_libraries(testutil libzmq ${OPTIONAL_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} unity)
endif()
if(BUILD_STATIC AND NOT BUILD_SHARED)
    # use testutil-static for both tests and unit tests
    set(TESTUTIL_LIB testutil-static)
else()
    # use testutil for tests and testutil-static for unit tests
    set(TESTUTIL_LIB testutil)
endif()

203 204 205
if(MSVC_VERSION LESS 1700)
  set_source_files_properties("${CMAKE_CURRENT_LIST_DIR}/../external/unity/unity.c" PROPERTIES LANGUAGE CXX)
endif()
Kachanovskiy's avatar
Kachanovskiy committed
206

207 208 209
if(MSVC_VERSION LESS 1600)
  target_compile_definitions(unity PUBLIC "UNITY_EXCLUDE_STDINT_H")
endif()
210

211
# add include dirs for all targets
212
include_directories("${ZeroMQ_SOURCE_DIR}/../include" "${ZeroMQ_BINARY_DIR}")
213 214 215
if(WIN32)
  add_definitions(-D_CRT_NONSTDC_NO_DEPRECATE)
endif()
216

217
foreach(test ${tests})
218
  # target_sources not supported before CMake 3.1
219
  if(ZMQ_HAVE_CURVE AND ${test} MATCHES test_security_curve)
220
    add_executable(${test} ${test}.cpp
221 222 223
      "../src/tweetnacl.c"
      "../src/err.cpp"
      "../src/random.cpp"
224
      "../src/clock.cpp")
225
  else()
226
    add_executable(${test} ${test}.cpp)
227
  endif()
228
  target_link_libraries(${test} ${TESTUTIL_LIB})
229
  if(WIN32)
230 231 232 233
    # This is the output for Debug dynamic builds on Visual Studio 6.0
    # You should provide the correct directory, don't know how to do it automatically
    find_path(LIBZMQ_PATH "libzmq.lib" PATHS "../bin/Win32/Debug/v120/dynamic")
    if(NOT ${LIBZMQ_PATH} STREQUAL "LIBZMQ_PATH-NOTFOUND")
234
      set_target_properties(${test} PROPERTIES LINK_FLAGS "/LIBPATH:${LIBZMQ_PATH}")
235
    endif()
236
  else()
237
    # per-test directories not generated on OS X / Darwin
238 239
    if(NOT ${CMAKE_CXX_COMPILER_ID} MATCHES "Clang.*")
      link_directories(${test} PRIVATE "${ZeroMQ_SOURCE_DIR}/../lib")
240
    endif()
241
  endif()
242
  
243
  if(RT_LIBRARY)
244
    target_link_libraries(${test} ${RT_LIBRARY})
245
  endif()
246 247 248 249 250 251

  if(CMAKE_SYSTEM_NAME MATCHES "QNX")
    target_link_libraries(${test} socket)
    target_link_libraries(${test} m)
  endif()

252
  if(WIN32)
Doron Somech's avatar
Doron Somech committed
253
    add_test(NAME ${test} WORKING_DIRECTORY ${LIBRARY_OUTPUT_PATH} COMMAND ${test})
254
  else()
255 256 257 258 259
    if (${test} MATCHES "_cap_net_admin")
      add_test(NAME ${test} COMMAND sh -c "sudo ${CAPSH_PROGRAM} --caps=cap_net_admin+eip -- -c $<TARGET_FILE:${test}>")
    else()
      add_test(NAME ${test} COMMAND ${test})
    endif()
260
  endif()
261
  set_tests_properties(${test} PROPERTIES TIMEOUT 10)
262
  set_tests_properties(${test} PROPERTIES SKIP_RETURN_CODE 77)
263 264
endforeach()

265
#override timeout for these tests
266 267 268
if(ZMQ_HAVE_CURVE)
  set_tests_properties(test_security_curve PROPERTIES TIMEOUT 60)
endif()
269
set_tests_properties(test_heartbeats PROPERTIES TIMEOUT 60)
270

271 272
if(WIN32 AND ${POLLER} MATCHES "epoll")
  set_tests_properties(test_many_sockets PROPERTIES TIMEOUT 120)
273 274
endif()

275
if(WIN32 AND ENABLE_DRAFTS)
276 277 278
  set_tests_properties(test_radio_dish PROPERTIES TIMEOUT 30)
endif()

279
#add additional required flags
280 281
#ZMQ_USE_TWEETNACL will already be defined when not using sodium
if(ZMQ_HAVE_CURVE AND NOT ZMQ_USE_TWEETNACL)
282 283
  target_compile_definitions(test_security_curve PRIVATE "-DZMQ_USE_TWEETNACL")
endif()
284

285 286
set_tests_properties(test_security_zap PROPERTIES TIMEOUT 60)

287 288 289 290 291 292
#Check whether all tests in the current folder are present
file(READ "${CMAKE_CURRENT_LIST_FILE}" CURRENT_LIST_FILE_CONTENT)
file(GLOB ALL_TEST_SOURCES "test_*.cpp")
foreach(TEST_SOURCE ${ALL_TEST_SOURCES})
  get_filename_component(TESTNAME "${TEST_SOURCE}" NAME_WE)
  string(REGEX MATCH "${TESTNAME}" MATCH_TESTNAME "${CURRENT_LIST_FILE_CONTENT}")
293
  if(NOT MATCH_TESTNAME)
294 295 296
    message(AUTHOR_WARNING "Test '${TESTNAME}' is not known to CTest.")
  endif()
endforeach()