CMakeLists.txt 28.2 KB
Newer Older
1 2
# CMake build script for ZeroMQ

3 4 5 6 7
cmake_minimum_required (VERSION 2.8.12)
project (ZeroMQ)

list (INSERT CMAKE_MODULE_PATH 0 "${CMAKE_SOURCE_DIR}")

8 9 10 11 12 13 14 15 16 17 18
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=gnu++11" COMPILER_SUPPORTS_CXX11)
if(COMPILER_SUPPORTS_CXX11)
	set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
endif()
include(CheckCCompilerFlag)
CHECK_C_COMPILER_FLAG("-std=gnu11" COMPILER_SUPPORTS_C11)
if(COMPILER_SUPPORTS_C11)
	set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu11")
endif()

19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
option (WITH_OPENPGM "Build with support for OpenPGM" OFF)
option (WITH_VMCI "Build with support for VMware VMCI socket" OFF)

if (APPLE)
    option (ZMQ_BUILD_FRAMEWORK "Build as OS X framework" ON)
endif ()

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

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")

36
elseif (WITH_LIBSODIUM)
37 38 39 40 41 42
    find_package (Sodium)
    if (SODIUM_FOUND)
        message (STATUS "Using libsodium for CURVE security")
        include_directories (${SODIUM_INCLUDE_DIRS})

        # On Solaris, libsodium depends on libssp
43
        if (${CMAKE_SYSTEM_NAME} MATCHES "SunOS")
44 45
            target_link_libraries (libzmq ssp)
        endif ()
46 47
        set (HAVE_LIBSODIUM 1)
        set (ZMQ_HAVE_CURVE 1)
48 49 50 51 52 53 54
    else ()
        message (FATAL_ERROR
            "libsodium is not installed. Install it, then run CMake again")
    endif ()

else ()
    message (STATUS "Using tweetnacl for CURVE security")
55 56 57
    list (APPEND sources ${CMAKE_CURRENT_SOURCE_DIR}/src/tweetnacl.c)
    set (ZMQ_USE_TWEETNACL 1)
    set (ZMQ_HAVE_CURVE 1)
58 59 60
endif ()

set (POLLER "" CACHE STRING "Choose polling system. valid values are
61 62
                            kqueue, epoll, devpoll, poll or select [default=autodetect]")

63 64 65 66 67 68 69 70 71
include (CheckFunctionExists)
include (CheckTypeSize)

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")
72
    endif()
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
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")
    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 poll.h)
    check_function_exists (poll HAVE_POLL)
    set (CMAKE_REQUIRED_INCLUDES)
    if (HAVE_POLL)
        set (POLLER "poll")
    endif ()
endif ()
101

102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
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 ()
118

119 120 121 122 123 124 125 126 127 128 129
if (POLLER STREQUAL "kqueue"
 OR POLLER STREQUAL "epoll"
 OR POLLER STREQUAL "devpoll"
 OR POLLER STREQUAL "poll"
 OR POLLER STREQUAL "select")
    message (STATUS "Detected ${POLLER} polling method")
    string (TOUPPER ${POLLER} UPPER_POLLER)
    set (ZMQ_USE_${UPPER_POLLER} 1)
else ()
    message (FATAL_ERROR "Invalid polling method")
endif ()
130

131 132
set (ZMQ_CMAKE_MODULES_DIR ${CMAKE_CURRENT_SOURCE_DIR}/builds/cmake/Modules)
list (APPEND CMAKE_MODULE_PATH ${ZMQ_CMAKE_MODULES_DIR})
133

134 135 136 137 138 139 140 141 142 143
include (TestZMQVersion)
include (ZMQSourceRunChecks)
include (CheckIncludeFiles)
include (CheckLibraryExists)
include (CheckCCompilerFlag)
include (CheckCXXCompilerFlag)
include (CheckCSourceCompiles)
include (CheckCSourceRuns)
include (CMakeDependentOption)
include (CheckCXXSymbolExists)
144

145 146 147 148
check_include_files (ifaddrs.h ZMQ_HAVE_IFADDRS)
check_include_files (windows.h ZMQ_HAVE_WINDOWS)
check_include_files (sys/uio.h ZMQ_HAVE_UIO)
check_include_files (sys/eventfd.h ZMQ_HAVE_EVENTFD)
149

