CMakeLists.txt 48.2 KB
Newer Older
1
# CMake build script for ZeroMQ
2
project(ZeroMQ)
3

4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
if(${CMAKE_SYSTEM_NAME} STREQUAL Darwin)
  cmake_minimum_required(VERSION 3.0.2)
else()
  cmake_minimum_required(VERSION 2.8.12)
endif()

option(ENABLE_ASAN "Build with address sanitizer)" OFF)
if(ENABLE_ASAN)
  message(STATUS "Instrumenting with Address Sanitizer")
  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -fsanitize-address-use-after-scope -fno-omit-frame-pointer")
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fsanitize-address-use-after-scope -fno-omit-frame-pointer")
  set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fsanitize=address -fsanitize-address-use-after-scope")
  set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address -fsanitize-address-use-after-scope")
endif()

option (ENABLE_INTRINSICS "Build using compiler intrinsics for atomic ops" OFF)
if (ENABLE_INTRINSICS)
   message(STATUS "Using compiler intrinsics for atomic ops")
   add_definitions(-DZMQ_HAVE_ATOMIC_INTRINSICS)
endif()

25 26 27
list(INSERT CMAKE_MODULE_PATH 0 "${CMAKE_CURRENT_SOURCE_DIR}")
set(ZMQ_CMAKE_MODULES_DIR ${CMAKE_CURRENT_SOURCE_DIR}/builds/cmake/Modules)
list(APPEND CMAKE_MODULE_PATH ${ZMQ_CMAKE_MODULES_DIR})
28

29
include(GNUInstallDirs)
30
if(${CMAKE_SYSTEM_NAME} STREQUAL Darwin)
31 32
  # Find more information: https://cmake.org/Wiki/CMake_RPATH_handling

33 34 35
  # Apply CMP0042: MACOSX_RPATH is enabled by default
  cmake_policy(SET CMP0042 NEW)

36
  # Add an install rpath if it is not a system directory
37 38 39 40
  list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}" isSystemDir)
  if("${isSystemDir}" STREQUAL "-1")
    set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}")
  endif()
41 42

  # Add linker search paths pointing to external dependencies
43 44
  set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
endif()
45

46
include(CheckCXXCompilerFlag)
47
check_cxx_compiler_flag("-std=gnu++11" COMPILER_SUPPORTS_CXX11)
48
if(COMPILER_SUPPORTS_CXX11)
49
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
50 51
endif()
include(CheckCCompilerFlag)
52
check_c_compiler_flag("-std=gnu11" COMPILER_SUPPORTS_C11)
53
if(COMPILER_SUPPORTS_C11)
54
  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu11")
55 56
endif()

57
include(ZMQSupportMacros)
58

59
if(NOT MSVC)
60 61 62 63 64 65 66 67 68
  # clang 6 has a warning that does not make sense on multi-platform code
  check_cxx_compiler_flag("-Wno-tautological-constant-compare" CXX_HAS_TAUT_WARNING)
  if(CXX_HAS_TAUT_WARNING)
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-tautological-constant-compare")
  endif()
  check_c_compiler_flag("-Wno-tautological-constant-compare" CC_HAS_TAUT_WARNING)
  if(CC_HAS_TAUT_WARNING)
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-tautological-constant-compare")
  endif()
69 70
endif()

71
# Will be used to add flags to pkg-config useful when apps want to statically link
72
set(pkg_config_libs_private "")
73
set(pkg_config_names_private "")
74

75 76
option(WITH_OPENPGM "Build with support for OpenPGM" OFF)
option(WITH_VMCI "Build with support for VMware VMCI socket" OFF)
77

78 79 80
if(APPLE)
  option(ZMQ_BUILD_FRAMEWORK "Build as OS X framework" OFF)
endif()
81 82

# Select curve encryption library, defaults to tweetnacl
83
# To use libsodium instead, use --with-libsodium(must be installed)
84 85
# To disable curve, use --disable-curve

86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
option(WITH_LIBSODIUM "Use libsodium instead of built-in tweetnacl" OFF)
option(ENABLE_CURVE "Enable CURVE security" ON)

if(NOT ENABLE_CURVE)
  message(STATUS "CURVE security is disabled")
elseif(WITH_LIBSODIUM)
  find_package(Sodium)
  if(SODIUM_FOUND)
    message(STATUS "Using libsodium for CURVE security")
    include_directories(${SODIUM_INCLUDE_DIRS})
    set(ZMQ_USE_LIBSODIUM 1)
    set(ZMQ_HAVE_CURVE 1)
  else()
    message(FATAL_ERROR
      "libsodium is not installed. Install it, then run CMake again")
  endif()
else()
  message(STATUS "Using tweetnacl for CURVE security")
  list(APPEND sources ${CMAKE_CURRENT_SOURCE_DIR}/src/tweetnacl.c)
  set(ZMQ_USE_TWEETNACL 1)
  set(ZMQ_HAVE_CURVE 1)
endif()
108

