diff --git a/CMakeLists.txt b/CMakeLists.txt index f73baf8c..c6d9fc1e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,63 +1,251 @@ -# CMake build script for ZeroMQ on Windows +# CMake build script for ZeroMQ -cmake_minimum_required (VERSION 2.8) -project (ZeroMQ) +cmake_minimum_required(VERSION 2.8) +project(ZeroMQ) -include (${CMAKE_SOURCE_DIR}/cmake/Modules/TestZMQVersion.cmake) +option(WITH_OPENPGM "Build with support for OpenPGM" OFF) -option (WITH_DOC "Build Reference Guide documentation (requires DocBook)" OFF) -option (WITH_OPENPGM "Build with support for OpenPGM" OFF) +if(APPLE) + option(ZMQ_BUILD_FRAMEWORK "Build as OS X framework" ON) +endif() -# WARNING: Windows Python will override Cygwin yet not work with Asciidoc. -#find_package (PythonInterp REQUIRED) -# Workaround, manually set Python location -set(PYTHON_EXECUTABLE c:/cygwin/bin/python2.6.exe CACHE FILEPATH "Python interpreter executable") -# TODO: Replace with FindAsciidoc.cmake -set(ASCIIDOC_EXECUTABLE c:/cygwin/bin/asciidoc CACHE FILEPATH "AsciiDoc executable") -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 (CMAKE_CL_64) - 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 (CMAKE_CL_64) - set(OPENPGM_INCLUDE_DIRS ${OPENPGM_ROOT}/include) - set(OPENPGM_LIBRARY_DIRS ${OPENPGM_ROOT}/lib) - set(OPENPGM_LIBRARIES - optimized libpgm${_zmq_COMPILER}-mt-${OPENPGM_VERSION_MAJOR}_${OPENPGM_VERSION_MINOR}_${OPENPGM_VERSION_MICRO}.lib - debug libpgm${_zmq_COMPILER}-mt-gd-${OPENPGM_VERSION_MAJOR}_${OPENPGM_VERSION_MINOR}_${OPENPGM_VERSION_MICRO}.lib) -endif (WITH_OPENPGM) +set(POLLER "" CACHE STRING "Choose polling system manually. valid values are + kqueue, epoll, devpoll, poll or select [default=autodetect]") + +if( NOT POLLER STREQUAL "" + AND NOT POLLER STREQUAL "kqueue" + AND NOT POLLER STREQUAL "epoll" + AND NOT POLLER STREQUAL "devpoll" + AND NOT POLLER STREQUAL "poll" + AND NOT POLLER STREQUAL "select") + message(FATAL_ERROR "Invalid polling method") +endif() + +if(NOT ${POLLER} STREQUAL "") + string(TOUPPER ${POLLER} UPPER_POLLER) + set(ZMQ_FORCE_${UPPER_POLLER} 1) +endif() + +set(ZMQ_CMAKE_MODULES_DIR ${CMAKE_CURRENT_LIST_DIR}/cmake/Modules) +list(APPEND CMAKE_MODULE_PATH ${ZMQ_CMAKE_MODULES_DIR}) + +include(TestZMQVersion) +include(ZMQSourceRunChecks) +include(CheckIncludeFiles) +include(CheckLibraryExists) +include(CheckFunctionExists) +include(CheckCCompilerFlag) +include(CheckCXXCompilerFlag) +include(CheckCSourceCompiles) +include(CheckCSourceRuns) +include(CMakeDependentOption) + +check_include_files(ifaddrs.h ZMQ_HAVE_IFADDRS) +check_include_files(windows.h HAVE_WINDOWS_H) +check_include_files(sys/uio.h ZMQ_HAVE_UIO) +check_include_files(sys/eventfd.h ZMQ_HAVE_EVENTFD) + +check_library_exists(ws2_32 printf "" HAVE_WS2_32) # TODO: Why doesn't something logical like WSAStartup work? +check_library_exists(ws2 printf "" HAVE_WS2) +check_library_exists(rpcrt4 printf "" HAVE_RPCRT4) # UuidCreateSequential +check_library_exists(iphlpapi printf "" HAVE_IPHLAPI) # GetAdaptersAddresses + +find_package(Threads) + + +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() + + if(NOT HAVE_IPHLAPI) + message(FATAL_ERROR "Cannot link to iphlapi") + endif() +endif() + +set(CMAKE_REQUIRED_LIBRARIES rt) +check_function_exists(clock_gettime HAVE_CLOCK_GETTIME) +set(CMAKE_REQUIRED_LIBRARIES ) + +set(CMAKE_REQUIRED_INCLUDES sys/time.h) +check_function_exists(gethrtime HAVE_GETHRTIME) +set(CMAKE_REQUIRED_INCLUDES ) + +add_definitions(-D_REENTRANT -D_THREAD_SAFE) + +if(WIN32) + add_definitions(-DDLL_EXPORT) +endif() + +option(ENABLE_EVENTFD "Enable/disable eventfd" ZMQ_HAVE_EVENTFD) + +macro(zmq_check_cxx_flag_prepend flag) + check_cxx_compiler_flag("${flag}" HAVE_FLAG_${flag}) + + if(HAVE_FLAG_${flag}) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}") + endif() +endmacro() + + +if(MSVC) + zmq_check_cxx_flag_prepend("/W3") +else() + zmq_check_cxx_flag_prepend("-Wall") +endif() + +if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") + zmq_check_cxx_flag_prepend("-Wextra") +endif() + +zmq_check_cxx_flag_prepend("-Wno-long-long") +zmq_check_cxx_flag_prepend("-Wno-uninitialized") + +option(LIBZMQ_PEDANTIC "" ON) +option(LIBZMQ_WERROR "" OFF) + +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") + endif() +endif() + +if(LIBZMQ_WERROR) + zmq_check_cxx_flag_prepend("-Werror") + zmq_check_cxx_flag_prepend("-errwarn=%all") +endif() + + +if(CMAKE_SYSTEM_PROCESSOR MATCHES "^sparc") + zmq_check_cxx_flag_prepend("-mcpu=v9") +endif() + +if(${CMAKE_CXX_COMPILER_ID} MATCHES "SunPro") + zmq_check_cxx_flag_prepend("-features=zla") +endif() + + +if(CMAKE_SYSTEM_NAME MATCHES "SunOS" OR CMAKE_SYSTEM_NAME MATCHES "NetBSD") + message(STATUS "Checking whether atomic operations can be used") + check_c_source_compiles( + " + #include + + int main() + { + uint32_t value; + atomic_cas_32(&value, 0, 0); + return 0; + } + " + HAVE_ATOMIC_H) + + if(NOT HAVE_ATOMIC_H) + set(ZMQ_FORCE_MUTEXES 1) + endif() +endif() + + +#----------------------------------------------------------------------------- +zmq_check_sock_cloexec() +zmq_check_so_keepalive() +zmq_check_tcp_keepcnt() +zmq_check_tcp_keepidle() +zmq_check_tcp_keepintvl() +zmq_check_tcp_keepalive() + + +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() + +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 + "PYTHON_FOUND;ASCIIDOC_FOUND" OFF) + +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(CMAKE_CL_64) + set(OPENPGM_INCLUDE_DIRS ${OPENPGM_ROOT}/include) + set(OPENPGM_LIBRARY_DIRS ${OPENPGM_ROOT}/lib) + set(OPENPGM_LIBRARIES + optimized libpgm${_zmq_COMPILER}-mt-${OPENPGM_VERSION_MAJOR}_${OPENPGM_VERSION_MINOR}_${OPENPGM_VERSION_MICRO}.lib + debug libpgm${_zmq_COMPILER}-mt-gd-${OPENPGM_VERSION_MAJOR}_${OPENPGM_VERSION_MINOR}_${OPENPGM_VERSION_MICRO}.lib) + endif() +else() + if(WITH_OPENPGM) + message(FATAL_ERROR "WITH_OPENPGM not implemented") + # DSO symbol visibility for openpgm + if(HAVE_FLAG_VISIBILITY_HIDDEN) + + elseif(HAVE_FLAG_LDSCOPE_HIDDEN) + endif() + endif() +endif() -mark_as_advanced(PYTHON_EXECUTABLE ASCIIDOC_EXECUTABLE) #----------------------------------------------------------------------------- # force off-tree build -if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR}) +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.: - del CMakeCache.txt + rm CMakeCache.txt mkdir cmake-make cd cmake-make cmake .. ") -endif(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR}) +endif() #----------------------------------------------------------------------------- # default to Release build @@ -66,330 +254,469 @@ if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel." FORCE) -endif(NOT CMAKE_BUILD_TYPE) +endif() -set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin) -set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib) +set(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}/bin) +set(LIBRARY_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}/lib) #----------------------------------------------------------------------------- # platform specifics -add_definitions( - -DWIN32 - -DDLL_EXPORT -# NB: May require tweaking for highly connected applications. - -DFD_SETSIZE=1024 - -D_CRT_SECURE_NO_WARNINGS -) +if(MSVC) + add_definitions( + -DWIN32 + -DDLL_EXPORT + # NB: May require tweaking for highly connected applications. + -DFD_SETSIZE=1024 + -D_CRT_SECURE_NO_WARNINGS) -# Parallel make. -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP") + # Parallel make. + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP") + + # Optimization flags. + # http://msdn.microsoft.com/en-us/magazine/cc301698.aspx + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /GL") + set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /LTCG") + set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /LTCG") + set(CMAKE_MODULE_LINKER_FLAGS_RELEASE "${CMAKE_MODULE_LINKER_FLAGS_RELEASE} /LTCG") +endif() -# Optimization flags. -# http://msdn.microsoft.com/en-us/magazine/cc301698.aspx -set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /GL") -set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /LTCG") -set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /LTCG") -set(CMAKE_MODULE_LINKER_FLAGS_RELEASE "${CMAKE_MODULE_LINKER_FLAGS_RELEASE} /LTCG") #----------------------------------------------------------------------------- # source files set(cxx-sources - address.cpp - clock.cpp - ctx.cpp - dealer.cpp - decoder.cpp - devpoll.cpp - dist.cpp - encoder.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 - msg.cpp - mtrie.cpp - object.cpp - options.cpp - own.cpp - pair.cpp - pgm_receiver.cpp - pgm_sender.cpp - pgm_socket.cpp - pipe.cpp - 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 - session_base.cpp - signaler.cpp - socket_base.cpp - 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 - xpub.cpp - xsub.cpp - zmq.cpp - zmq_utils.cpp -) + address.cpp + clock.cpp + ctx.cpp + dealer.cpp + decoder.cpp + devpoll.cpp + dist.cpp + encoder.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 + msg.cpp + mtrie.cpp + object.cpp + options.cpp + own.cpp + pair.cpp + pgm_receiver.cpp + pgm_sender.cpp + pgm_socket.cpp + pipe.cpp + 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 + session_base.cpp + signaler.cpp + socket_base.cpp + 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 + xpub.cpp + xsub.cpp + zmq.cpp + zmq_utils.cpp) -set(rc-sources - version.rc -) +set(rc-sources version.rc) -include_directories( - include - ${CMAKE_BINARY_DIR} -) -set(headers - include/zmq.h - include/zmq_utils.h -) -set(readme-docs - AUTHORS - COPYING - COPYING.LESSER - MAINTAINERS - NEWS - README -) +if(MINGW) + # Generate the right type when using -m32 or -m64 + macro(set_rc_arch rc_target) + set(CMAKE_RC_COMPILER_INIT windres) + enable_language(RC) + set(CMAKE_RC_COMPILE_OBJECT + " --target=${rc_target} -i -o ") + endmacro() + + if( ${CMAKE_SYSTEM_PROCESSOR} MATCHES "i386" + OR ${CMAKE_SYSTEM_PROCESSOR} MATCHES "i486" + OR ${CMAKE_SYSTEM_PROCESSOR} MATCHES "i586" + OR ${CMAKE_SYSTEM_PROCESSOR} MATCHES "i686" + # This also happens on x86_64 systems...what a worthless variable + 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() + +include_directories(include ${CMAKE_CURRENT_BINARY_DIR}) +set(public_headers include/zmq.h + include/zmq_utils.h) + +set(readme-docs AUTHORS + COPYING + COPYING.LESSER + MAINTAINERS + NEWS + README) #----------------------------------------------------------------------------- # optional modules if(WITH_OPENPGM) - add_definitions( - -DZMQ_HAVE_OPENPGM - ) - include_directories( - ${OPENPGM_INCLUDE_DIRS} - ) - link_directories( - ${OPENPGM_LIBRARY_DIRS} - ) - set(OPTIONAL_LIBRARIES ${OPENPGM_LIBRARIES}) + add_definitions(-DZMQ_HAVE_OPENPGM) + include_directories(${OPENPGM_INCLUDE_DIRS}) + link_directories(${OPENPGM_LIBRARY_DIRS}) + set(OPTIONAL_LIBRARIES ${OPENPGM_LIBRARIES}) endif(WITH_OPENPGM) #----------------------------------------------------------------------------- # source generators -foreach (source ${cxx-sources}) - list(APPEND sources ${CMAKE_SOURCE_DIR}/src/${source}) +foreach(source ${cxx-sources}) + list(APPEND sources ${CMAKE_CURRENT_SOURCE_DIR}/src/${source}) endforeach() -foreach (source ${rc-sources}) - list(APPEND sources ${CMAKE_BINARY_DIR}/${source}) - configure_file(${CMAKE_SOURCE_DIR}/src/${source}.in ${CMAKE_BINARY_DIR}/${source}) +foreach(source ${rc-sources}) + list(APPEND sources ${CMAKE_CURRENT_BINARY_DIR}/${source}) endforeach() -add_custom_command( - OUTPUT ${CMAKE_BINARY_DIR}/platform.hpp - COMMAND ${CMAKE_COMMAND} - ARGS -E - copy - ${CMAKE_SOURCE_DIR}/builds/msvc/platform.hpp - ${CMAKE_BINARY_DIR}/platform.hpp - DEPENDS ${CMAKE_SOURCE_DIR}/builds/msvc/platform.hpp -) -list(APPEND sources ${CMAKE_BINARY_DIR}/platform.hpp) +foreach(source ${rc-sources}) + list(APPEND sources ${CMAKE_BINARY_DIR}/${source}) + configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/${source}.in ${CMAKE_CURRENT_BINARY_DIR}/${source}) +endforeach() -if (CMAKE_CL_64) - set (nsis-template ${CMAKE_SOURCE_DIR}/cmake/NSIS.template64.in) -else (CMAKE_CL_64) - set (nsis-template ${CMAKE_SOURCE_DIR}/cmake/NSIS.template32.in) -endif (CMAKE_CL_64) -add_custom_command( - OUTPUT ${CMAKE_BINARY_DIR}/NSIS.template.in - COMMAND ${CMAKE_COMMAND} - ARGS -E - copy - ${nsis-template} - ${CMAKE_BINARY_DIR}/NSIS.template.in - DEPENDS ${nsis-template} -) +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) + +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/libzmq.pc.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/libzmq.pc) +set(zmq-pkgconfig ${CMAKE_CURRENT_BINARY_DIR}/libzmq.pc) + +if(NOT ZMQ_BUILD_FRAMEWORK) + install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libzmq.pc DESTINATION lib/pkgconfig) +endif() + + + +if(MSVC) + if(CMAKE_CL_64) + set(nsis-template ${CMAKE_CURRENT_SOURCE_DIR}/cmake/NSIS.template64.in) + else() + set(nsis-template ${CMAKE_CURRENT_SOURCE_DIR}/cmake/NSIS.template32.in) + endif() + + add_custom_command( + 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}) +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( + OUTPUT ${dst} + COMMAND ${PYTHON_EXECUTABLE} + ARGS -x + ${ASCIIDOC_EXECUTABLE} + -d manpage + -b xhtml11 + -f ${CMAKE_SOURCE_DIR}/doc/asciidoc.conf + -azmq_version=${ZMQ_VERSION} + -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}") + if(WITH_DOC) + list(APPEND html-docs ${CMAKE_CURRENT_BINARY_DIR}/${dst}) + endif() +endforeach() + +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() -file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/doc) -file(GLOB docs RELATIVE ${CMAKE_BINARY_DIR}/ "${CMAKE_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( - OUTPUT ${dst} - COMMAND ${PYTHON_EXECUTABLE} - ARGS -x - ${ASCIIDOC_EXECUTABLE} - -d manpage - -b xhtml11 - -f ${CMAKE_SOURCE_DIR}/doc/asciidoc.conf - -azmq_version=${ZMQ_VERSION_MAJOR}.${ZMQ_VERSION_MINOR}.${ZMQ_VERSION_PATCH} - -o ${dst} - ${src} - DEPENDS ${CMAKE_BINARY_DIR}/${src} - WORKING_DIRECTORY ${CMAKE_BINARY_DIR} - COMMENT "Generating ${html}" - ) - if (WITH_DOC) - list(APPEND html-docs ${CMAKE_BINARY_DIR}/${dst}) - endif (WITH_DOC) -endforeach (txt ${docs}) #----------------------------------------------------------------------------- # output -add_library(libzmq SHARED ${sources} ${html-docs} ${CMAKE_BINARY_DIR}/NSIS.template.in) -target_link_libraries(libzmq ws2_32.lib rpcrt4.lib ${OPTIONAL_LIBRARIES}) -set_target_properties(libzmq PROPERTIES - RELEASE_POSTFIX "${_zmq_COMPILER}-mt-${ZMQ_VERSION_MAJOR}_${ZMQ_VERSION_MINOR}_${ZMQ_VERSION_PATCH}" - DEBUG_POSTFIX "${_zmq_COMPILER}-mt-gd-${ZMQ_VERSION_MAJOR}_${ZMQ_VERSION_MINOR}_${ZMQ_VERSION_PATCH}") +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 + PUBLIC_HEADER "${public_headers}" + RELEASE_POSTFIX "${_zmq_COMPILER}-mt-${ZMQ_VERSION_MAJOR}_${ZMQ_VERSION_MINOR}_${ZMQ_VERSION_PATCH}" + DEBUG_POSTFIX "${_zmq_COMPILER}-mt-gd-${ZMQ_VERSION_MAJOR}_${ZMQ_VERSION_MINOR}_${ZMQ_VERSION_PATCH}") +else() + add_library(libzmq SHARED ${sources} ${public_headers} ${html-docs} ${readme-docs} ${zmq-pkgconfig}) + if(ZMQ_BUILD_FRAMEWORK) + set_target_properties(libzmq PROPERTIES + FRAMEWORK TRUE + OUTPUT_NAME "ZeroMQ" + PUBLIC_HEADER "${public_headers}" + MACOSX_FRAMEWORK_IDENTIFIER "org.zeromq.libzmq" + MACOSX_FRAMEWORK_SHORT_VERSION_STRING ${ZMQ_VERSION} + MACOSX_FRAMEWORK_BUNDLE_VERSION ${ZMQ_VERSION} + VERSION ${ZMQ_VERSION} + SOVERSION "${ZMQ_VERSION_MAJOR}.${ZMQ_VERSION_MINOR}.0") + 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) + else() + set_target_properties(libzmq PROPERTIES + OUTPUT_NAME "zmq" + PUBLIC_HEADER "${public_headers}") + endif() +endif() + +target_link_libraries(libzmq ${CMAKE_THREAD_LIBS_INIT}) +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() + +set(perf-tools local_lat + remote_lat + local_thr + remote_thr + inproc_lat + inproc_thr) + +if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug") # Why? + foreach(perf-tool ${perf-tools}) + add_executable(${perf-tool} perf/${perf-tool}.cpp) + target_link_libraries(${perf-tool} libzmq) + + if(ZMQ_BUILD_FRAMEWORK) + # Copy perf-tools binaries into Framework + add_custom_command( + TARGET libzmq ${perf-tool} + POST_BUILD + COMMAND ${CMAKE_COMMAND} + ARGS -E copy "$" "${LIBRARY_OUTPUT_PATH}/ZeroMQ.framework/Versions/${ZMQ_VERSION_STRING}/MacOS/${perf-tool}" + VERBATIM + COMMENT "Perf tools") + else() + install(TARGETS ${perf-tool} + RUNTIME DESTINATION bin + COMPONENT PerfTools) + endif() + endforeach() +endif() + #----------------------------------------------------------------------------- # installer -install (TARGETS libzmq ARCHIVE DESTINATION lib COMPONENT SDK) -if (CMAKE_BUILD_TYPE STREQUAL "Debug") - install (TARGETS libzmq RUNTIME DESTINATION bin COMPONENT SDK) - install (FILES ${CMAKE_BINARY_DIR}/lib/libzmq${_zmq_COMPILER}-mt-gd-${ZMQ_VERSION_MAJOR}_${ZMQ_VERSION_MINOR}_${ZMQ_VERSION_PATCH}.pdb DESTINATION lib COMPONENT SDK) -else (CMAKE_BUILD_TYPE STREQUAL "Debug") - install (TARGETS libzmq RUNTIME DESTINATION bin COMPONENT Runtime) -endif (CMAKE_BUILD_TYPE STREQUAL "Debug") -install (FILES ${headers} DESTINATION include COMPONENT SDK) +if(MSVC) + install(TARGETS libzmq + ARCHIVE DESTINATION lib + LIBRARY DESTINATION lib + PUBLIC_HEADER DESTINATION include + COMPONENT SDK) + if(CMAKE_BUILD_TYPE STREQUAL "Debug") + install(TARGETS libzmq + RUNTIME DESTINATION bin + PUBLIC_HEADER DESTINATION include + COMPONENT SDK) + install(FILES ${CMAKE_CURRENT_BINARY_DIR}/lib/libzmq${_zmq_COMPILER}-mt-gd-${ZMQ_VERSION_MAJOR}_${ZMQ_VERSION_MINOR}_${ZMQ_VERSION_PATCH}.pdb DESTINATION lib + COMPONENT SDK) + else() + install(TARGETS libzmq + RUNTIME DESTINATION bin + PUBLIC_HEADER DESTINATION include + COMPONENT Runtime) + endif() +else() + install(TARGETS libzmq + RUNTIME DESTINATION bin + ARCHIVE DESTINATION lib + LIBRARY DESTINATION lib + FRAMEWORK DESTINATION "Library/Frameworks" + PUBLIC_HEADER DESTINATION include) +endif() -set (perf-tools - local_lat - remote_lat - local_thr - remote_thr - inproc_lat - inproc_thr -) -if (NOT CMAKE_BUILD_TYPE STREQUAL "Debug") - foreach (perf-tool ${perf-tools}) - add_executable (${perf-tool} perf/${perf-tool}.cpp) - target_link_libraries (${perf-tool} libzmq) - install (TARGETS ${perf-tool} RUNTIME DESTINATION bin COMPONENT PerfTools) - endforeach (perf-tool ${perf-tools}) -endif (NOT CMAKE_BUILD_TYPE STREQUAL "Debug") +# install(FILES ${public_headers} +# DESTINATION include +# COMPONENT SDK) -file(GLOB headers "${CMAKE_SOURCE_DIR}/src/*.hpp") -install (FILES ${sources} ${headers} DESTINATION src COMPONENT SourceCode) +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_SOURCE_DIR}/${readme} ${CMAKE_BINARY_DIR}/${readme}.txt) - install (FILES ${CMAKE_BINARY_DIR}/${readme}.txt DESTINATION .) -endforeach (readme ${readme-docs}) -if (WITH_DOC) - install (FILES ${html-docs} DESTINATION doc COMPONENT RefGuide) -endif (WITH_DOC) +foreach(readme ${readme-docs}) + configure_file(${CMAKE_CURRENT_SOURCE_DIR}/${readme} ${CMAKE_CURRENT_BINARY_DIR}/${readme}.txt) -include (InstallRequiredSystemLibraries) + 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 etc/zmq) + endif() + endif() +endforeach() -if (CMAKE_CL_64) - set (CPACK_NSIS_DISPLAY_NAME "ZeroMQ ${ZMQ_VERSION_MAJOR}.${ZMQ_VERSION_MINOR}.${ZMQ_VERSION_PATCH} (x64)") - set (CPACK_PACKAGE_FILE_NAME "ZeroMQ-${ZMQ_VERSION_MAJOR}.${ZMQ_VERSION_MINOR}.${ZMQ_VERSION_PATCH}-x64") - set (CPACK_INSTALL_CMAKE_PROJECTS - "${CMAKE_SOURCE_DIR}/build/x64/v110;ZeroMQ;ALL;/" - "${CMAKE_SOURCE_DIR}/debug/x64/v110;ZeroMQ;ALL;/" - "${CMAKE_SOURCE_DIR}/build/x64/v100;ZeroMQ;ALL;/" - "${CMAKE_SOURCE_DIR}/debug/x64/v100;ZeroMQ;ALL;/" - "${CMAKE_SOURCE_DIR}/build/x64/v90;ZeroMQ;ALL;/" - "${CMAKE_SOURCE_DIR}/debug/x64/v90;ZeroMQ;ALL;/" - ) -else (CMAKE_CL_64) - set (CPACK_NSIS_DISPLAY_NAME "ZeroMQ ${ZMQ_VERSION_MAJOR}.${ZMQ_VERSION_MINOR}.${ZMQ_VERSION_PATCH}") - set (CPACK_PACKAGE_FILE_NAME "ZeroMQ-${ZMQ_VERSION_MAJOR}.${ZMQ_VERSION_MINOR}.${ZMQ_VERSION_PATCH}-x86") - set (CPACK_INSTALL_CMAKE_PROJECTS - "${CMAKE_SOURCE_DIR}/build/x86/v110;ZeroMQ;ALL;/" - "${CMAKE_SOURCE_DIR}/debug/x86/v110;ZeroMQ;ALL;/" - "${CMAKE_SOURCE_DIR}/build/x86/v100;ZeroMQ;ALL;/" - "${CMAKE_SOURCE_DIR}/debug/x86/v100;ZeroMQ;ALL;/" - "${CMAKE_SOURCE_DIR}/build/x86/v90;ZeroMQ;ALL;/" - "${CMAKE_SOURCE_DIR}/debug/x86/v90;ZeroMQ;ALL;/" - ) -endif (CMAKE_CL_64) -set (CMAKE_MODULE_PATH "${CMAKE_BINARY_DIR}") -set (CPACK_PACKAGE_DESCRIPTION_SUMMARY "ZeroMQ lightweight messaging kernel") -set (CPACK_PACKAGE_VENDOR "Miru") -set (CPACK_NSIS_CONTACT "Steven McCoy ") -set (CPACK_RESOURCE_FILE_LICENSE "${CMAKE_BINARY_DIR}/COPYING.txt") -# There is a bug in NSI that does not handle full unix paths properly. Make -# sure there is at least one set of four (4) backlasshes. -set (CPACK_NSIS_MUI_ICON "${CMAKE_SOURCE_DIR}\\\\installer.ico") -set (CPACK_NSIS_MUI_UNIICON "${CMAKE_SOURCE_DIR}\\\\installer.ico") -set (CPACK_PACKAGE_ICON "${CMAKE_SOURCE_DIR}\\\\branding.bmp") -set (CPACK_NSIS_COMPRESSOR "/SOLID lzma") -set (CPACK_PACKAGE_VERSION_MAJOR "${ZMQ_VERSION_MAJOR}") -set (CPACK_PACKAGE_VERSION_MINOR "${ZMQ_VERSION_MINOR}") -set (CPACK_PACKAGE_VERSION_PATCH "${ZMQ_VERSION_PATCH}") +if(WITH_DOC) + if(NOT ZMQ_BUILD_FRAMEWORK) + install(FILES ${html-docs} DESTINATION doc/zmq COMPONENT RefGuide) + endif() +endif() -include (CPack) -cpack_add_component_group (Development - DISPLAY_NAME "ZeroMQ software development kit" - EXPANDED -) -cpack_add_component (PerfTools - DISPLAY_NAME "ZeroMQ performance tools" - INSTALL_TYPES FullInstall DevInstall -) -cpack_add_component (SourceCode - DISPLAY_NAME "ZeroMQ source code" - DISABLED - INSTALL_TYPES FullInstall -) -cpack_add_component (SDK - DISPLAY_NAME "ZeroMQ headers and libraries" - INSTALL_TYPES FullInstall DevInstall - GROUP Development -) -if (WITH_DOC) - cpack_add_component (RefGuide - DISPLAY_NAME "ZeroMQ reference guide" - INSTALL_TYPES FullInstall DevInstall - GROUP Development - ) -endif (WITH_DOC) -cpack_add_component (Runtime - DISPLAY_NAME "ZeroMQ runtime files" - REQUIRED - INSTALL_TYPES FullInstall DevInstall MinInstall -) -cpack_add_install_type (FullInstall - DISPLAY_NAME "Full install, including source code" -) -cpack_add_install_type (DevInstall - DISPLAY_NAME "Developer install, headers and libraries" -) -cpack_add_install_type (MinInstall - DISPLAY_NAME "Minimal install, runtime only" -) +if(MSVC) + include(InstallRequiredSystemLibraries) -# end of file + if(CMAKE_CL_64) + set(arch_name "x64") + else() + set(arch_name "x86") + endif() + + 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}") + + # TODO: I think this part was intended to be used when running cpack + # separately from cmake but I don't know how that works. + # + # 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 ") + 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}\\\\README.txt") + # There is a bug in NSI that does not handle full unix paths properly. Make + # 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 + DISPLAY_NAME "ZeroMQ software development kit" + EXPANDED) + cpack_add_component(PerfTools + DISPLAY_NAME "ZeroMQ performance tools" + INSTALL_TYPES FullInstall DevInstall) + cpack_add_component(SourceCode + DISPLAY_NAME "ZeroMQ source code" + DISABLED + INSTALL_TYPES FullInstall) + cpack_add_component(SDK + DISPLAY_NAME "ZeroMQ headers and libraries" + INSTALL_TYPES FullInstall DevInstall + GROUP Development) + if(WITH_DOC) + cpack_add_component(RefGuide + DISPLAY_NAME "ZeroMQ reference guide" + INSTALL_TYPES FullInstall DevInstall + GROUP Development) + endif() + cpack_add_component(Runtime + DISPLAY_NAME "ZeroMQ runtime files" + REQUIRED + INSTALL_TYPES FullInstall DevInstall MinInstall) + cpack_add_install_type(FullInstall + DISPLAY_NAME "Full install, including source code") + cpack_add_install_type(DevInstall + DISPLAY_NAME "Developer install, headers and libraries") + cpack_add_install_type(MinInstall + DISPLAY_NAME "Minimal install, runtime only") +endif() + +# Export this for library to help build this as a sub-project +set(ZEROMQ_LIBRARY libzmq CACHE STRING "ZeroMQ library") + +# Workaround for MSVS10 to avoid the Dialog Hell +# FIXME: This could be removed with future version of CMake. +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() diff --git a/builds/cmake/platform.hpp.in b/builds/cmake/platform.hpp.in new file mode 100644 index 00000000..5f5eb2e0 --- /dev/null +++ b/builds/cmake/platform.hpp.in @@ -0,0 +1,91 @@ +#ifndef __ZMQ_PLATFORM_HPP_INCLUDED__ +#define __ZMQ_PLATFORM_HPP_INCLUDED__ + +#cmakedefine ZMQ_FORCE_SELECT +#cmakedefine ZMQ_FORCE_POLL +#cmakedefine ZMQ_FORCE_EPOLL +#cmakedefine ZMQ_FORCE_DEVPOLL +#cmakedefine ZMQ_FORCE_KQUEUE +#cmakedefine ZMQ_FORCE_SELECT +#cmakedefine ZMQ_FORCE_POLL + +#cmakedefine ZMQ_FORCE_MUTEXES + + +#cmakedefine HAVE_CLOCK_GETTIME +#cmakedefine HAVE_GETHRTIME +#cmakedefine ZMQ_HAVE_UIO + +#cmakedefine ZMQ_HAVE_EVENTFD +#cmakedefine ZMQ_HAVE_IFADDRS + +#cmakedefine ZMQ_HAVE_SOCK_CLOEXEC +#cmakedefine ZMQ_HAVE_SO_KEEPALIVE +#cmakedefine ZMQ_HAVE_TCP_KEEPCNT +#cmakedefine ZMQ_HAVE_TCP_KEEPIDLE +#cmakedefine ZMQ_HAVE_TCP_KEEPINTVL +#cmakedefine ZMQ_HAVE_TCP_KEEPALIVE + +#cmakedefine ZMQ_HAVE_OPENPGM +#cmakedefine ZMQ_MAKE_VALGRIND_HAPPY + + +#ifdef _AIX + #define ZMQ_HAVE_AIX +#endif + +#if defined ANDROID + #define ZMQ_HAVE_ANDROID +#endif + +#if defined __CYGWIN__ + #define ZMQ_HAVE_CYGWIN +#endif + +#if defined __MINGW32__ + #define ZMQ_HAVE_MINGW32 +#endif + +#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(__FreeBSD_kernel__) + #define ZMQ_HAVE_FREEBSD +#endif + +#if defined __hpux + #define ZMQ_HAVE_HPUX +#endif + +#if defined __linux__ + #define ZMQ_HAVE_LINUX +#endif + +#if defined __NetBSD__ + #define ZMQ_HAVE_NETBSD +#endif + +#if defined __OpenBSD__ + #define ZMQ_HAVE_OPENBSD +#endif + +#if defined __VMS + #define ZMQ_HAVE_OPENVMS +#endif + +#if defined __APPLE__ + #define ZMQ_HAVE_OSX +#endif + +#if defined __QNXNTO__ + #define ZMQ_HAVE_QNXNTO +#endif + +#if defined(sun) || defined(__sun) + #define ZMQ_HAVE_SOLARIS +#endif + +#if defined(WIN32) || defined(_WIN32) + #define ZMQ_HAVE_WINDOWS +#endif + + + +#endif diff --git a/cmake/Modules/FindAsciiDoc.cmake b/cmake/Modules/FindAsciiDoc.cmake new file mode 100644 index 00000000..db4e418c --- /dev/null +++ b/cmake/Modules/FindAsciiDoc.cmake @@ -0,0 +1,24 @@ +# - Find Asciidoc +# this module looks for asciidoc and a2x +# +# ASCIIDOC_EXECUTABLE - the full path to asciidoc +# ASCIIDOC_FOUND - If false, don't attempt to use asciidoc. +# A2X_EXECUTABLE - the full path to a2x +# A2X_FOUND - If false, don't attempt to use a2x. + +find_program(ASCIIDOC_EXECUTABLE asciidoc asciidoc.py + PATHS "$ENV{ASCIIDOC_ROOT}" + "$ENV{PROGRAMW6432}/asciidoc" + "$ENV{PROGRAMFILES}/asciidoc" + "$ENV{PROGRAMFILES(X86)}/asciidoc") + +find_program(A2X_EXECUTABLE a2x + PATHS "$ENV{ASCIIDOC_ROOT}" + "$ENV{PROGRAMW6432}/asciidoc" + "$ENV{PROGRAMFILES}/asciidoc" + "$ENV{PROGRAMFILES(X86)}/asciidoc") + + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_ARGS(AsciiDoc REQUIRED_VARS ASCIIDOC_EXECUTABLE) +mark_as_advanced(ASCIIDOC_EXECUTABLE A2X_EXECUTABLE) \ No newline at end of file diff --git a/cmake/Modules/TestZMQVersion.cmake b/cmake/Modules/TestZMQVersion.cmake index 0fcdc7cd..130c6013 100644 --- a/cmake/Modules/TestZMQVersion.cmake +++ b/cmake/Modules/TestZMQVersion.cmake @@ -1,35 +1,18 @@ - MESSAGE(STATUS "Detecting ZMQ") - SET(TRY_RUN_DIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/zmq_run.dir) +file(READ "${PROJECT_SOURCE_DIR}/include/zmq.h" _ZMQ_H_CONTENTS) +string(REGEX REPLACE ".*#define ZMQ_VERSION_MAJOR ([0-9]+).*" "\\1" ZMQ_VERSION_MAJOR "${_ZMQ_H_CONTENTS}") +string(REGEX REPLACE ".*#define ZMQ_VERSION_MINOR ([0-9]+).*" "\\1" ZMQ_VERSION_MINOR "${_ZMQ_H_CONTENTS}") +string(REGEX REPLACE ".*#define ZMQ_VERSION_PATCH ([0-9]+).*" "\\1" ZMQ_VERSION_PATCH "${_ZMQ_H_CONTENTS}") +set(ZMQ_VERSION "${ZMQ_VERSION_MAJOR}.${ZMQ_VERSION_MINOR}.${ZMQ_VERSION_PATCH}") - TRY_RUN(RUN_RESULT COMPILE_RESULT - ${TRY_RUN_DIR} - ${CMAKE_SOURCE_DIR}/cmake/Modules/zmq_version.cpp - CMAKE_FLAGS - "-DINCLUDE_DIRECTORIES:STRING=${CMAKE_SOURCE_DIR}/include" - COMPILE_OUTPUT_VARIABLE COMPILE_OUTPUT - RUN_OUTPUT_VARIABLE RUN_OUTPUT) +message(STATUS "Detected ZMQ Version - ${ZMQ_VERSION}") - IF(COMPILE_RESULT) - IF(RUN_RESULT MATCHES "FAILED_TO_RUN") - MESSAGE(STATUS "Detecting ZMQ - failed") - ELSE() - STRING(REGEX REPLACE "([0-9]+)\\.([0-9]+)\\.([0-9]+).*" "\\1" ZMQ_VERSION_MAJOR "${RUN_OUTPUT}") - STRING(REGEX REPLACE "([0-9]+)\\.([0-9]+)\\.([0-9]+).*" "\\2" ZMQ_VERSION_MINOR "${RUN_OUTPUT}") - STRING(REGEX REPLACE "([0-9]+)\\.([0-9]+)\\.([0-9]+).*" "\\3" ZMQ_VERSION_PATCH "${RUN_OUTPUT}") - MESSAGE(STATUS "Detecting ZMQ - ${ZMQ_VERSION_MAJOR}.${ZMQ_VERSION_MINOR}.${ZMQ_VERSION_PATCH}") - ENDIF() - ELSE() - MESSAGE(STATUS "Check for ZMQ version - not found") - MESSAGE(STATUS "Detecting ZMQ - failed") - ENDIF() - - if(MSVC_VERSION MATCHES "1700") - set(_zmq_COMPILER "-v110") - elseif(MSVC10) - set(_zmq_COMPILER "-v100") - elseif(MSVC90) - set(_zmq_COMPILER "-v90") - else() - set(_zmq_COMPILER "") - endif() +if(MSVC_VERSION MATCHES "1700") + set(_zmq_COMPILER "-v110") +elseif(MSVC10) + set(_zmq_COMPILER "-v100") +elseif(MSVC90) + set(_zmq_COMPILER "-v90") +else() + set(_zmq_COMPILER "") +endif() diff --git a/cmake/Modules/ZMQSourceRunChecks.cmake b/cmake/Modules/ZMQSourceRunChecks.cmake new file mode 100644 index 00000000..4d23a2a1 --- /dev/null +++ b/cmake/Modules/ZMQSourceRunChecks.cmake @@ -0,0 +1,129 @@ + + +macro(zmq_check_sock_cloexec) + message(STATUS "Checking whether SOCK_CLOEXEC is supported") + check_c_source_runs( + " +#include +#include + +int main(int argc, char *argv []) +{ + int s = socket(PF_INET, SOCK_STREAM | SOCK_CLOEXEC, 0); + return(s == -1); +} +" + ZMQ_HAVE_SOCK_CLOEXEC) +endmacro() + +# TCP keep-alives Checks. + +macro(zmq_check_so_keepalive) + message(STATUS "Checking whether SO_KEEPALIVE is supported") + check_c_source_runs( +" +#include +#include + +int main(int argc, char *argv []) +{ + int s, rc, opt = 1; + return( + ((s = socket(PF_INET, SOCK_STREAM, 0)) == -1) || + ((rc = setsockopt(s, SOL_SOCKET, SO_KEEPALIVE,(char*) &opt, sizeof(int))) == -1) + ); +} +" + ZMQ_HAVE_SO_KEEPALIVE) +endmacro() + +macro(zmq_check_tcp_keepcnt) + message(STATUS "Checking whether TCP_KEEPCNT is supported") + check_c_source_runs( + " +#include +#include +#include +#include + +int main(int argc, char *argv []) +{ + int s, rc, opt = 1; + return( + ((s = socket(PF_INET, SOCK_STREAM, 0)) == -1) || + ((rc = setsockopt(s, SOL_SOCKET, SO_KEEPALIVE,(char*) &opt, sizeof(int))) == -1) || + ((rc = setsockopt(s, IPPROTO_TCP, TCP_KEEPCNT,(char*) &opt, sizeof(int))) == -1) + ); +} +" + ZMQ_HAVE_TCP_KEEPCNT) +endmacro() + +macro(zmq_check_tcp_keepidle) + message(STATUS "Checking whether TCP_KEEPIDLE is supported") + check_c_source_runs( + " +#include +#include +#include +#include + +int main(int argc, char *argv []) +{ + int s, rc, opt = 1; + return( + ((s = socket(PF_INET, SOCK_STREAM, 0)) == -1) || + ((rc = setsockopt(s, SOL_SOCKET, SO_KEEPALIVE,(char*) &opt, sizeof(int))) == -1) || + ((rc = setsockopt(s, IPPROTO_TCP, TCP_KEEPIDLE,(char*) &opt, sizeof(int))) == -1) + ); +} +" + ZMQ_HAVE_TCP_KEEPIDLE) +endmacro() + + +macro(zmq_check_tcp_keepintvl) + message(STATUS "Checking whether TCP_KEEPINTVL is supported") + check_c_source_runs( + " +#include +#include +#include +#include + +int main(int argc, char *argv []) +{ + int s, rc, opt = 1; + return( + ((s = socket(PF_INET, SOCK_STREAM, 0)) == -1) || + ((rc = setsockopt(s, SOL_SOCKET, SO_KEEPALIVE,(char*) &opt, sizeof(int))) == -1) || + ((rc = setsockopt(s, IPPROTO_TCP, TCP_KEEPINTVL,(char*) &opt, sizeof(int))) == -1) + ); +} + +" + ZMQ_HAVE_TCP_KEEPINTVL) +endmacro() + + +macro(zmq_check_tcp_keepalive) + message(STATUS "Checking whether TCP_KEEPALIVE is supported") + check_c_source_runs( + " +#include +#include +#include +#include + +int main(int argc, char *argv []) +{ + int s, rc, opt = 1; + return( + ((s = socket(PF_INET, SOCK_STREAM, 0)) == -1) || + ((rc = setsockopt(s, SOL_SOCKET, SO_KEEPALIVE,(char*) &opt, sizeof(int))) == -1) || + ((rc = setsockopt(s, IPPROTO_TCP, TCP_KEEPALIVE,(char*) &opt, sizeof(int))) == -1) + ); +} +" + ZMQ_HAVE_TCP_KEEPALIVE) +endmacro() diff --git a/cmake/Modules/zmq_version.cpp b/cmake/Modules/zmq_version.cpp deleted file mode 100644 index 120fd5c2..00000000 --- a/cmake/Modules/zmq_version.cpp +++ /dev/null @@ -1,31 +0,0 @@ -/* - Copyright (c) 2007-2012 iMatix Corporation - Copyright (c) 2009-2011 250bpm s.r.o. - Copyright (c) 2007-2011 Other contributors as noted in the AUTHORS file - - This file is part of 0MQ. - - 0MQ is free software; you can redistribute it and/or modify it under - the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - 0MQ is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#include "zmq.h" - -#include - -int main () -{ - printf ("%d.%d.%d\n", ZMQ_VERSION_MAJOR, ZMQ_VERSION_MINOR, ZMQ_VERSION_PATCH); - return 0; -} - diff --git a/perf/inproc_lat.cpp b/perf/inproc_lat.cpp index 6c1b19ec..626d7e8e 100644 --- a/perf/inproc_lat.cpp +++ b/perf/inproc_lat.cpp @@ -26,7 +26,7 @@ #include #include -#include "../src/platform.hpp" +#include "platform.hpp" #if defined ZMQ_HAVE_WINDOWS #include diff --git a/perf/inproc_thr.cpp b/perf/inproc_thr.cpp index f5bd8a25..22116fc1 100644 --- a/perf/inproc_thr.cpp +++ b/perf/inproc_thr.cpp @@ -26,7 +26,7 @@ #include #include -#include "../src/platform.hpp" +#include "platform.hpp" #if defined ZMQ_HAVE_WINDOWS #include diff --git a/src/decoder.hpp b/src/decoder.hpp index 4ed2eb31..7235045a 100644 --- a/src/decoder.hpp +++ b/src/decoder.hpp @@ -163,7 +163,7 @@ namespace zmq return false; } - inline bool message_ready_size (size_t msg_sz) + inline bool message_ready_size (size_t /* msg_sz */) { zmq_assert (false); return false; diff --git a/src/i_decoder.hpp b/src/i_decoder.hpp index 789df6de..bb53b725 100644 --- a/src/i_decoder.hpp +++ b/src/i_decoder.hpp @@ -30,8 +30,9 @@ namespace zmq // Interface to be implemented by message decoder. - struct i_decoder + class i_decoder { + public: virtual ~i_decoder () {} virtual void set_msg_sink (i_msg_sink *msg_sink_) = 0; diff --git a/src/i_msg_sink.hpp b/src/i_msg_sink.hpp index 2b1a8c40..4a86023c 100644 --- a/src/i_msg_sink.hpp +++ b/src/i_msg_sink.hpp @@ -29,8 +29,9 @@ namespace zmq // Interface to be implemented by message sink. - struct i_msg_sink + class i_msg_sink { + public: virtual ~i_msg_sink () {} // Delivers a message. Returns 0 if successful; -1 otherwise. diff --git a/src/i_msg_source.hpp b/src/i_msg_source.hpp index a6956c1c..c6d7b74c 100644 --- a/src/i_msg_source.hpp +++ b/src/i_msg_source.hpp @@ -29,8 +29,9 @@ namespace zmq // Interface to be implemented by message source. - struct i_msg_source + class i_msg_source { + public: virtual ~i_msg_source () {} // Fetch a message. Returns 0 if successful; -1 otherwise. diff --git a/src/ip.cpp b/src/ip.cpp index 45e54984..0133efa4 100644 --- a/src/ip.cpp +++ b/src/ip.cpp @@ -73,11 +73,11 @@ zmq::fd_t zmq::open_socket (int domain_, int type_, int protocol_) void zmq::unblock_socket (fd_t s_) { -#ifdef ZMQ_HAVE_WINDOWS +#if defined ZMQ_HAVE_WINDOWS u_long nonblock = 1; int rc = ioctlsocket (s_, FIONBIO, &nonblock); wsa_assert (rc != SOCKET_ERROR); -#elif ZMQ_HAVE_OPENVMS +#elif defined ZMQ_HAVE_OPENVMS int nonblock = 1; int rc = ioctl (s_, FIONBIO, &nonblock); errno_assert (rc != -1); @@ -92,6 +92,8 @@ void zmq::unblock_socket (fd_t s_) void zmq::enable_ipv4_mapping (fd_t s_) { + (void) s_; + #ifdef IPV6_V6ONLY #ifdef ZMQ_HAVE_WINDOWS DWORD flag = 0; @@ -107,3 +109,4 @@ void zmq::enable_ipv4_mapping (fd_t s_) #endif #endif } + diff --git a/src/libzmq.pc.cmake.in b/src/libzmq.pc.cmake.in new file mode 100644 index 00000000..ac25909b --- /dev/null +++ b/src/libzmq.pc.cmake.in @@ -0,0 +1,10 @@ +prefix=@CMAKE_INSTALL_PREFIX@ +exec_prefix=@CMAKE_INSTALL_PREFIX@ +libdir=@CMAKE_INSTALL_PREFIX@/lib +includedir=@CMAKE_INSTALL_PREFIX@/include + +Name: libzmq +Description: 0MQ c++ library +Version: @ZMQ_VERSION_MAJOR@.@ZMQ_VERSION_MINOR@.@ZMQ_VERSION_PATCH@ +Libs: -L${libdir} -lzmq +Cflags: -I@CMAKE_INSTALL_PREFIX@/include diff --git a/src/object.cpp b/src/object.cpp index 57e6ea81..814ec08c 100644 --- a/src/object.cpp +++ b/src/object.cpp @@ -124,6 +124,7 @@ void zmq::object_t::process_command (command_t &cmd_) process_reaped (); break; + case command_t::done: default: zmq_assert (false); } diff --git a/src/options.cpp b/src/options.cpp index 84e95f42..4a371693 100644 --- a/src/options.cpp +++ b/src/options.cpp @@ -320,20 +320,23 @@ int zmq::options_t::setsockopt (int option_, const void *optval_, else { std::string filter_str ((const char*) optval_, optvallen_); - tcp_address_mask_t filter; - int rc = filter.resolve (filter_str.c_str (), ipv4only ? true : false); + tcp_address_mask_t mask; + int rc = mask.resolve (filter_str.c_str (), ipv4only ? true : false); if (rc != 0) { errno = EINVAL; return -1; } - tcp_accept_filters.push_back(filter); + tcp_accept_filters.push_back(mask); return 0; } } + default: + { + errno = EINVAL; + return -1; + } } - errno = EINVAL; - return -1; } int zmq::options_t::getsockopt (int option_, void *optval_, size_t *optvallen_) diff --git a/src/signaler.cpp b/src/signaler.cpp index 5c86a6aa..f199d08c 100644 --- a/src/signaler.cpp +++ b/src/signaler.cpp @@ -206,8 +206,8 @@ void zmq::signaler_t::recv () // one, return it back to the eventfd object. if (unlikely (dummy == 2)) { const uint64_t inc = 1; - ssize_t sz = write (w, &inc, sizeof (inc)); - errno_assert (sz == sizeof (inc)); + ssize_t sz2 = write (w, &inc, sizeof (inc)); + errno_assert (sz2 == sizeof (inc)); return; } @@ -238,8 +238,10 @@ int zmq::signaler_t::make_fdpair (fd_t *r_, fd_t *w_) return 0; #elif defined ZMQ_HAVE_WINDOWS - SECURITY_DESCRIPTOR sd = {0}; - SECURITY_ATTRIBUTES sa = {0}; + SECURITY_DESCRIPTOR sd; + SECURITY_ATTRIBUTES sa; + memset (&sd, 0, sizeof (sd)); + memset (&sa, 0, sizeof (sa)); InitializeSecurityDescriptor(&sd, SECURITY_DESCRIPTOR_REVISION); SetSecurityDescriptorDacl(&sd, TRUE, 0, FALSE); diff --git a/src/socket_base.cpp b/src/socket_base.cpp index e9ea68b4..562d4b30 100644 --- a/src/socket_base.cpp +++ b/src/socket_base.cpp @@ -437,14 +437,14 @@ int zmq::socket_base_t::connect (const char *addr_) // Create a bi-directional pipe to connect the peers. object_t *parents [2] = {this, peer.socket}; - pipe_t *pipes [2] = {NULL, NULL}; + pipe_t *new_pipes [2] = {NULL, NULL}; int hwms [2] = {sndhwm, rcvhwm}; bool delays [2] = {options.delay_on_disconnect, options.delay_on_close}; - int rc = pipepair (parents, pipes, hwms, delays); + int rc = pipepair (parents, new_pipes, hwms, delays); errno_assert (rc == 0); // Attach local end of the pipe to this socket object. - attach_pipe (pipes [0]); + attach_pipe (new_pipes [0]); // If required, send the identity of the local socket to the peer. if (peer.options.recv_identity) { @@ -453,9 +453,9 @@ int zmq::socket_base_t::connect (const char *addr_) errno_assert (rc == 0); memcpy (id.data (), options.identity, options.identity_size); id.set_flags (msg_t::identity); - bool written = pipes [0]->write (&id); + bool written = new_pipes [0]->write (&id); zmq_assert (written); - pipes [0]->flush (); + new_pipes [0]->flush (); } // If required, send the identity of the peer to the local socket. @@ -465,21 +465,21 @@ int zmq::socket_base_t::connect (const char *addr_) errno_assert (rc == 0); memcpy (id.data (), peer.options.identity, peer.options.identity_size); id.set_flags (msg_t::identity); - bool written = pipes [1]->write (&id); + bool written = new_pipes [1]->write (&id); zmq_assert (written); - pipes [1]->flush (); + new_pipes [1]->flush (); } // Attach remote end of the pipe to the peer socket. Note that peer's // seqnum was incremented in find_endpoint function. We don't need it // increased here. - send_bind (peer.socket, pipes [1], false); + send_bind (peer.socket, new_pipes [1], false); // Save last endpoint URI options.last_endpoint.assign (addr_); // remember inproc connections for disconnect - inprocs.insert (inprocs_t::value_type (std::string (addr_), pipes[0])); + inprocs.insert (inprocs_t::value_type (std::string (addr_), new_pipes[0])); return 0; } @@ -540,17 +540,17 @@ int zmq::socket_base_t::connect (const char *addr_) if (options.delay_attach_on_connect != 1 || icanhasall) { // Create a bi-directional pipe. object_t *parents [2] = {this, session}; - pipe_t *pipes [2] = {NULL, NULL}; + pipe_t *new_pipes [2] = {NULL, NULL}; int hwms [2] = {options.sndhwm, options.rcvhwm}; bool delays [2] = {options.delay_on_disconnect, options.delay_on_close}; - rc = pipepair (parents, pipes, hwms, delays); + rc = pipepair (parents, new_pipes, hwms, delays); errno_assert (rc == 0); // Attach local end of the pipe to the socket object. - attach_pipe (pipes [0], icanhasall); + attach_pipe (new_pipes [0], icanhasall); // Attach remote end of the pipe to the session object later on. - session->attach_pipe (pipes [1]); + session->attach_pipe (new_pipes [1]); } // Save last endpoint URI @@ -664,7 +664,7 @@ int zmq::socket_base_t::send (msg_t *msg_, int flags_) return -1; // Compute the time when the timeout should occur. - // If the timeout is infite, don't care. + // If the timeout is infinite, don't care. int timeout = options.sndtimeo; uint64_t end = timeout < 0 ? 0 : (clock.now_ms () + timeout); @@ -746,7 +746,7 @@ int zmq::socket_base_t::recv (msg_t *msg_, int flags_) } // Compute the time when the timeout should occur. - // If the timeout is infite, don't care. + // If the timeout is infinite, don't care. int timeout = options.rcvtimeo; uint64_t end = timeout < 0 ? 0 : (clock.now_ms () + timeout); diff --git a/src/stream_engine.hpp b/src/stream_engine.hpp index 2d83995c..d7505331 100644 --- a/src/stream_engine.hpp +++ b/src/stream_engine.hpp @@ -94,7 +94,7 @@ namespace zmq // Size of the greeting message: // Preamble (10 bytes) + version (1 byte) + socket type (1 byte). - const static size_t greeting_size = 12; + static const size_t greeting_size = 12; // True iff we are registered with an I/O poller. bool io_enabled; diff --git a/src/tcp_listener.cpp b/src/tcp_listener.cpp index 4ee88d3d..3cd29b6c 100644 --- a/src/tcp_listener.cpp +++ b/src/tcp_listener.cpp @@ -240,7 +240,8 @@ zmq::fd_t zmq::tcp_listener_t::accept () // Accept one connection and deal with different failure modes. zmq_assert (s != retired_fd); - struct sockaddr_storage ss = {}; + struct sockaddr_storage ss; + memset (&ss, 0, sizeof (ss)); #ifdef ZMQ_HAVE_HPUX int ss_len = sizeof (ss); #else diff --git a/src/zmq.cpp b/src/zmq.cpp index 72bed06c..6a74989b 100644 --- a/src/zmq.cpp +++ b/src/zmq.cpp @@ -56,7 +56,7 @@ // XSI vector I/O -#if ZMQ_HAVE_UIO +#if defined ZMQ_HAVE_UIO #include #else struct iovec { @@ -980,7 +980,7 @@ int zmq_proxy (void *frontend_, void *backend_, void *control_) // The deprecated device functionality -int zmq_device (int type, void *frontend_, void *backend_) +int zmq_device (int /* type */, void *frontend_, void *backend_) { return zmq::proxy ( (zmq::socket_base_t*) frontend_, @@ -989,7 +989,7 @@ int zmq_device (int type, void *frontend_, void *backend_) // Callback to free socket event data -void zmq_free_event (void *event_data, void *hint) +void zmq_free_event (void *event_data, void * /* hint */) { zmq_event_t *event = (zmq_event_t *) event_data;