150 151 152 153
check_library_exists (ws2_32 fopen "" HAVE_WS2_32) # TODO: Why doesn't something logical like WSAStartup work?
check_library_exists (ws2 fopen "" HAVE_WS2)
check_library_exists (rpcrt4 fopen "" HAVE_RPCRT4) # UuidCreateSequential
check_library_exists (iphlpapi fopen "" HAVE_IPHLAPI) # GetAdaptersAddresses
154

155 156
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)
157

158
find_library (RT_LIBRARY rt)
159

160
find_package (Threads)
Matt Arsenault's avatar
Matt Arsenault committed
161

162

163 164 165 166 167 168 169 170
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 ()

  if (NOT HAVE_RPCRT4)
    message (FATAL_ERROR "Cannot link to rpcrt4")
  endif ()
171

172 173 174 175
  if (NOT HAVE_IPHLAPI)
    message (FATAL_ERROR "Cannot link to iphlapi")
  endif ()
endif ()
176

177 178 179
set (CMAKE_REQUIRED_LIBRARIES rt)
check_function_exists (clock_gettime HAVE_CLOCK_GETTIME)
set (CMAKE_REQUIRED_LIBRARIES)
180

181 182 183
set (CMAKE_REQUIRED_INCLUDES unistd.h)
check_function_exists (fork HAVE_FORK)
set (CMAKE_REQUIRED_INCLUDES)
Frank's avatar
Frank committed
184

185 186 187
set (CMAKE_REQUIRED_INCLUDES sys/time.h)
check_function_exists (gethrtime HAVE_GETHRTIME)
set (CMAKE_REQUIRED_INCLUDES)
188

189
add_definitions (-D_REENTRANT -D_THREAD_SAFE)
190
add_definitions (-DZMQ_CUSTOM_PLATFORM_HPP)
191

192
option (ENABLE_EVENTFD "Enable/disable eventfd" ZMQ_HAVE_EVENTFD)
193

194 195
macro (zmq_check_cxx_flag_prepend flag)
  check_cxx_compiler_flag ("${flag}" HAVE_FLAG_${flag})
196

197 198 199 200
  if (HAVE_FLAG_${flag})
    set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}")
  endif ()
endmacro ()
201 202


203 204
if (MSVC)
  zmq_check_cxx_flag_prepend ("/W3")
205

206 207 208 209 210 211 212 213
  if (MSVC_IDE)
    set (MSVC_TOOLSET "-${CMAKE_VS_PLATFORM_TOOLSET}")
  else ()
    set (MSVC_TOOLSET "")
  endif ()
else ()
  zmq_check_cxx_flag_prepend ("-Wall")
endif ()
214