109 110
set(SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")

111 112 113 114 115 116
if(EXISTS "${SOURCE_DIR}/.git")
  option(ENABLE_DRAFTS "Build and install draft classes and methods" ON)
else()
  option(ENABLE_DRAFTS "Build and install draft classes and methods" OFF)
endif()
if(ENABLE_DRAFTS)
117
  option (ENABLE_RADIX_TREE "Use radix tree implementation to manage subscriptions" ON)
118 119 120
  add_definitions(-DZMQ_BUILD_DRAFT_API)
  set(pkg_config_defines "-DZMQ_BUILD_DRAFT_API=1")
else()
121
  option (ENABLE_RADIX_TREE "Use radix tree implementation to manage subscriptions" OFF)
122
  set(pkg_config_defines "")
123 124
endif()

125 126 127 128 129
if (ENABLE_RADIX_TREE)
   message(STATUS "Using radix tree implementation to manage subscriptions")
   add_definitions(-DZMQ_USE_RADIX_TREE)
endif()

130 131 132
option(WITH_MILITANT "Enable militant assertions" OFF)
if(WITH_MILITANT)
  add_definitions(-DZMQ_ACT_MILITANT)
133
endif()
134

135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192
set(API_POLLER "" CACHE STRING "Choose polling system for zmq_poll(er)_*. valid values are
  poll or select [default=poll unless POLLER=select]")

set(POLLER "" CACHE STRING "Choose polling system for I/O threads. valid values are
  kqueue, epoll, devpoll, pollset, poll or select [default=autodetect]")

include(CheckFunctionExists)
include(CheckTypeSize)

if(NOT MSVC)
  if(POLLER STREQUAL "")
    set(CMAKE_REQUIRED_INCLUDES sys/event.h)
    check_function_exists(kqueue HAVE_KQUEUE)
    set(CMAKE_REQUIRED_INCLUDES)
    if(HAVE_KQUEUE)
      set(POLLER "kqueue")
    endif()
  endif()

  if(POLLER STREQUAL "")
    set(CMAKE_REQUIRED_INCLUDES sys/epoll.h)
    check_function_exists(epoll_create HAVE_EPOLL)
    set(CMAKE_REQUIRED_INCLUDES)
    if(HAVE_EPOLL)
      set(POLLER "epoll")
      check_function_exists(epoll_create1 HAVE_EPOLL_CLOEXEC)
      if(HAVE_EPOLL_CLOEXEC)
        set(ZMQ_IOTHREAD_POLLER_USE_EPOLL_CLOEXEC 1)
      endif()
    endif()
  endif()

  if(POLLER STREQUAL "")
    set(CMAKE_REQUIRED_INCLUDES sys/devpoll.h)
    check_type_size("struct pollfd" DEVPOLL)
    set(CMAKE_REQUIRED_INCLUDES)
    if(HAVE_DEVPOLL)
      set(POLLER "devpoll")
    endif()
  endif()

  if(POLLER STREQUAL "")
    set(CMAKE_REQUIRED_INCLUDES sys/pollset.h)
    check_function_exists(pollset_create HAVE_POLLSET)
    set(CMAKE_REQUIRED_INCLUDES)
    if(HAVE_POLLSET)
      set(POLLER "pollset")
    endif()
  endif()

  if(POLLER STREQUAL "")
    set(CMAKE_REQUIRED_INCLUDES poll.h)
    check_function_exists(poll HAVE_POLL)
    set(CMAKE_REQUIRED_INCLUDES)
    if(HAVE_POLL)
      set(POLLER "poll")
    endif()
  endif()
193 194
endif()

195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
if(POLLER STREQUAL "")
  if(WIN32)
    set(CMAKE_REQUIRED_INCLUDES winsock2.h)
    set(HAVE_SELECT 1)
  else()
    set(CMAKE_REQUIRED_INCLUDES sys/select.h)
    check_function_exists(select HAVE_SELECT)
    set(CMAKE_REQUIRED_INCLUDES)
  endif()
  if(HAVE_SELECT)
    set(POLLER "select")
  else()
    message(FATAL_ERROR
      "Could not autodetect polling method")
  endif()
endif()

if(POLLER STREQUAL "kqueue"
  OR POLLER STREQUAL "epoll"
  OR POLLER STREQUAL "devpoll"
  OR POLLER STREQUAL "pollset"
  OR POLLER STREQUAL "poll"
  OR POLLER STREQUAL "select")
  message(STATUS "Using polling method in I/O threads: ${POLLER}")
  string(TOUPPER ${POLLER} UPPER_POLLER)
  set(ZMQ_IOTHREAD_POLLER_USE_${UPPER_POLLER} 1)
else()
  message(FATAL_ERROR "Invalid polling method")
223 224
endif()

225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242
if(POLLER STREQUAL "epoll" AND WIN32)
  message(STATUS "Including wepoll")
  list(APPEND sources ${CMAKE_CURRENT_SOURCE_DIR}/external/wepoll/wepoll.c ${CMAKE_CURRENT_SOURCE_DIR}/external/wepoll/wepoll.h)
endif()

if(API_POLLER STREQUAL "")
  if(POLLER STREQUAL "select")
    set(API_POLLER "select")
  else()
    set(API_POLLER "poll")
  endif()
endif()

message(STATUS "Using polling method in zmq_poll(er)_* API: ${API_POLLER}")
string(TOUPPER ${API_POLLER} UPPER_API_POLLER)
set(ZMQ_POLL_BASED_ON_${UPPER_API_POLLER} 1)

include(TestZMQVersion)
243
include(ZMQSourceRunChecks)
244 245 246 247 248 249 250 251 252
include(CheckIncludeFiles)
include(CheckLibraryExists)
include(CheckCCompilerFlag)
include(CheckCXXCompilerFlag)
include(CheckCSourceCompiles)
include(CheckCSourceRuns)
include(CMakeDependentOption)
include(CheckCXXSymbolExists)
include(CheckSymbolExists)
253
include(FindThreads)
254

255 256 257 258 259 260 261 262
execute_process(COMMAND getconf LEVEL1_DCACHE_LINESIZE OUTPUT_VARIABLE CACHELINE_SIZE ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
if(CACHELINE_SIZE STREQUAL "" OR CACHELINE_SIZE EQUAL 0 OR CACHELINE_SIZE EQUAL -1)
  set(ZMQ_CACHELINE_SIZE 64)
else()
  set(ZMQ_CACHELINE_SIZE ${CACHELINE_SIZE})
endif()
message(STATUS "Using ${ZMQ_CACHELINE_SIZE} bytes alignment for lock-free data structures")

263 264 265
if(NOT CYGWIN)
  # TODO cannot we simply do 'if(WIN32) set(ZMQ_HAVE_WINDOWS ON)' or similar?
  check_include_files(windows.h ZMQ_HAVE_WINDOWS)
266 267
endif()

268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310
if (WIN32)
    # from https://stackoverflow.com/a/40217291/2019765
    macro(get_WIN32_WINNT version)
        if (CMAKE_SYSTEM_VERSION)
            set(ver ${CMAKE_SYSTEM_VERSION})
            string(REGEX MATCH "^([0-9]+).([0-9])" ver ${ver})
            string(REGEX MATCH "^([0-9]+)" verMajor ${ver})
            # Check for Windows 10, b/c we'll need to convert to hex 'A'.
            if ("${verMajor}" MATCHES "10")
                set(verMajor "A")
                string(REGEX REPLACE "^([0-9]+)" ${verMajor} ver ${ver})
            endif ("${verMajor}" MATCHES "10")
            # Remove all remaining '.' characters.
            string(REPLACE "." "" ver ${ver})
            # Prepend each digit with a zero.
            string(REGEX REPLACE "([0-9A-Z])" "0\\1" ver ${ver})
            set(${version} "0x${ver}")
        endif(CMAKE_SYSTEM_VERSION)
    endmacro(get_WIN32_WINNT)

    get_WIN32_WINNT(ZMQ_WIN32_WINNT_DEFAULT)
    message(STATUS "Detected _WIN32_WINNT from CMAKE_SYSTEM_VERSION: ${ZMQ_WIN32_WINNT_DEFAULT}")

    # TODO limit _WIN32_WINNT to the actual Windows SDK version, which might be different from the default version installed with Visual Studio
    if(MSVC_VERSION STREQUAL "1500" AND CMAKE_SYSTEM_VERSION VERSION_GREATER "6.0")
        set(ZMQ_WIN32_WINNT_LIMIT "0x0600")
    elseif(MSVC_VERSION STREQUAL "1600" AND CMAKE_SYSTEM_VERSION VERSION_GREATER "6.1")
        set(ZMQ_WIN32_WINNT_LIMIT "0x0601")
    elseif(MSVC_VERSION STREQUAL "1700" AND CMAKE_SYSTEM_VERSION VERSION_GREATER "6.1")
        set(ZMQ_WIN32_WINNT_LIMIT "0x0601")
    elseif(MSVC_VERSION STREQUAL "1800" AND CMAKE_SYSTEM_VERSION VERSION_GREATER "6.2")
        set(ZMQ_WIN32_WINNT_LIMIT "0x0602")
    endif()
    if(ZMQ_WIN32_WINNT_LIMIT)
        message(STATUS "Mismatch of Visual Studio Version (${MSVC_VERSION}) and CMAKE_SYSTEM_VERSION (${CMAKE_SYSTEM_VERSION}), limiting _WIN32_WINNT to ${ZMQ_WIN32_WINNT_LIMIT}, you may override this by setting ZMQ_WIN32_WINNT")
        set(ZMQ_WIN32_WINNT_DEFAULT "${ZMQ_WIN32_WINNT_LIMIT}")
    endif()

    set(ZMQ_WIN32_WINNT "${ZMQ_WIN32_WINNT_DEFAULT}" CACHE STRING "Value to set _WIN32_WINNT to for building [default=autodetect from build environment]")

    add_definitions(-D_WIN32_WINNT=${ZMQ_WIN32_WINNT})
endif(WIN32)

311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347
###################### BEGIN condition_variable_t selection
if(NOT ZMQ_CV_IMPL)
    # prefer C++11 STL std::condition_variable implementation, if available
    check_include_files(condition_variable ZMQ_HAVE_STL_CONDITION_VARIABLE LANGUAGE CXX)

    if (ZMQ_HAVE_STL_CONDITION_VARIABLE)
        set(ZMQ_CV_IMPL_DEFAULT "stl11")
    else()
        if(WIN32 AND NOT CMAKE_SYSTEM_VERSION VERSION_LESS "6.0")
            # Win32API CONDITION_VARIABLE is supported from Windows Vista only
            set(ZMQ_CV_IMPL_DEFAULT "win32api")
        elseif(CMAKE_USE_PTHREADS_INIT)
            set(ZMQ_CV_IMPL_DEFAULT "pthreads")
        else()
            set(ZMQ_CV_IMPL_DEFAULT "none")
        endif()
    endif()

    # TODO a vxworks implementation also exists, but vxworks is not currently supported with cmake at all
    set(ZMQ_CV_IMPL "${ZMQ_CV_IMPL_DEFAULT}" CACHE STRING "Choose condition_variable_t implementation. Valid values are
       stl11, win32api, pthreads, none [default=autodetect]")
endif()

message(STATUS "Using condition_variable_t implementation: ${ZMQ_CV_IMPL}")
if(ZMQ_CV_IMPL STREQUAL "stl11")
    set(ZMQ_USE_CV_IMPL_STL11 1)
elseif(ZMQ_CV_IMPL STREQUAL "win32api")
    set(ZMQ_USE_CV_IMPL_WIN32API 1)
elseif(ZMQ_CV_IMPL STREQUAL "pthreads")
    set(ZMQ_USE_CV_IMPL_PTHREADS 1)
elseif(ZMQ_CV_IMPL STREQUAL "none")
    set(ZMQ_USE_CV_IMPL_NONE 1)
else()
    message(ERROR "Unknown value for ZMQ_CV_IMPL: ${ZMQ_CV_IMPL}")
endif()
###################### END condition_variable_t selection

348
if(CMAKE_SYSTEM_NAME STREQUAL "WindowsStore" AND CMAKE_SYSTEM_VERSION STREQUAL "10.0")
349
  set(ZMQ_HAVE_WINDOWS_UWP ON)
350
endif()
351 352 353 354 355 356 357
if(NOT MSVC)
  check_include_files(ifaddrs.h ZMQ_HAVE_IFADDRS)
  check_include_files(sys/uio.h ZMQ_HAVE_UIO)
  check_include_files(sys/eventfd.h ZMQ_HAVE_EVENTFD)
  if(ZMQ_HAVE_EVENTFD AND NOT CMAKE_CROSSCOMPILING)
    zmq_check_efd_cloexec()
  endif()
358
endif()
359

360
if(ZMQ_HAVE_WINDOWS)
361 362
  # Cannot use check_library_exists because the symbol is always declared as char(*)(void)
  set(CMAKE_REQUIRED_LIBRARIES "ws2_32.lib")
363
  check_symbol_exists(WSAStartup "winsock2.h" HAVE_WS2_32)
364 365

  set(CMAKE_REQUIRED_LIBRARIES "rpcrt4.lib")
366
  check_symbol_exists(UuidCreateSequential "rpc.h" HAVE_RPCRT4)
367 368

  set(CMAKE_REQUIRED_LIBRARIES "iphlpapi.lib")
369
  check_symbol_exists(GetAdaptersAddresses "winsock2.h;iphlpapi.h" HAVE_IPHLAPI)
370 371 372

  set(CMAKE_REQUIRED_LIBRARIES "")
  # TODO: This not the symbol we're looking for. What is the symbol?
373
  check_library_exists(ws2 fopen "" HAVE_WS2)
374
else()
375 376
  check_cxx_symbol_exists(SO_PEERCRED sys/socket.h ZMQ_HAVE_SO_PEERCRED)
  check_cxx_symbol_exists(LOCAL_PEERCRED sys/socket.h ZMQ_HAVE_LOCAL_PEERCRED)
377
endif()
378

379
find_library(RT_LIBRARY rt)
380 381 382
if(RT_LIBRARY)
  set(pkg_config_libs_private "${pkg_config_libs_private} -lrt")
endif()
383

384
find_package(Threads)
Matt Arsenault's avatar
Matt Arsenault committed
385

386 387 388 389
if(WIN32 AND NOT CYGWIN)
  if(NOT HAVE_WS2_32 AND NOT HAVE_WS2)
    message(FATAL_ERROR "Cannot link to ws2_32 or ws2")
  endif()
390

391 392 393
  if(NOT HAVE_RPCRT4)
    message(FATAL_ERROR "Cannot link to rpcrt4")
  endif()
394

395 396 397 398
  if(NOT HAVE_IPHLAPI)
    message(FATAL_ERROR "Cannot link to iphlapi")
  endif()
endif()
399

400 401 402 403
if(NOT MSVC)
  set(CMAKE_REQUIRED_LIBRARIES rt)
  check_function_exists(clock_gettime HAVE_CLOCK_GETTIME)
  set(CMAKE_REQUIRED_LIBRARIES)
404

405 406 407
  set(CMAKE_REQUIRED_INCLUDES unistd.h)
  check_function_exists(fork HAVE_FORK)
  set(CMAKE_REQUIRED_INCLUDES)
Frank's avatar
Frank committed
408

409 410 411
  set(CMAKE_REQUIRED_INCLUDES sys/time.h)
  check_function_exists(gethrtime HAVE_GETHRTIME)
  set(CMAKE_REQUIRED_INCLUDES)
412

413 414 415
  set(CMAKE_REQUIRED_INCLUDES stdlib.h)
  check_function_exists(mkdtemp HAVE_MKDTEMP)
  set(CMAKE_REQUIRED_INCLUDES)
416

417 418 419
  set(CMAKE_REQUIRED_INCLUDES sys/socket.h)
  check_function_exists(accept4 HAVE_ACCEPT4)
  set(CMAKE_REQUIRED_INCLUDES)
420 421 422 423

  set(CMAKE_REQUIRED_INCLUDES string.h)
  check_function_exists(strnlen HAVE_STRNLEN)
  set(CMAKE_REQUIRED_INCLUDES)
424
endif()
425

426 427
add_definitions(-D_REENTRANT -D_THREAD_SAFE)
add_definitions(-DZMQ_CUSTOM_PLATFORM_HPP)
428

429
option(ENABLE_EVENTFD "Enable/disable eventfd" ZMQ_HAVE_EVENTFD)
430

431 432
macro(zmq_check_cxx_flag_prepend flag)
  check_cxx_compiler_flag("${flag}" HAVE_FLAG_${flag})
433

434 435 436 437
  if(HAVE_FLAG_${flag})
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}")
  endif()
endmacro()
438

439
option(ENABLE_ANALYSIS "Build with static analysis(make take very long)" OFF)
440

441 442 443 444 445
if(MSVC)
  if(ENABLE_ANALYSIS)
    zmq_check_cxx_flag_prepend("/W4")

    zmq_check_cxx_flag_prepend("/analyze")
446 447

    # C++11/14/17-specific, but maybe possible via conditional defines
448 449 450 451 452 453
    zmq_check_cxx_flag_prepend("/wd26440") # Function '...' can be declared 'noexcept'
    zmq_check_cxx_flag_prepend("/wd26432") # If you define or delete any default operation in the type '...', define or delete them all
    zmq_check_cxx_flag_prepend("/wd26439") # This kind of function may not throw. Declare it 'noexcept'
    zmq_check_cxx_flag_prepend("/wd26447") # The function is declared 'noexcept' but calls function '...' which may throw exceptions
    zmq_check_cxx_flag_prepend("/wd26433") # Function '...' should be marked with 'override'
    zmq_check_cxx_flag_prepend("/wd26409") # Avoid calling new and delete explicitly, use std::make_unique<T> instead
454
    # Requires GSL
455 456 457 458 459 460 461
    zmq_check_cxx_flag_prepend("/wd26429") # Symbol '...' is never tested for nullness, it can be marked as not_null
    zmq_check_cxx_flag_prepend("/wd26446") # Prefer to use gsl::at()
    zmq_check_cxx_flag_prepend("/wd26481") # Don't use pointer arithmetic. Use span instead
    zmq_check_cxx_flag_prepend("/wd26472") # Don't use a static_cast for arithmetic conversions. Use brace initialization, gsl::narrow_cast or gsl::narow
    zmq_check_cxx_flag_prepend("/wd26448") # Consider using gsl::finally if final action is intended
    zmq_check_cxx_flag_prepend("/wd26400") # Do not assign the result of an allocation or a function call with an owner<T> return value to a raw pointer, use owner<T> instead
    zmq_check_cxx_flag_prepend("/wd26485") # Expression '...': No array to pointer decay(bounds.3)
462
  else()
463
    zmq_check_cxx_flag_prepend("/W3")
464
  endif()
465

466 467 468 469 470 471 472
  if(MSVC_IDE)
    set(MSVC_TOOLSET "-${CMAKE_VS_PLATFORM_TOOLSET}")
  else()
    set(MSVC_TOOLSET "")
  endif()
else()
  zmq_check_cxx_flag_prepend("-Wall")
473
endif()
474

475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  zmq_check_cxx_flag_prepend("-Wextra")
endif()

option(LIBZMQ_PEDANTIC "" ON)
option(LIBZMQ_WERROR "" OFF)

# TODO: why is -Wno-long-long defined differently than in configure.ac?
if(NOT MSVC)
  zmq_check_cxx_flag_prepend("-Wno-long-long")
  zmq_check_cxx_flag_prepend("-Wno-uninitialized")

  if(LIBZMQ_PEDANTIC)
    zmq_check_cxx_flag_prepend("-pedantic")

    if(${CMAKE_CXX_COMPILER_ID} MATCHES "Intel")
      zmq_check_cxx_flag_prepend("-strict-ansi")
    endif()

    if(${CMAKE_CXX_COMPILER_ID} MATCHES "SunPro")
      zmq_check_cxx_flag_prepend("-compat=5")
496
    endif()
497 498
  endif()
endif()
499

500 501 502 503 504 505 506 507 508 509
if(LIBZMQ_WERROR)
  if(MSVC)
    zmq_check_cxx_flag_prepend("/WX")
  else()
    zmq_check_cxx_flag_prepend("-Werror")
    if(NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
      zmq_check_cxx_flag_prepend("-errwarn=%all")
    endif()
  endif()
endif()
510

511 512 513
if(CMAKE_SYSTEM_PROCESSOR MATCHES "^sparc")
  zmq_check_cxx_flag_prepend("-mcpu=v9")
endif()
514

515 516 517
if(${CMAKE_CXX_COMPILER_ID} MATCHES "SunPro")
  zmq_check_cxx_flag_prepend("-features=zla")
endif()
518

519 520 521 522 523 524 525 526 527 528 529 530
if(CMAKE_SYSTEM_NAME MATCHES "SunOS" OR CMAKE_SYSTEM_NAME MATCHES "NetBSD")
  message(STATUS "Checking whether atomic operations can be used")
  check_c_source_compiles(
  "\
  #include <atomic.h> \
  \
  int main() \
  { \
    uint32_t value; \
    atomic_cas_32(&value, 0, 0); \
    return 0; \
  } \
531
  "
532
  HAVE_ATOMIC_H)
533

534 535 536 537
  if(NOT HAVE_ATOMIC_H)
    set(ZMQ_FORCE_MUTEXES 1)
  endif()
endif()
538

539 540 541
if(NOT ANDROID)
    zmq_check_noexcept()
endif()
542 543

#-----------------------------------------------------------------------------
544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606
if(NOT CMAKE_CROSSCOMPILING AND NOT MSVC)
  zmq_check_sock_cloexec()
  zmq_check_o_cloexec()
  zmq_check_so_bindtodevice()
  zmq_check_so_keepalive()
  zmq_check_tcp_keepcnt()
  zmq_check_tcp_keepidle()
  zmq_check_tcp_keepintvl()
  zmq_check_tcp_keepalive()
  zmq_check_tcp_tipc()
  zmq_check_pthread_setname()
  zmq_check_pthread_setaffinity()
  zmq_check_getrandom()
endif()

if(CMAKE_SYSTEM_NAME MATCHES "Linux"
  OR CMAKE_SYSTEM_NAME MATCHES "GNU/kFreeBSD"
  OR CMAKE_SYSTEM_NAME MATCHES "GNU/Hurd"
  OR CYGWIN)
  add_definitions(-D_GNU_SOURCE)
elseif(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
  add_definitions(-D__BSD_VISIBLE)
elseif(CMAKE_SYSTEM_NAME MATCHES "NetBSD")
  add_definitions(-D_NETBSD_SOURCE)
elseif(CMAKE_SYSTEM_NAME MATCHES "OpenBSD")
  add_definitions(-D_OPENBSD_SOURCE)
elseif(CMAKE_SYSTEM_NAME MATCHES "SunOS")
  add_definitions(-D_PTHREADS)
elseif(CMAKE_SYSTEM_NAME MATCHES "HP-UX")
  add_definitions(-D_POSIX_C_SOURCE=200112L)
  zmq_check_cxx_flag_prepend(-Ae)
elseif(CMAKE_SYSTEM_NAME MATCHES "Darwin")
  add_definitions(-D_DARWIN_C_SOURCE)
endif()

find_package(AsciiDoc)

cmake_dependent_option(WITH_DOC "Build Reference Guide documentation(requires DocBook)" ON
  "ASCIIDOC_FOUND;NOT WIN32" OFF)  # Do not build docs on Windows due to issues with symlinks

if(MSVC)
  if(WITH_OPENPGM)
    #set(OPENPGM_ROOT "" CACHE PATH "Location of OpenPGM")
    set(OPENPGM_VERSION_MAJOR 5)
    set(OPENPGM_VERSION_MINOR 2)
    set(OPENPGM_VERSION_MICRO 122)
    if(CMAKE_CL_64)
      find_path(OPENPGM_ROOT include/pgm/pgm.h
          PATHS
          "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Miru\\OpenPGM ${OPENPGM_VERSION_MAJOR}.${OPENPGM_VERSION_MINOR}.${OPENPGM_VERSION_MICRO}]"
          NO_DEFAULT_PATH)
      message(STATUS "OpenPGM x64 detected - ${OPENPGM_ROOT}")
    else()
      find_path(OPENPGM_ROOT include/pgm/pgm.h
          PATHS
          "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Miru\\OpenPGM ${OPENPGM_VERSION_MAJOR}.${OPENPGM_VERSION_MINOR}.${OPENPGM_VERSION_MICRO}]"
          "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Miru\\OpenPGM ${OPENPGM_VERSION_MAJOR}.${OPENPGM_VERSION_MINOR}.${OPENPGM_VERSION_MICRO}]"
          NO_DEFAULT_PATH)
      message(STATUS "OpenPGM x86 detected - ${OPENPGM_ROOT}")
    endif()
    set(OPENPGM_INCLUDE_DIRS ${OPENPGM_ROOT}/include)
    set(OPENPGM_LIBRARY_DIRS ${OPENPGM_ROOT}/lib)
    set(OPENPGM_LIBRARIES
607 608
      optimized libpgm${MSVC_TOOLSET}-mt-${OPENPGM_VERSION_MAJOR}_${OPENPGM_VERSION_MINOR}_${OPENPGM_VERSION_MICRO}.lib
      debug libpgm${MSVC_TOOLSET}-mt-gd-${OPENPGM_VERSION_MAJOR}_${OPENPGM_VERSION_MINOR}_${OPENPGM_VERSION_MICRO}.lib)
609 610 611 612
  endif()
else()
  if(WITH_OPENPGM)
    #  message(FATAL_ERROR "WITH_OPENPGM not implemented")
613

614 615 616
    if(NOT OPENPGM_PKGCONFIG_NAME)
      set(OPENPGM_PKGCONFIG_NAME "openpgm-5.2")
    endif()
617

618
    set(OPENPGM_PKGCONFIG_NAME ${OPENPGM_PKGCONFIG_NAME} CACHE STRING
619
      "Name pkg-config shall use to find openpgm libraries and include paths"
620
      FORCE)
621

622
    find_package(PkgConfig)
623
    pkg_check_modules(OPENPGM  ${OPENPGM_PKGCONFIG_NAME})
624

625 626
    if(OPENPGM_FOUND)
      message(STATUS ${OPENPGM_PKGCONFIG_NAME}" found")
627
      set(pkg_config_names_private "${pkg_config_names_private} ${OPENPGM_PKGCONFIG_NAME}")
628 629 630 631
    else()
      message(FATAL_ERROR
        ${OPENPGM_PKGCONFIG_NAME}"  not found. openpgm is searchd via `pkg-config ${OPENPGM_PKGCONFIG_NAME}`. Consider providing a valid OPENPGM_PKGCONFIG_NAME")
    endif()
632

633
    # DSO symbol visibility for openpgm
634
    if(HAVE_FLAG_VISIBILITY_HIDDEN)
635

636
    elseif(HAVE_FLAG_LDSCOPE_HIDDEN)
637

638 639 640
    endif()
  endif()
endif()
641

642 643 644 645

#-----------------------------------------------------------------------------
# force off-tree build

646 647 648 649 650 651 652 653 654
if(${CMAKE_CURRENT_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_BINARY_DIR})
  message(FATAL_ERROR "CMake generation is not allowed within the source directory! \
    Remove the CMakeCache.txt file and try again from another folder, e.g.: \
    \
      rm CMakeCache.txt \
      mkdir cmake-make \
      cd cmake-make \
      cmake ..")
endif()
655 656 657 658

#-----------------------------------------------------------------------------
# default to Release build

659
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
660 661
  # CMAKE_BUILD_TYPE is not used for multi-configuration generators like Visual Studio/XCode
  # which instead use CMAKE_CONFIGURATION_TYPES
662 663 664 665
  set(CMAKE_BUILD_TYPE Release CACHE STRING
    "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel."
    FORCE)
endif()
666

667 668 669 670 671 672 673 674 675 676 677
#-----------------------------------------------------------------------------
# output directories

zmq_set_with_default(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${ZeroMQ_BINARY_DIR}/bin")
if(UNIX)
  set(zmq_library_directory "lib")
else()
  set(zmq_library_directory "bin")
endif()
zmq_set_with_default(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${ZeroMQ_BINARY_DIR}/${zmq_library_directory}")
zmq_set_with_default(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${ZeroMQ_BINARY_DIR}/lib")
678

679 680 681
#-----------------------------------------------------------------------------
# platform specifics

682 683 684 685 686 687
if(WIN32)
  # Socket limit is 16K(can be raised arbitrarily)
  add_definitions(-DFD_SETSIZE=16384)
  add_definitions(-D_CRT_SECURE_NO_WARNINGS)
  add_definitions(-D_WINSOCK_DEPRECATED_NO_WARNINGS)
endif()
688

689
if(MSVC)
690
  # Parallel make.
691 692
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /MP")
693

694
  # Compile the static lib with debug information included
695
  # note: we assume here that the default flags contain some /Z flag
696 697
  string(REGEX REPLACE "/Z." "/Z7" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
  string(REGEX REPLACE "/Z." "/Z7" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
698

699 700
  # Optimization flags.
  # http://msdn.microsoft.com/en-us/magazine/cc301698.aspx
701 702 703 704 705 706 707
  if(NOT ${CMAKE_BUILD_TYPE} MATCHES "Debug")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /GL")
    set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /LTCG")
    set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /LTCG")
    set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} /LTCG")
  endif()
endif()
708 709


710 711 712
#-----------------------------------------------------------------------------
# source files

713 714 715 716 717 718 719 720 721 722 723 724 725
set(cxx-sources
  precompiled.cpp
  address.cpp
  client.cpp
  clock.cpp
  ctx.cpp
  curve_mechanism_base.cpp
  curve_client.cpp
  curve_server.cpp
  dealer.cpp
  devpoll.cpp
  dgram.cpp
  dist.cpp
726
  endpoint.cpp
727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744
  epoll.cpp
  err.cpp
  fq.cpp
  io_object.cpp
  io_thread.cpp
  ip.cpp
  ipc_address.cpp
  ipc_connecter.cpp
  ipc_listener.cpp
  kqueue.cpp
  lb.cpp
  mailbox.cpp
  mailbox_safe.cpp
  mechanism.cpp
  mechanism_base.cpp
  metadata.cpp
  msg.cpp
  mtrie.cpp
745
  norm_engine.cpp
746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787
  object.cpp
  options.cpp
  own.cpp
  null_mechanism.cpp
  pair.cpp
  pgm_receiver.cpp
  pgm_sender.cpp
  pgm_socket.cpp
  pipe.cpp
  plain_client.cpp
  plain_server.cpp
  poll.cpp
  poller_base.cpp
  polling_util.cpp
  pollset.cpp
  proxy.cpp
  pub.cpp
  pull.cpp
  push.cpp
  random.cpp
  raw_encoder.cpp
  raw_decoder.cpp
  reaper.cpp
  rep.cpp
  req.cpp
  router.cpp
  select.cpp
  server.cpp
  session_base.cpp
  signaler.cpp
  socket_base.cpp
  socks.cpp
  socks_connecter.cpp
  stream.cpp
  stream_engine.cpp
  sub.cpp
  tcp.cpp
  tcp_address.cpp
  tcp_connecter.cpp
  tcp_listener.cpp
  thread.cpp
  trie.cpp
788
  radix_tree.cpp
789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833
  v1_decoder.cpp
  v1_encoder.cpp
  v2_decoder.cpp
  v2_encoder.cpp
  xpub.cpp
  xsub.cpp
  zmq.cpp
  zmq_utils.cpp
  decoder_allocators.cpp
  socket_poller.cpp
  timers.cpp
  config.hpp
  radio.cpp
  dish.cpp
  udp_engine.cpp
  udp_address.cpp
  scatter.cpp
  gather.cpp
  ip_resolver.cpp
  zap_client.cpp
  # at least for VS, the header files must also be listed
  address.hpp
  array.hpp
  atomic_counter.hpp
  atomic_ptr.hpp
  blob.hpp
  client.hpp
  clock.hpp
  command.hpp
  condition_variable.hpp
  config.hpp
  ctx.hpp
  curve_client.hpp
  curve_client_tools.hpp
  curve_mechanism_base.hpp
  curve_server.hpp
  dbuffer.hpp
  dealer.hpp
  decoder.hpp
  decoder_allocators.hpp
  devpoll.hpp
  dgram.hpp
  dish.hpp
  dist.hpp
  encoder.hpp
834
  endpoint.hpp
835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910
  epoll.hpp
  err.hpp
  fd.hpp
  fq.hpp
  gather.hpp
  generic_mtrie.hpp
  generic_mtrie_impl.hpp
  gssapi_client.hpp
  gssapi_mechanism_base.hpp
  gssapi_server.hpp
  i_decoder.hpp
  i_encoder.hpp
  i_engine.hpp
  i_mailbox.hpp
  i_poll_events.hpp
  io_object.hpp
  io_thread.hpp
  ip.hpp
  ipc_address.hpp
  ipc_connecter.hpp
  ipc_listener.hpp
  kqueue.hpp
  lb.hpp
  likely.hpp
  macros.hpp
  mailbox.hpp
  mailbox_safe.hpp
  mechanism.hpp
  mechanism_base.hpp
  metadata.hpp
  msg.hpp
  mtrie.hpp
  mutex.hpp
  norm_engine.hpp
  null_mechanism.hpp
  object.hpp
  options.hpp
  own.hpp
  pair.hpp
  pgm_receiver.hpp
  pgm_sender.hpp
  pgm_socket.hpp
  pipe.hpp
  plain_client.hpp
  plain_common.hpp
  plain_server.hpp
  poll.hpp
  poller.hpp
  poller_base.hpp
  polling_util.hpp
  pollset.hpp
  precompiled.hpp
  proxy.hpp
  pub.hpp
  pull.hpp
  push.hpp
  radio.hpp
  random.hpp
  raw_decoder.hpp
  raw_encoder.hpp
  reaper.hpp
  rep.hpp
  req.hpp
  router.hpp
  scatter.hpp
  select.hpp
  server.hpp
  session_base.hpp
  signaler.hpp
  socket_base.hpp
  socket_poller.hpp
  socks.hpp
  socks_connecter.hpp
  stdint.hpp
  stream.hpp
  stream_engine.hpp
911 912
  stream_connecter_base.hpp
  stream_connecter_base.cpp
913 914
  stream_listener_base.hpp
  stream_listener_base.cpp
915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948
  sub.hpp
  tcp.hpp
  tcp_address.hpp
  tcp_connecter.hpp
  tcp_listener.hpp
  thread.hpp
  timers.hpp
  tipc_address.hpp
  tipc_connecter.hpp
  tipc_listener.hpp
  trie.hpp
  udp_address.hpp
  udp_engine.hpp
  v1_decoder.hpp
  v1_encoder.hpp
  v2_decoder.hpp
  v2_encoder.hpp
  v2_protocol.hpp
  vmci.hpp
  vmci_address.hpp
  vmci_connecter.hpp
  vmci_listener.hpp
  windows.hpp
  wire.hpp
  xpub.hpp
  xsub.hpp
  ypipe.hpp
  ypipe_base.hpp
  ypipe_conflate.hpp
  yqueue.hpp
  zap_client.hpp
)

if(MINGW)
Matt Arsenault's avatar
Matt Arsenault committed
949
  # Generate the right type when using -m32 or -m64
950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986
  macro(set_rc_arch rc_target)
    set(CMAKE_RC_COMPILER_INIT windres)
    enable_language(RC)
    set(CMAKE_RC_COMPILE_OBJECT
      "<CMAKE_RC_COMPILER> <FLAGS> -O coff --target=${rc_target} <DEFINES> -i <SOURCE> -o <OBJECT>")
  endmacro()

  if(NOT CMAKE_SYSTEM_PROCESSOR)
    set(CMAKE_SYSTEM_PROCESSOR ${CMAKE_HOST_SYSTEM_PROCESSOR})
  endif()

  # Also happens on x86_64 systems...what a worthless variable
  if(CMAKE_SYSTEM_PROCESSOR MATCHES "i386"
    OR CMAKE_SYSTEM_PROCESSOR MATCHES "i486"
    OR CMAKE_SYSTEM_PROCESSOR MATCHES "i586"
    OR CMAKE_SYSTEM_PROCESSOR MATCHES "i686"
    OR CMAKE_SYSTEM_PROCESSOR MATCHES "x86"
    OR CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64"
    OR CMAKE_SYSTEM_PROCESSOR MATCHES "amd64")

    if(CMAKE_SIZEOF_VOID_P EQUAL 8)
      set_rc_arch("pe-x86-64")
    else()
      set_rc_arch("pe-i386")
    endif()
  endif()
endif()

set(public_headers
  include/zmq.h
  include/zmq_utils.h)

set(readme-docs
  AUTHORS
  COPYING
  COPYING.LESSER
  NEWS)
987 988 989 990

#-----------------------------------------------------------------------------
# optional modules

991 992 993 994 995 996
if(WITH_OPENPGM)
  add_definitions(-DZMQ_HAVE_OPENPGM)
  include_directories(${OPENPGM_INCLUDE_DIRS})
  link_directories(${OPENPGM_LIBRARY_DIRS})
  set(OPTIONAL_LIBRARIES ${OPENPGM_LIBRARIES})
endif()
997

998 999 1000 1001 1002
if(WITH_VMCI)
  add_definitions(-DZMQ_HAVE_VMCI)
  include_directories(${VMCI_INCLUDE_DIRS})
  list(APPEND cxx-sources vmci_address.cpp vmci_connecter.cpp vmci_listener.cpp vmci.cpp)
endif()
Ilya Kulakov's avatar
Ilya Kulakov committed
1003

1004 1005 1006 1007
if(ZMQ_HAVE_TIPC)
  add_definitions(-DZMQ_HAVE_TIPC)
  list(APPEND cxx-sources tipc_address.cpp tipc_connecter.cpp tipc_listener.cpp)
endif()
1008

1009 1010 1011
#-----------------------------------------------------------------------------
# source generators

1012 1013 1014
foreach(source ${cxx-sources})
  list(APPEND sources ${CMAKE_CURRENT_SOURCE_DIR}/src/${source})
endforeach()
1015

1016
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/version.rc.in ${CMAKE_CURRENT_BINARY_DIR}/version.rc)
Frank's avatar
Frank committed
1017

1018
#   Delete any src/platform.hpp left by configure
1019
file(REMOVE ${CMAKE_CURRENT_SOURCE_DIR}/src/platform.hpp)
1020

1021 1022
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/builds/cmake/platform.hpp.in ${CMAKE_CURRENT_BINARY_DIR}/platform.hpp)
list(APPEND sources ${CMAKE_CURRENT_BINARY_DIR}/platform.hpp)
1023

1024 1025 1026 1027 1028 1029
set(prefix ${CMAKE_INSTALL_PREFIX})
set(exec_prefix ${prefix})
set(libdir ${prefix}/lib)
set(includedir ${prefix}/include)
set(VERSION ${ZMQ_VERSION_MAJOR}.${ZMQ_VERSION_MINOR}.${ZMQ_VERSION_PATCH})
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/libzmq.pc.in ${CMAKE_CURRENT_BINARY_DIR}/libzmq.pc @ONLY)
1030
set(zmq-pkgconfig ${CMAKE_CURRENT_BINARY_DIR}/libzmq.pc)
1031

1032 1033 1034
if(NOT ZMQ_BUILD_FRAMEWORK)
  install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libzmq.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
endif()
1035

1036 1037 1038 1039 1040 1041
if(MSVC)
  if(CMAKE_CL_64)
    set(nsis-template ${CMAKE_CURRENT_SOURCE_DIR}/builds/cmake/NSIS.template64.in)
  else()
    set(nsis-template ${CMAKE_CURRENT_SOURCE_DIR}/builds/cmake/NSIS.template32.in)
  endif()
1042

1043
  add_custom_command(
Matt Arsenault's avatar
Matt Arsenault committed
1044 1045 1046 1047 1048 1049 1050
    OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/NSIS.template.in
    COMMAND ${CMAKE_COMMAND}
    ARGS -E
    copy
    ${nsis-template}
    ${CMAKE_CURRENT_BINARY_DIR}/NSIS.template.in
    DEPENDS ${nsis-template})
1051 1052
endif()

1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078
option (WITH_DOCS "Build html docs" ON)
if (WITH_DOCS)
  file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/doc)
  file(GLOB docs RELATIVE ${CMAKE_CURRENT_BINARY_DIR}/ "${CMAKE_CURRENT_SOURCE_DIR}/doc/*.txt")
  set(html-docs)
  foreach(txt ${docs})
    string(REGEX REPLACE ".*/(.*)\\.txt" "\\1.html" html ${txt})
    set(src ${txt})
    set(dst doc/${html})
    if(WITH_DOC)
      add_custom_command(
        OUTPUT  ${dst}
        COMMAND ${ASCIIDOC_EXECUTABLE}
        -d manpage
        -b xhtml11
        -f ${CMAKE_CURRENT_SOURCE_DIR}/doc/asciidoc.conf
        -azmq_version=${ZMQ_VERSION}
        -o ${dst}
        ${src}
        DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${src}
        WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
        COMMENT "Generating ${html}")
      list(APPEND html-docs ${CMAKE_CURRENT_BINARY_DIR}/${dst})
    endif()
  endforeach()
endif()
1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094

if(ZMQ_BUILD_FRAMEWORK)
  add_custom_command(
  TARGET libzmq
  POST_BUILD
  COMMAND ${CMAKE_COMMAND}
  ARGS -E make_directory "${CMAKE_LIBRARY_OUTPUT_PATH}/ZeroMQ.framework/Versions/${ZMQ_VERSION}/MacOS"
  COMMENT "Perf tools")
endif()

if(MSVC)
  # default for all sources is to use precompiled headers
  foreach(source ${sources})
    # C and C++ can not use the same precompiled header
    if(${soruce} MATCHES ".cpp$" AND NOT ${source} STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}/src/precompiled.cpp")
      set_source_files_properties(${source}
1095
        PROPERTIES
1096 1097 1098 1099 1100 1101 1102 1103 1104 1105
        COMPILE_FLAGS "/Yuprecompiled.hpp"
        OBJECT_DEPENDS precompiled.hpp)
    endif()
  endforeach()
  # create precompiled header
  set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/src/precompiled.cpp
    PROPERTIES
    COMPILE_FLAGS "/Ycprecompiled.hpp"
    OBJECT_OUTPUTS precompiled.hpp)
endif()
1106

1107 1108 1109

#-----------------------------------------------------------------------------
# output
1110 1111 1112 1113 1114
option(BUILD_SHARED "Whether or not to build the shared object"  ON)
option(BUILD_STATIC "Whether or not to build the static archive" ON)

list(APPEND target_outputs "")

1115
if(BUILD_SHARED)
1116
  list(APPEND target_outputs "libzmq")
1117 1118
endif()

1119
if(BUILD_STATIC)
1120
  list(APPEND target_outputs "libzmq-static")
1121
endif()
1122

1123
if(MSVC)
1124 1125
  # Suppress linker warnings caused by #ifdef omission
  # of file content.
1126
  set(CMAKE_STATIC_LINKER_FLAGS "${CMAKE_STATIC_LINKER_FLAGS} /ignore:4221")
1127 1128
  set(PDB_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin")
  set(PDB_NAME "libzmq${MSVC_TOOLSET}-mt-gd-${ZMQ_VERSION_MAJOR}_${ZMQ_VERSION_MINOR}_${ZMQ_VERSION_PATCH}")
1129 1130
  function(enable_vs_guideline_checker target)
    set_target_properties(${target} PROPERTIES
1131 1132 1133
      VS_GLOBAL_EnableCppCoreCheck true
      VS_GLOBAL_CodeAnalysisRuleSet CppCoreCheckRules.ruleset
      VS_GLOBAL_RunCodeAnalysis true)
1134
  endfunction()
1135 1136
  if(BUILD_SHARED)
    add_library(libzmq SHARED ${sources} ${public_headers} ${html-docs} ${readme-docs} ${CMAKE_CURRENT_BINARY_DIR}/NSIS.template.in ${CMAKE_CURRENT_BINARY_DIR}/version.rc)
1137
    if(ENABLE_ANALYSIS)
1138
      enable_vs_guideline_checker(libzmq)
1139
    endif()
1140
    set_target_properties(libzmq PROPERTIES
1141 1142 1143
      PUBLIC_HEADER "${public_headers}"
      RELEASE_POSTFIX "${MSVC_TOOLSET}-mt-${ZMQ_VERSION_MAJOR}_${ZMQ_VERSION_MINOR}_${ZMQ_VERSION_PATCH}"
      RELWITHDEBINFO_POSTFIX "${MSVC_TOOLSET}-mt-${ZMQ_VERSION_MAJOR}_${ZMQ_VERSION_MINOR}_${ZMQ_VERSION_PATCH}"
1144
      MINSIZEREL_POSTFIX "${MSVC_TOOLSET}-mt-${ZMQ_VERSION_MAJOR}_${ZMQ_VERSION_MINOR}_${ZMQ_VERSION_PATCH}"
1145
      DEBUG_POSTFIX "${MSVC_TOOLSET}-mt-gd-${ZMQ_VERSION_MAJOR}_${ZMQ_VERSION_MINOR}_${ZMQ_VERSION_PATCH}"
1146
      RUNTIME_OUTPUT_DIRECTORY "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}"
1147 1148 1149
      COMPILE_DEFINITIONS "DLL_EXPORT"
      OUTPUT_NAME "libzmq")
  endif()
1150

1151 1152 1153
  if(BUILD_STATIC)
    add_library(libzmq-static STATIC ${sources} ${CMAKE_CURRENT_BINARY_DIR}/version.rc)
    set_target_properties(libzmq-static PROPERTIES
1154 1155 1156
      PUBLIC_HEADER "${public_headers}"
      RELEASE_POSTFIX "${MSVC_TOOLSET}-mt-s-${ZMQ_VERSION_MAJOR}_${ZMQ_VERSION_MINOR}_${ZMQ_VERSION_PATCH}"
      RELWITHDEBINFO_POSTFIX "${MSVC_TOOLSET}-mt-s-${ZMQ_VERSION_MAJOR}_${ZMQ_VERSION_MINOR}_${ZMQ_VERSION_PATCH}"
1157
      MINSIZEREL_POSTFIX "${MSVC_TOOLSET}-mt-s-${ZMQ_VERSION_MAJOR}_${ZMQ_VERSION_MINOR}_${ZMQ_VERSION_PATCH}"
1158 1159 1160 1161
      DEBUG_POSTFIX "${MSVC_TOOLSET}-mt-sgd-${ZMQ_VERSION_MAJOR}_${ZMQ_VERSION_MINOR}_${ZMQ_VERSION_PATCH}"
      COMPILE_FLAGS "/DZMQ_STATIC"
      OUTPUT_NAME "libzmq")
  endif()
1162
else()
1163 1164
  # avoid building everything twice for shared + static
  # only on *nix, as Windows needs different preprocessor defines in static builds
1165 1166
  if(NOT MINGW)
    add_library(objects OBJECT ${sources})
1167
    set_property(TARGET objects PROPERTY POSITION_INDEPENDENT_CODE ON)
1168
    target_include_directories(objects
1169
      PUBLIC
1170 1171 1172
      $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
      $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
      $<INSTALL_INTERFACE:include>)
1173 1174
  endif()

1175 1176 1177 1178 1179 1180 1181 1182 1183
  if(BUILD_SHARED)
    if(MINGW)
      add_library(libzmq SHARED ${sources} ${public_headers} ${html-docs} ${readme-docs} ${zmq-pkgconfig} ${CMAKE_CURRENT_BINARY_DIR}/version.rc)
    else()
      add_library(libzmq SHARED $<TARGET_OBJECTS:objects> ${public_headers} ${html-docs} ${readme-docs} ${zmq-pkgconfig} ${CMAKE_CURRENT_BINARY_DIR}/version.rc)
    endif()
    # NOTE: the SOVERSION and VERSION MUST be the same as the one generated by libtool! It is NOT the same as the version of the package.
    set_target_properties(libzmq PROPERTIES
      COMPILE_DEFINITIONS "DLL_EXPORT"
1184
      PUBLIC_HEADER "${public_headers}"
1185
      VERSION "5.2.2"
1186
      SOVERSION "5"
Yann Diorcet's avatar
Yann Diorcet committed
1187 1188
      OUTPUT_NAME "zmq"
      PREFIX "lib")
1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201
    if(ZMQ_BUILD_FRAMEWORK)
      set_target_properties(libzmq PROPERTIES
        FRAMEWORK TRUE
        MACOSX_FRAMEWORK_IDENTIFIER "org.zeromq.libzmq"
        MACOSX_FRAMEWORK_SHORT_VERSION_STRING ${ZMQ_VERSION}
        MACOSX_FRAMEWORK_BUNDLE_VERSION ${ZMQ_VERSION})
      set_source_files_properties(${html-docs} PROPERTIES
        MACOSX_PACKAGE_LOCATION doc)
      set_source_files_properties(${readme-docs} PROPERTIES
        MACOSX_PACKAGE_LOCATION etc)
      set_source_files_properties(${zmq-pkgconfig} PROPERTIES
        MACOSX_PACKAGE_LOCATION lib/pkgconfig)
    endif()
1202
  endif()
1203

1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217
  if(BUILD_STATIC)
    if(MINGW)
      add_library(libzmq-static STATIC ${sources} ${public_headers} ${html-docs}
        ${readme-docs} ${zmq-pkgconfig} ${CMAKE_CURRENT_BINARY_DIR}/version.rc)
    else()
      add_library(libzmq-static STATIC $<TARGET_OBJECTS:objects> ${public_headers}
        ${html-docs} ${readme-docs} ${zmq-pkgconfig} ${CMAKE_CURRENT_BINARY_DIR}/version.rc)
    endif()
    set_target_properties(libzmq-static PROPERTIES
      PUBLIC_HEADER "${public_headers}"
      OUTPUT_NAME "zmq"
      PREFIX "lib")
  endif()
endif()
1218

1219
if(BUILD_STATIC)
1220
  target_compile_definitions(libzmq-static
1221 1222
    PUBLIC ZMQ_STATIC)
endif()
1223

1224 1225
foreach(target ${target_outputs})
  target_include_directories(${target}
1226 1227 1228
    PUBLIC
      $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
      $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
1229
      $<INSTALL_INTERFACE:include>)
1230 1231
endforeach()

1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266
if(BUILD_SHARED)
  target_link_libraries(libzmq ${OPTIONAL_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})

  if(SODIUM_FOUND)
    target_link_libraries(libzmq ${SODIUM_LIBRARIES})
    # On Solaris, libsodium depends on libssp
    if(${CMAKE_SYSTEM_NAME} MATCHES "SunOS")
      target_link_libraries(libzmq ssp)
    endif()
  endif()

  if(HAVE_WS2_32)
    target_link_libraries(libzmq ws2_32)
  elseif(HAVE_WS2)
    target_link_libraries(libzmq ws2)
  endif()

  if(HAVE_RPCRT4)
    target_link_libraries(libzmq rpcrt4)
  endif()

  if(HAVE_IPHLAPI)
    target_link_libraries(libzmq iphlpapi)
  endif()

  if(RT_LIBRARY)
    target_link_libraries(libzmq -lrt)
  endif()
endif()

if(BUILD_STATIC)
  target_link_libraries(libzmq-static ${OPTIONAL_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})

  if(SODIUM_FOUND)
    target_link_libraries(libzmq-static ${SODIUM_LIBRARIES})
1267
    # On Solaris, libsodium depends on libssp
1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298
    if(${CMAKE_SYSTEM_NAME} MATCHES "SunOS")
      target_link_libraries(libzmq-static ssp)
    endif()
  endif()

  if(HAVE_WS2_32)
    target_link_libraries(libzmq-static ws2_32)
  elseif(HAVE_WS2)
    target_link_libraries(libzmq-static ws2)
  endif()

  if(HAVE_RPCRT4)
    target_link_libraries(libzmq-static rpcrt4)
  endif()

  if(HAVE_IPHLAPI)
    target_link_libraries(libzmq-static iphlpapi)
  endif()

  if(RT_LIBRARY)
    target_link_libraries(libzmq-static -lrt)
  endif()
endif()

if(BUILD_SHARED)
  set(perf-tools
    local_lat
    remote_lat
    local_thr
    remote_thr
    inproc_lat
1299 1300
    inproc_thr
    proxy_thr)
1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313

  if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug") # Why?
    option(WITH_PERF_TOOL "Build with perf-tools" ON)
  else()
    option(WITH_PERF_TOOL "Build with perf-tools" OFF)
  endif()

  if(WITH_PERF_TOOL)
    foreach(perf-tool ${perf-tools})
      add_executable(${perf-tool} perf/${perf-tool}.cpp)
      target_link_libraries(${perf-tool} libzmq)

      if(ZMQ_BUILD_FRAMEWORK)
1314
        # Copy perf-tools binaries into Framework
1315
        add_custom_command(
1316
          TARGET libzmq ${perf-tool}
1317 1318 1319 1320 1321
          POST_BUILD
          COMMAND ${CMAKE_COMMAND}
          ARGS -E copy "$<TARGET_FILE:${perf-tool}>" "${LIBRARY_OUTPUT_PATH}/ZeroMQ.framework/Versions/${ZMQ_VERSION_STRING}/MacOS/${perf-tool}"
          VERBATIM
          COMMENT "Perf tools")
1322 1323 1324 1325 1326 1327
      else()
        install(TARGETS ${perf-tool}
          RUNTIME DESTINATION bin
          COMPONENT PerfTools)
      endif()
    endforeach()
1328 1329 1330 1331 1332 1333

    if(BUILD_STATIC)
      add_executable(benchmark_radix_tree perf/benchmark_radix_tree.cpp)
      target_link_libraries(benchmark_radix_tree libzmq-static)
      target_include_directories(benchmark_radix_tree
        PUBLIC
1334
        "${CMAKE_CURRENT_LIST_DIR}/src")
1335 1336
    endif()

1337 1338
  endif()
elseif(WITH_PERF_TOOL)
1339
  message(FATAL_ERROR "Shared library disabled - perf-tools unavailable.")
1340
endif()
1341

1342 1343 1344
#-----------------------------------------------------------------------------
# tests

1345 1346
option(BUILD_TESTS "Whether or not to build the tests" ON)

1347
set(ZMQ_BUILD_TESTS ${BUILD_TESTS} CACHE BOOL "Build the tests for ZeroMQ")
1348

1349 1350 1351 1352 1353 1354 1355 1356 1357
if(ZMQ_BUILD_TESTS)
  enable_testing() # Enable testing only works in root scope
  add_subdirectory(tests)
  if(BUILD_STATIC)
    add_subdirectory(unittests)
  else()
    message(WARNING "Not building unit tests, since BUILD_STATIC is not enabled")
  endif()
endif()
1358

1359 1360
#-----------------------------------------------------------------------------
# installer
1361

1362 1363 1364 1365 1366 1367 1368 1369 1370 1371
if(MSVC AND(BUILD_SHARED OR BUILD_STATIC))
  install(TARGETS ${target_outputs}
    EXPORT ${PROJECT_NAME}-targets
    ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
    PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
    COMPONENT SDK)
  if(MSVC_IDE)
    install(FILES ${PDB_OUTPUT_DIRECTORY}/\${CMAKE_INSTALL_CONFIG_NAME}/${PDB_NAME}.pdb DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT SDK OPTIONAL)
1372
  else()
1373 1374 1375 1376 1377 1378 1379
    install(FILES ${PDB_OUTPUT_DIRECTORY}/${PDB_NAME}.pdb DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT SDK OPTIONAL)
  endif()
  if(BUILD_SHARED)
    install(TARGETS libzmq
      RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
      PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
      COMPONENT Runtime)
1380
  endif()
1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413
elseif(BUILD_SHARED OR BUILD_STATIC)
  install(TARGETS ${target_outputs}
    EXPORT ${PROJECT_NAME}-targets
    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
    ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
    FRAMEWORK DESTINATION "Library/Frameworks"
    PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
endif()

# install(FILES ${public_headers}
#   DESTINATION include
#   COMPONENT SDK)

#if(NOT ZMQ_BUILD_FRAMEWORK)
#  file(GLOB private_headers "${CMAKE_CURRENT_SOURCE_DIR}/src/*.hpp")
#  install(FILES ${sources} ${private_headers} DESTINATION src/zmq
#    COMPONENT SourceCode)
#endif()

foreach(readme ${readme-docs})
  configure_file(${CMAKE_CURRENT_SOURCE_DIR}/${readme} ${CMAKE_CURRENT_BINARY_DIR}/${readme}.txt)

  if(NOT ZMQ_BUILD_FRAMEWORK)
    install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${readme}.txt DESTINATION share/zmq)
  endif()
endforeach()

if(WITH_DOC)
  if(NOT ZMQ_BUILD_FRAMEWORK)
    install(FILES ${html-docs} DESTINATION doc/zmq COMPONENT RefGuide)
  endif()
endif()
1414

1415 1416
include(CMakePackageConfigHelpers)

1417
if(WIN32)
1418 1419 1420 1421 1422
  set(ZEROMQ_CMAKECONFIG_INSTALL_DIR "CMake" CACHE STRING "install path for ZeroMQConfig.cmake")
else()
  # GNUInstallDirs "DATADIR" wrong here; CMake search path wants "share".
  set(ZEROMQ_CMAKECONFIG_INSTALL_DIR "share/cmake/${PROJECT_NAME}" CACHE STRING "install path for ZeroMQConfig.cmake")
endif()
1423

1424
if((NOT CMAKE_VERSION VERSION_LESS 3.0) AND (BUILD_SHARED OR BUILD_STATIC))
1425
  export(EXPORT ${PROJECT_NAME}-targets
1426
    FILE "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Targets.cmake")
1427
endif()
1428
configure_package_config_file(builds/cmake/${PROJECT_NAME}Config.cmake.in
1429 1430
  "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
  INSTALL_DESTINATION ${ZEROMQ_CMAKECONFIG_INSTALL_DIR})
1431
write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
1432 1433 1434
  VERSION ${ZMQ_VERSION_MAJOR}.${ZMQ_VERSION_MINOR}.${ZMQ_VERSION_PATCH}
  COMPATIBILITY AnyNewerVersion)
if(BUILD_SHARED OR BUILD_STATIC)
1435
  install(EXPORT ${PROJECT_NAME}-targets
1436 1437
    FILE ${PROJECT_NAME}Targets.cmake
    DESTINATION ${ZEROMQ_CMAKECONFIG_INSTALL_DIR})
1438
  install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
1439 1440
    ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
    DESTINATION ${ZEROMQ_CMAKECONFIG_INSTALL_DIR})
1441
endif()
1442

1443
option(ENABLE_CPACK "Enables cpack rules" ON)
1444 1445
if(MSVC AND ENABLE_CPACK)
  include(InstallRequiredSystemLibraries)
1446

1447 1448 1449 1450 1451
  if(CMAKE_CL_64)
    set(arch_name "x64")
  else()
    set(arch_name "x86")
  endif()
1452

1453 1454
  set(CPACK_NSIS_DISPLAY_NAME "ZeroMQ ${ZMQ_VERSION_MAJOR}.${ZMQ_VERSION_MINOR}.${ZMQ_VERSION_PATCH}(${arch_name})")
  set(CPACK_PACKAGE_FILE_NAME "ZeroMQ-${ZMQ_VERSION_MAJOR}.${ZMQ_VERSION_MINOR}.${ZMQ_VERSION_PATCH}-${arch_name}")
1455 1456 1457 1458

  # TODO: I think this part was intended to be used when running cpack
  # separately from cmake but I don't know how that works.
  #
1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483
  # macro(add_crt_version version)
  #   set(rel_dir "${CMAKE_CURRENT_BINARY_DIR}/build/${arch_name}/${version};ZeroMQ;ALL;/")
  #   set(debug_dir "${CMAKE_CURRENT_BINARY_DIR}/debug/${arch_name}/${version};ZeroMQ;ALL;/")
  #   if(EXISTS ${rel_dir})
  #     list(APPEND CPACK_INSTALL_CMAKE_PROJECTS ${rel_dir})
  #   endif()

  #   if(EXISTS ${debug_dir})
  #     list(APPEND CPACK_INSTALL_CMAKE_PROJECTS ${rel_dir})
  #   endmacro()
  # endmacro()

  # add_crt_version(v110)
  # add_crt_version(v100)
  # add_crt_version(v90)

  list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_BINARY_DIR})
  set(CPACK_GENERATOR "NSIS")
  set(CPACK_PACKAGE_NAME "ZeroMQ")
  set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "ZeroMQ lightweight messaging kernel")
  set(CPACK_PACKAGE_VENDOR "Miru")
  set(CPACK_NSIS_CONTACT "Steven McCoy <Steven.McCoy@miru.hk>")
  set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_BINARY_DIR}\\\\COPYING.txt")
  # set(CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_BINARY_DIR}\\\\README.txt")
  # set(CPACK_RESOURCE_FILE_WELCOME "${CMAKE_CURRENT_BINARY_DIR}\\\\WELCOME.txt")
1484
  # There is a bug in NSI that does not handle full unix paths properly. Make
1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500
  # sure there is at least one set of four(4) backslashes.
  set(CPACK_NSIS_MUI_ICON "${CMAKE_CURRENT_SOURCE_DIR}\\\\installer.ico")
  set(CPACK_NSIS_MUI_UNIICON "${CMAKE_CURRENT_SOURCE_DIR}\\\\installer.ico")

  set(CPACK_PACKAGE_ICON "${CMAKE_CURRENT_SOURCE_DIR}\\\\branding.bmp")
  set(CPACK_NSIS_COMPRESSOR "/SOLID lzma")
  set(CPACK_PACKAGE_VERSION ${ZMQ_VERSION})
  set(CPACK_PACKAGE_VERSION_MAJOR ${ZMQ_VERSION_MAJOR})
  set(CPACK_PACKAGE_VERSION_MINOR ${ZMQ_VERSION_MINOR})
  set(CPACK_PACKAGE_VERSION_PATCH ${ZMQ_VERSION_PATCH})
  # set(CPACK_PACKAGE_INSTALL_DIRECTORY "ZMQ Install Directory")
  # set(CPACK_TEMPORARY_DIRECTORY "ZMQ Temporary CPack Directory")

  include(CPack)

  cpack_add_component_group(Development
1501 1502
    DISPLAY_NAME "ZeroMQ software development kit"
    EXPANDED)