215 216 217
if (CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  zmq_check_cxx_flag_prepend ("-Wextra")
endif ()
218

219 220 221
#   TODO: why is -Wno-long-long defined differently than in configure.ac?
zmq_check_cxx_flag_prepend ("-Wno-long-long")
zmq_check_cxx_flag_prepend ("-Wno-uninitialized")
222

223 224
option (LIBZMQ_PEDANTIC "" ON)
option (LIBZMQ_WERROR "" OFF)
225

226 227
if (LIBZMQ_PEDANTIC)
  zmq_check_cxx_flag_prepend ("-pedantic")
228

229 230 231
  if (${CMAKE_CXX_COMPILER_ID} MATCHES "Intel")
    zmq_check_cxx_flag_prepend ("-strict-ansi")
  endif ()
232

233 234 235 236
  if (${CMAKE_CXX_COMPILER_ID} MATCHES "SunPro")
    zmq_check_cxx_flag_prepend ("-compat=5")
  endif ()
endif ()
237

238 239 240 241
if (LIBZMQ_WERROR)
  zmq_check_cxx_flag_prepend ("-Werror")
  zmq_check_cxx_flag_prepend ("-errwarn=%all")
endif ()
242 243


244 245 246
if (CMAKE_SYSTEM_PROCESSOR MATCHES "^sparc")
  zmq_check_cxx_flag_prepend ("-mcpu=v9")
endif ()
247

248 249 250
if (${CMAKE_CXX_COMPILER_ID} MATCHES "SunPro")
  zmq_check_cxx_flag_prepend ("-features=zla")
endif ()
251

252

253 254 255
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 (
256 257 258
  "
   #include <atomic.h>

259
    int main ()
260 261
    {
      uint32_t value;
262
      atomic_cas_32 (&value, 0, 0);
263 264 265 266 267
      return 0;
    }
    "
    HAVE_ATOMIC_H)

268 269 270 271
  if (NOT HAVE_ATOMIC_H)
    set (ZMQ_FORCE_MUTEXES 1)
  endif ()
endif ()
272 273 274


#-----------------------------------------------------------------------------
275 276 277 278 279 280
zmq_check_sock_cloexec ()
zmq_check_so_keepalive ()
zmq_check_tcp_keepcnt ()
zmq_check_tcp_keepidle ()
zmq_check_tcp_keepintvl ()
zmq_check_tcp_keepalive ()
281 282


283
if (    CMAKE_SYSTEM_NAME MATCHES "Linux"
284 285 286
    OR CMAKE_SYSTEM_NAME MATCHES "GNU/kFreeBSD"
    OR CMAKE_SYSTEM_NAME MATCHES "GNU/Hurd"
    OR CYGWIN)
287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307
  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 ()

set (CMAKE_PYTHON_VERSION 2.7 2.6 2.5 2.4)
find_package (PythonInterp)
find_package (AsciiDoc)

cmake_dependent_option (WITH_DOC "Build Reference Guide documentation (requires DocBook)" ON
308 309
                       "PYTHON_FOUND;ASCIIDOC_FOUND" OFF)

310 311 312 313 314 315 316 317
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
318 319 320
                PATHS
                "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Miru\\OpenPGM ${OPENPGM_VERSION_MAJOR}.${OPENPGM_VERSION_MINOR}.${OPENPGM_VERSION_MICRO}]"
                NO_DEFAULT_PATH
321 322 323 324
               )
      message (STATUS "OpenPGM x64 detected - ${OPENPGM_ROOT}")
    else ()
      find_path (OPENPGM_ROOT include/pgm/pgm.h
325 326 327 328
                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
329 330 331 332 333 334
               )
      message (STATUS "OpenPGM x86 detected - ${OPENPGM_ROOT}")
    endif (CMAKE_CL_64)
    set (OPENPGM_INCLUDE_DIRS ${OPENPGM_ROOT}/include)
    set (OPENPGM_LIBRARY_DIRS ${OPENPGM_ROOT}/lib)
    set (OPENPGM_LIBRARIES
335 336
      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)
337 338 339 340
  endif ()
else ()
  if (WITH_OPENPGM)
    message (FATAL_ERROR "WITH_OPENPGM not implemented")
341
    # DSO symbol visibility for openpgm
342
    if (HAVE_FLAG_VISIBILITY_HIDDEN)
343

344 345 346 347
    elseif (HAVE_FLAG_LDSCOPE_HIDDEN)
    endif ()
  endif ()
endif ()
348

349 350 351 352

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

353 354
if (${CMAKE_CURRENT_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_BINARY_DIR})
message (FATAL_ERROR "CMake generation is not allowed within the source directory!
355 356
Remove the CMakeCache.txt file and try again from another folder, e.g.:

357
   rm CMakeCache.txt
358 359 360 361
   mkdir cmake-make
   cd cmake-make
   cmake ..
")
362
endif ()
363 364 365 366

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

367
if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
368 369
  # CMAKE_BUILD_TYPE is not used for multi-configuration generators like Visual Studio/XCode
  # which instead use CMAKE_CONFIGURATION_TYPES
370
  set (CMAKE_BUILD_TYPE Release CACHE STRING
371 372
      "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel."
      FORCE)
373
endif ()
374

375 376
set (EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}/bin)
set (LIBRARY_OUTPUT_PATH  ${CMAKE_CURRENT_BINARY_DIR}/lib)
Doron Somech's avatar
Doron Somech committed
377

378 379 380
#-----------------------------------------------------------------------------
# platform specifics

xantares's avatar
xantares committed
381
if (WIN32)
382 383
    #   Socket limit is 16K (can be raised arbitrarily)
    add_definitions (-DFD_SETSIZE=16384)
384
    add_definitions (-D_CRT_SECURE_NO_WARNINGS)
xantares's avatar
xantares committed
385
endif ()
386

387
if (MSVC)
388
  # Parallel make.
389
  set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
390