1503
  cpack_add_component(PerfTools
1504 1505
    DISPLAY_NAME "ZeroMQ performance tools"
    INSTALL_TYPES FullInstall DevInstall)
1506
  cpack_add_component(SourceCode
1507 1508 1509
    DISPLAY_NAME "ZeroMQ source code"
    DISABLED
    INSTALL_TYPES FullInstall)
1510
  cpack_add_component(SDK
1511 1512 1513
    DISPLAY_NAME "ZeroMQ headers and libraries"
    INSTALL_TYPES FullInstall DevInstall
    GROUP Development)
1514 1515
  if(WITH_DOC)
    cpack_add_component(RefGuide
1516 1517 1518
      DISPLAY_NAME "ZeroMQ reference guide"
      INSTALL_TYPES FullInstall DevInstall
      GROUP Development)
1519 1520
  endif()
  cpack_add_component(Runtime
1521 1522 1523
    DISPLAY_NAME "ZeroMQ runtime files"
    REQUIRED
    INSTALL_TYPES FullInstall DevInstall MinInstall)
1524
    cpack_add_install_type(FullInstall
1525
    DISPLAY_NAME "Full install, including source code")
1526
    cpack_add_install_type(DevInstall
1527
    DISPLAY_NAME "Developer install, headers and libraries")
1528
    cpack_add_install_type(MinInstall
1529
    DISPLAY_NAME "Minimal install, runtime only")
1530
endif()
1531 1532

# Export this for library to help build this as a sub-project
1533
set(ZEROMQ_LIBRARY libzmq CACHE STRING "ZeroMQ library")
1534 1535 1536

# Workaround for MSVS10 to avoid the Dialog Hell
# FIXME: This could be removed with future version of CMake.
1537 1538 1539 1540 1541 1542
if(MSVC_VERSION EQUAL 1600)
  set(ZMQ_SLN_FILENAME "${CMAKE_CURRENT_BINARY_DIR}/ZeroMQ.sln")
  if(EXISTS "${ZMQ_SLN_FILENAME}")
    file(APPEND "${ZMQ_SLN_FILENAME}" "\n# This should be regenerated!\n")
  endif()
endif()
1543 1544

include(ClangFormat)