391 392
  # Optimization flags.
  # http://msdn.microsoft.com/en-us/magazine/cc301698.aspx
393 394 395 396 397 398 399
  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 ()
400 401


402 403 404
#-----------------------------------------------------------------------------
# source files

405
set (cxx-sources
406
        address.cpp
somdoron's avatar
somdoron committed
407
        client.cpp
408 409
        clock.cpp
        ctx.cpp
410 411
        curve_client.cpp
        curve_server.cpp
412 413 414 415 416 417 418 419 420 421 422 423 424 425 426
        dealer.cpp
        devpoll.cpp
        dist.cpp
        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
427
        mailbox_safe.cpp
428
        mechanism.cpp
Frank's avatar
Frank committed
429
        metadata.cpp
430 431 432 433 434
        msg.cpp
        mtrie.cpp
        object.cpp
        options.cpp
        own.cpp
435
        null_mechanism.cpp
436 437 438 439 440
        pair.cpp
        pgm_receiver.cpp
        pgm_sender.cpp
        pgm_socket.cpp
        pipe.cpp
441 442
        plain_client.cpp
        plain_server.cpp
443 444 445 446 447 448 449 450 451 452 453 454 455 456 457
        poll.cpp
        poller_base.cpp
        precompiled.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
somdoron's avatar
somdoron committed
458
        server.cpp
459 460 461
        session_base.cpp
        signaler.cpp
        socket_base.cpp
Richard Newton's avatar
Richard Newton committed
462 463
        socks.cpp
        socks_connecter.cpp
Richard Newton's avatar
Richard Newton committed
464
        stream.cpp
465 466 467 468 469 470 471 472 473 474
        stream_engine.cpp
        sub.cpp
        tcp.cpp
        tcp_address.cpp
        tcp_connecter.cpp
        tcp_listener.cpp
        thread.cpp
        trie.cpp
        v1_decoder.cpp
        v1_encoder.cpp
475 476
        v2_decoder.cpp
        v2_encoder.cpp
477 478 479
        xpub.cpp
        xsub.cpp
        zmq.cpp
Jens Auer's avatar
Jens Auer committed
480
        zmq_utils.cpp
481
        decoder_allocators.cpp
482
        socket_poller.cpp
somdoron's avatar
somdoron committed
483
        timers.cpp
somdoron's avatar
somdoron committed
484 485
        config.hpp
        radio.cpp
486 487 488
        dish.cpp
        udp_engine.cpp
        udp_address.cpp)
Matt Arsenault's avatar
Matt Arsenault committed
489

490
set (rc-sources version.rc)
Matt Arsenault's avatar
Matt Arsenault committed
491

492
if (MINGW)
Matt Arsenault's avatar
Matt Arsenault committed
493
  # Generate the right type when using -m32 or -m64
494 495 496 497
  macro (set_rc_arch rc_target)
    set (CMAKE_RC_COMPILER_INIT windres)
    enable_language (RC)
    set (CMAKE_RC_COMPILE_OBJECT
Maarten Ditzel's avatar
Maarten Ditzel committed
498
        "<CMAKE_RC_COMPILER> <FLAGS> -O coff --target=${rc_target} <DEFINES> -i <SOURCE> -o <OBJECT>")
499
  endmacro ()
Matt Arsenault's avatar
Matt Arsenault committed
500

501 502
  if (NOT CMAKE_SYSTEM_PROCESSOR)
    set (CMAKE_SYSTEM_PROCESSOR ${CMAKE_HOST_SYSTEM_PROCESSOR})
503 504
  endif ()

505
  if (    CMAKE_SYSTEM_PROCESSOR MATCHES "i386"
506 507 508
      OR CMAKE_SYSTEM_PROCESSOR MATCHES "i486"
      OR CMAKE_SYSTEM_PROCESSOR MATCHES "i586"
      OR CMAKE_SYSTEM_PROCESSOR MATCHES "i686"
Matt Arsenault's avatar
Matt Arsenault committed
509
     # This also happens on x86_64 systems...what a worthless variable
510 511 512
      OR CMAKE_SYSTEM_PROCESSOR MATCHES "x86"
      OR CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64"
      OR CMAKE_SYSTEM_PROCESSOR MATCHES "amd64")
Matt Arsenault's avatar
Matt Arsenault committed
513

514 515 516 517 518 519 520
    if (CMAKE_SIZEOF_VOID_P EQUAL 8)
      set_rc_arch ("pe-x86-64")
    else ()
      set_rc_arch ("pe-i386")
    endif ()
  endif ()
endif ()
Matt Arsenault's avatar
Matt Arsenault committed
521

522
include_directories (include ${CMAKE_CURRENT_BINARY_DIR})
Min RK's avatar
Min RK committed
523 524
set (public_headers include/zmq.h
                    include/zmq_utils.h)
Matt Arsenault's avatar
Matt Arsenault committed
525

526
set (readme-docs AUTHORS
Matt Arsenault's avatar
Matt Arsenault committed
527 528 529
                COPYING
                COPYING.LESSER
                MAINTAINERS
530
                NEWS)
531 532 533 534

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

535 536 537 538 539 540
if (WITH_OPENPGM)
  add_definitions (-DZMQ_HAVE_OPENPGM)
  include_directories (${OPENPGM_INCLUDE_DIRS})
  link_directories (${OPENPGM_LIBRARY_DIRS})
  set (OPTIONAL_LIBRARIES ${OPENPGM_LIBRARIES})
endif (WITH_OPENPGM)
541

542 543 544 545 546
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 (WITH_VMCI)
Ilya Kulakov's avatar
Ilya Kulakov committed
547

548 549 550
#-----------------------------------------------------------------------------
# source generators

551 552 553
foreach (source ${cxx-sources})
  list (APPEND sources ${CMAKE_CURRENT_SOURCE_DIR}/src/${source})
endforeach ()
554

555 556 557 558
foreach (source ${rc-sources})
  list (APPEND sources ${CMAKE_CURRENT_BINARY_DIR}/${source})
  configure_file (${CMAKE_CURRENT_SOURCE_DIR}/src/${source}.in ${CMAKE_CURRENT_BINARY_DIR}/${source})
endforeach ()
Frank's avatar
Frank committed
559

560 561 562
#   Delete any src/platform.hpp left by configure
file (REMOVE ${CMAKE_CURRENT_SOURCE_DIR}/src/platform.hpp)

563 564
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)
565

566 567
configure_file (${CMAKE_CURRENT_SOURCE_DIR}/src/libzmq.pc.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/libzmq.pc @ONLY)
set (zmq-pkgconfig ${CMAKE_CURRENT_BINARY_DIR}/libzmq.pc)
568

569 570 571
if (NOT ZMQ_BUILD_FRAMEWORK)
  install (FILES ${CMAKE_CURRENT_BINARY_DIR}/libzmq.pc DESTINATION lib/pkgconfig)
endif ()
572

573 574 575 576 577 578
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 ()
579

580
  add_custom_command (
Matt Arsenault's avatar
Matt Arsenault committed
581 582 583 584 585 586 587
    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})
588 589 590 591 592 593 594 595 596 597
endif ()

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})
  add_custom_command (
598 599 600 601 602 603
    OUTPUT  ${dst}
    COMMAND ${PYTHON_EXECUTABLE}
    ARGS    -x
    ${ASCIIDOC_EXECUTABLE}
    -d manpage
    -b xhtml11
604 605
    -f ${CMAKE_CURRENT_SOURCE_DIR}/doc/asciidoc.conf
    -azmq_version=${ZMQ_VERSION}
606 607
    -o ${dst}
    ${src}
608 609
    DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${src}
    WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
610
    COMMENT "Generating ${html}")
611 612 613 614
  if (WITH_DOC)
    list (APPEND html-docs ${CMAKE_CURRENT_BINARY_DIR}/${dst})
  endif ()
endforeach ()
615

616 617
if (ZMQ_BUILD_FRAMEWORK)
  add_custom_command (
618 619 620 621 622
    TARGET libzmq
    POST_BUILD
    COMMAND ${CMAKE_COMMAND}
    ARGS -E make_directory "${CMAKE_LIBRARY_OUTPUT_PATH}/ZeroMQ.framework/Versions/${ZMQ_VERSION}/MacOS"
    COMMENT "Perf tools")
623
endif ()
624

625 626 627 628

#-----------------------------------------------------------------------------
# output

629 630 631 632
if (MSVC)
  add_library (libzmq SHARED ${sources} ${public_headers} ${html-docs} ${readme-docs} ${CMAKE_CURRENT_BINARY_DIR}/NSIS.template.in)
  target_link_libraries (libzmq ${OPTIONAL_LIBRARIES})
  set_target_properties (libzmq PROPERTIES
633
    PUBLIC_HEADER "${public_headers}"
634
    RELEASE_POSTFIX "${MSVC_TOOLSET}-mt-${ZMQ_VERSION_MAJOR}_${ZMQ_VERSION_MINOR}_${ZMQ_VERSION_PATCH}"
635
    RELWITHDEBINFO_POSTFIX "${MSVC_TOOLSET}-mt-${ZMQ_VERSION_MAJOR}_${ZMQ_VERSION_MINOR}_${ZMQ_VERSION_PATCH}"
636
    DEBUG_POSTFIX "${MSVC_TOOLSET}-mt-gd-${ZMQ_VERSION_MAJOR}_${ZMQ_VERSION_MINOR}_${ZMQ_VERSION_PATCH}"
637 638
    RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin"
    COMPILE_DEFINITIONS "DLL_EXPORT")
639 640
  add_library (libzmq-static STATIC ${sources})
  set_target_properties (libzmq-static PROPERTIES
641
    PUBLIC_HEADER "${public_headers}"
642
    RELEASE_POSTFIX "${MSVC_TOOLSET}-mt-s-${ZMQ_VERSION_MAJOR}_${ZMQ_VERSION_MINOR}_${ZMQ_VERSION_PATCH}"
643
    RELWITHDEBINFO_POSTFIX "${MSVC_TOOLSET}-mt-s-${ZMQ_VERSION_MAJOR}_${ZMQ_VERSION_MINOR}_${ZMQ_VERSION_PATCH}"
644
    DEBUG_POSTFIX "${MSVC_TOOLSET}-mt-sgd-${ZMQ_VERSION_MAJOR}_${ZMQ_VERSION_MINOR}_${ZMQ_VERSION_PATCH}"
645
    COMPILE_FLAGS "/D ZMQ_STATIC"
646
    OUTPUT_NAME "libzmq-static")
647 648 649
else ()
    add_library (libzmq SHARED ${sources} ${public_headers} ${html-docs} ${readme-docs} ${zmq-pkgconfig})
    set_target_properties (libzmq PROPERTIES
650 651 652
                          COMPILE_DEFINITIONS "DLL_EXPORT"
                          PUBLIC_HEADER "${public_headers}"
                          VERSION ${ZMQ_VERSION}
653
                          SOVERSION "${ZMQ_VERSION_MAJOR}.${ZMQ_VERSION_MINOR}.0"
654 655
                          OUTPUT_NAME "libzmq"
                          PREFIX "")
656 657
    if (ZMQ_BUILD_FRAMEWORK)
      set_target_properties (libzmq PROPERTIES
Doron Somech's avatar
Doron Somech committed
658 659 660
                            FRAMEWORK TRUE
                            MACOSX_FRAMEWORK_IDENTIFIER "org.zeromq.libzmq"
                            MACOSX_FRAMEWORK_SHORT_VERSION_STRING ${ZMQ_VERSION}
661
                            MACOSX_FRAMEWORK_BUNDLE_VERSION ${ZMQ_VERSION})
662
      set_source_files_properties (${html-docs} PROPERTIES
Doron Somech's avatar
Doron Somech committed
663
                                  MACOSX_PACKAGE_LOCATION doc)
664
      set_source_files_properties (${readme-docs} PROPERTIES
Doron Somech's avatar
Doron Somech committed
665
                                  MACOSX_PACKAGE_LOCATION etc)
666
      set_source_files_properties (${zmq-pkgconfig} PROPERTIES
Doron Somech's avatar
Doron Somech committed
667
                                  MACOSX_PACKAGE_LOCATION lib/pkgconfig)
668 669 670
    endif ()
    add_library (libzmq-static STATIC ${sources} ${public_headers} ${html-docs} ${readme-docs} ${zmq-pkgconfig})
    set_target_properties (libzmq-static PROPERTIES
671
      PUBLIC_HEADER "${public_headers}"
672
      COMPILE_DEFINITIONS "ZMQ_STATIC"
673 674
      OUTPUT_NAME "libzmq-static"
      PREFIX "")
675
endif ()
676

677
target_link_libraries (libzmq ${CMAKE_THREAD_LIBS_INIT})
678

679 680 681 682 683 684 685 686
if (SODIUM_FOUND)
  target_link_libraries (libzmq ${SODIUM_LIBRARIES})
endif ()
if (HAVE_WS2_32)
  target_link_libraries (libzmq ws2_32)
elseif (HAVE_WS2)
  target_link_libraries (libzmq ws2)
endif ()
687

688 689 690
if (HAVE_RPCRT4)
  target_link_libraries (libzmq rpcrt4)
endif ()
691

692 693 694
if (HAVE_IPHLAPI)
  target_link_libraries (libzmq iphlpapi)
endif ()
695

696 697 698
if (RT_LIBRARY)
  target_link_libraries (libzmq ${RT_LIBRARY})
endif ()
699

700
set (perf-tools local_lat
701 702 703 704 705 706
               remote_lat
               local_thr
               remote_thr
               inproc_lat
               inproc_thr)

707 708 709 710 711
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 ()
712

713 714 715 716
if (WITH_PERF_TOOL)
  foreach (perf-tool ${perf-tools})
    add_executable (${perf-tool} perf/${perf-tool}.cpp)
    target_link_libraries (${perf-tool} libzmq)
717

718 719 720
    if (RT_LIBRARY)
      target_link_libraries (${perf-tool} ${RT_LIBRARY})
    endif ()
721

722
    if (ZMQ_BUILD_FRAMEWORK)
Doron Somech's avatar
Doron Somech committed
723
      # Copy perf-tools binaries into Framework
724
      add_custom_command (
Doron Somech's avatar
Doron Somech committed
725 726 727 728 729 730
        TARGET libzmq ${perf-tool}
        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")
731 732
    else ()
      install (TARGETS ${perf-tool}
Doron Somech's avatar
Doron Somech committed
733 734
              RUNTIME DESTINATION bin
              COMPONENT PerfTools)
735 736 737
    endif ()
  endforeach ()
endif ()
738

739 740 741
#-----------------------------------------------------------------------------
# tests

742
set (ZMQ_BUILD_TESTS ON CACHE BOOL "Build the tests for ZeroMQ")
743

744 745 746 747
if (ZMQ_BUILD_TESTS)
  enable_testing () # Enable testing only works in root scope
  ADD_SUBDIRECTORY (tests)
endif ()
748

749 750
#-----------------------------------------------------------------------------
# installer
751

752 753
if (MSVC)
  install (TARGETS libzmq libzmq-static
Doron Somech's avatar
Doron Somech committed
754 755 756 757
          ARCHIVE DESTINATION lib
          LIBRARY DESTINATION lib
          PUBLIC_HEADER DESTINATION include
          COMPONENT SDK)
758 759
  if (CMAKE_BUILD_TYPE STREQUAL "Debug")
    install (TARGETS libzmq libzmq-static
760
            RUNTIME DESTINATION bin
761
            ARCHIVE DESTINATION lib
762 763
            PUBLIC_HEADER DESTINATION include
            COMPONENT SDK)
764 765
    if (NOT CMAKE_PDB_OUTPUT_DIRECTORY)
      install (FILES ${CMAKE_CURRENT_BINARY_DIR}/bin/libzmq${MSVC_TOOLSET}-mt-gd-${ZMQ_VERSION_MAJOR}_${ZMQ_VERSION_MINOR}_${ZMQ_VERSION_PATCH}.pdb DESTINATION lib
Doron Somech's avatar
Doron Somech committed
766
            COMPONENT SDK)
767 768 769
    endif ()
  else ()
    install (TARGETS libzmq
770
            RUNTIME DESTINATION bin
Doron Somech's avatar
Doron Somech committed
771 772
            PUBLIC_HEADER DESTINATION include
            COMPONENT Runtime)
773 774 775
  endif ()
else ()
  install (TARGETS libzmq libzmq-static
Doron Somech's avatar
Doron Somech committed
776 777 778 779 780
          RUNTIME DESTINATION bin
          ARCHIVE DESTINATION lib
          LIBRARY DESTINATION lib
          FRAMEWORK DESTINATION "Library/Frameworks"
          PUBLIC_HEADER DESTINATION include)
781
endif ()
782

783
# install (FILES ${public_headers}
Doron Somech's avatar
Doron Somech committed
784 785
#          DESTINATION include
#          COMPONENT SDK)
786

787 788 789
#if (NOT ZMQ_BUILD_FRAMEWORK)
#  file (GLOB private_headers "${CMAKE_CURRENT_SOURCE_DIR}/src/*.hpp")
#  install (FILES ${sources} ${private_headers} DESTINATION src/zmq
xantares's avatar
xantares committed
790
#          COMPONENT SourceCode)
791
#endif ()
792

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

796 797 798 799 800 801 802 803
  if (NOT ZMQ_BUILD_FRAMEWORK)
    if (MSVC)
      install (FILES ${CMAKE_CURRENT_BINARY_DIR}/${readme}.txt DESTINATION .)
    else ()
      install (FILES ${CMAKE_CURRENT_BINARY_DIR}/${readme}.txt DESTINATION share/zmq)
    endif ()
  endif ()
endforeach ()
804

805 806 807 808 809
if (WITH_DOC)
  if (NOT ZMQ_BUILD_FRAMEWORK)
    install (FILES ${html-docs} DESTINATION doc/zmq COMPONENT RefGuide)
  endif ()
endif ()
Doron Somech's avatar
Doron Somech committed
810 811


812 813
if (MSVC)
  include (InstallRequiredSystemLibraries)
Doron Somech's avatar
Doron Somech committed
814

815 816 817 818 819
  if (CMAKE_CL_64)
    set (arch_name "x64")
  else ()
    set (arch_name "x86")
  endif ()
Doron Somech's avatar
Doron Somech committed
820

821 822
  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}")
Doron Somech's avatar
Doron Somech committed
823 824 825 826

  # TODO: I think this part was intended to be used when running cpack
  # separately from cmake but I don't know how that works.
  #
827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851
  # 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)

  set (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")
Doron Somech's avatar
Doron Somech committed
852
  # There is a bug in NSI that does not handle full unix paths properly. Make
853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868
  # 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
Doron Somech's avatar
Doron Somech committed
869 870
    DISPLAY_NAME "ZeroMQ software development kit"
    EXPANDED)
871
  cpack_add_component (PerfTools
Doron Somech's avatar
Doron Somech committed
872 873
    DISPLAY_NAME "ZeroMQ performance tools"
    INSTALL_TYPES FullInstall DevInstall)
874
  cpack_add_component (SourceCode
Doron Somech's avatar
Doron Somech committed
875 876 877
    DISPLAY_NAME "ZeroMQ source code"
    DISABLED
    INSTALL_TYPES FullInstall)
878
  cpack_add_component (SDK
Doron Somech's avatar
Doron Somech committed
879 880 881
    DISPLAY_NAME "ZeroMQ headers and libraries"
    INSTALL_TYPES FullInstall DevInstall
    GROUP Development)
882 883
  if (WITH_DOC)
    cpack_add_component (RefGuide
Doron Somech's avatar
Doron Somech committed
884 885 886
      DISPLAY_NAME "ZeroMQ reference guide"
      INSTALL_TYPES FullInstall DevInstall
      GROUP Development)
887 888
  endif ()
  cpack_add_component (Runtime
Doron Somech's avatar
Doron Somech committed
889 890 891
    DISPLAY_NAME "ZeroMQ runtime files"
    REQUIRED
    INSTALL_TYPES FullInstall DevInstall MinInstall)
892
  cpack_add_install_type (FullInstall
Doron Somech's avatar
Doron Somech committed
893
    DISPLAY_NAME "Full install, including source code")
894
  cpack_add_install_type (DevInstall
Doron Somech's avatar
Doron Somech committed
895
    DISPLAY_NAME "Developer install, headers and libraries")
896
  cpack_add_install_type (MinInstall
Doron Somech's avatar
Doron Somech committed
897
    DISPLAY_NAME "Minimal install, runtime only")
898
endif ()
Doron Somech's avatar
Doron Somech committed
899 900

# Export this for library to help build this as a sub-project
901
set (ZEROMQ_LIBRARY libzmq CACHE STRING "ZeroMQ library")
Doron Somech's avatar
Doron Somech committed
902 903 904

# Workaround for MSVS10 to avoid the Dialog Hell
# FIXME: This could be removed with future version of CMake.
905 906 907 908 909 910
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 ()