|
| 1 | +# ************************************************************************** |
| 2 | +# * Copyright(c) 1998-2014, ALICE Experiment at CERN, All rights reserved. * |
| 3 | +# * * |
| 4 | +# * Author: The ALICE Off-line Project. * |
| 5 | +# * Contributors are mentioned in the code where appropriate. * |
| 6 | +# * * |
| 7 | +# * Permission to use, copy, modify and distribute this software and its * |
| 8 | +# * documentation strictly for non-commercial purposes is hereby granted * |
| 9 | +# * without fee, provided that the above copyright notice appears in all * |
| 10 | +# * copies and that both the copyright notice and this permission notice * |
| 11 | +# * appear in the supporting documentation. The authors make no claims * |
| 12 | +# * about the suitability of this software for any purpose. It is * |
| 13 | +# * provided "as is" without express or implied warranty. * |
| 14 | +# ************************************************************************** |
| 15 | + |
| 16 | +# Checks for a ZeroMQ installation. Enables ZeroMQ by default if found on the |
| 17 | +# system and with the right version. |
| 18 | +# |
| 19 | +# Point to a custom ZeroMQ installation with -DZEROMQ=<path>: in that case, if |
| 20 | +# ZeroMQ is not found or has not the right version, a fatal error is raised. |
| 21 | +# |
| 22 | +# Variables set: |
| 23 | +# |
| 24 | +# - ZEROMQ_FOUND True if ZeroMQ is found |
| 25 | +# - ZEROMQ_INCLUDE_DIR Where to find ZeroMQ include directory |
| 26 | +# - ZEROMQ_LIBRARIES List of libraries when using ZeroMQ |
| 27 | +# - ZEROMQ_VERSION ZeroMQ version, major.minor.patches |
| 28 | +# - ZEROMQ_VERSION_MAJOR Major component of version |
| 29 | +# - ZEROMQ_VERSION_MINOR Minor component of version |
| 30 | +# - ZEROMQ_VERSION_MAJOR Patches component of version |
| 31 | + |
| 32 | +set(ZEROMQ_VERSION_MIN "4.0.0") |
| 33 | + |
| 34 | +message(STATUS "Checking for ZeroMQ ${ZEROMQ}") |
| 35 | + |
| 36 | +set(ZEROMQ_FOUND FALSE) |
| 37 | + |
| 38 | +if(ZEROMQ) |
| 39 | + # ZeroMQ is installed in a custom place |
| 40 | + find_library(ZEROMQ_LIBRARIES NAMES zmq |
| 41 | + PATHS ${ZEROMQ}/lib |
| 42 | + NO_DEFAULT_PATH |
| 43 | + DOC "Path to libzmq)" |
| 44 | + ) |
| 45 | + find_path(ZEROMQ_INCLUDE_DIR NAMES zmq.h zmq_utils.h |
| 46 | + PATHS ${ZEROMQ}/include |
| 47 | + NO_DEFAULT_PATH |
| 48 | + DOC "Path to ZeroMQ include header files." |
| 49 | + ) |
| 50 | +else(ZEROMQ) |
| 51 | + # Check is the library is installed on the system |
| 52 | + find_library(ZEROMQ_LIBRARIES NAMES zmq |
| 53 | + HINTS ENV LD_LIBRARY_PATH |
| 54 | + DOC "Path to libzmq)" |
| 55 | + ) |
| 56 | + string(REPLACE "lib/libzmq.so" "" INCLUDE_HINT ${ZEROMQ_LIBRARIES}) |
| 57 | + find_path(ZEROMQ_INCLUDE_DIR NAMES zmq_utils.h |
| 58 | + HINTS "${INCLUDE_HINT}include" |
| 59 | + DOC "Path to ZeroMQ include header files." |
| 60 | + ) |
| 61 | +endif(ZEROMQ) |
| 62 | + |
| 63 | +mark_as_advanced(ZEROMQ_LIBRARIES ZEROMQ_INCLUDE_DIR) |
| 64 | + |
| 65 | +# Did we find ZeroMQ? We need to parse its version. |
| 66 | +if(ZEROMQ_INCLUDE_DIR) |
| 67 | + message(STATUS "ZeroMQ include path: ${ZEROMQ_INCLUDE_DIR}") |
| 68 | +endif() |
| 69 | +if(ZEROMQ_LIBRARIES) |
| 70 | + message(STATUS "ZeroMQ libraries: ${ZEROMQ_LIBRARIES}") |
| 71 | +endif() |
| 72 | +if(ZEROMQ_INCLUDE_DIR AND ZEROMQ_LIBRARIES) |
| 73 | + file(READ "${ZEROMQ_INCLUDE_DIR}/zmq.h" zmqh) |
| 74 | + |
| 75 | + string(REGEX MATCH "#define +ZMQ_VERSION_MAJOR +([0-9]+)" zmqv "${zmqh}") |
| 76 | + set(ZEROMQ_VERSION_MAJOR "${CMAKE_MATCH_1}") |
| 77 | + string(REGEX MATCH "#define +ZMQ_VERSION_MINOR +([0-9]+)" zmqv "${zmqh}") |
| 78 | + set(ZEROMQ_VERSION_MINOR "${CMAKE_MATCH_1}") |
| 79 | + string(REGEX MATCH "#define +ZMQ_VERSION_PATCH +([0-9]+)" zmqv "${zmqh}") |
| 80 | + set(ZEROMQ_VERSION_PATCH "${CMAKE_MATCH_1}") |
| 81 | + |
| 82 | + unset(zmqh) |
| 83 | + unset(zmqv) |
| 84 | + |
| 85 | + set(ZEROMQ_VERSION "${ZEROMQ_VERSION_MAJOR}.${ZEROMQ_VERSION_MINOR}.${ZEROMQ_VERSION_PATCH}") |
| 86 | + message(STATUS "ZeroMQ version: ${ZEROMQ_VERSION}") |
| 87 | + |
| 88 | + if(ZEROMQ_VERSION VERSION_GREATER "${ZEROMQ_VERSION_MIN}") |
| 89 | + # Version OK. |
| 90 | + set(ZEROMQ_FOUND TRUE) |
| 91 | + add_definitions(-DZMQ_FOUND) |
| 92 | + message(STATUS "ZeroMQ version ${ZEROMQ_VERSION} (> ${ZEROMQ_VERSION_MIN}) found") |
| 93 | + elseif(ZEROMQ) |
| 94 | + # Version not OK and explicitly requested: fatal. |
| 95 | + message(FATAL_ERROR "ZeroMQ in ${ZEROMQ} has version ${ZEROMQ_VERSION} <= ${ZEROMQ_VERSION_MIN}") |
| 96 | + else() |
| 97 | + message(STATUS "ZeroMQ found but version ${ZEROMQ_VERSION} <= ${ZEROMQ_VERSION_MIN}. Disabling ZeroMQ support.") |
| 98 | + endif() |
| 99 | +elseif(ZEROMQ) |
| 100 | + # ZeroMQ not found and explicitly requested: fatal. |
| 101 | + message(FATAL_ERROR "ZeroMQ not found in ${ZEROMQ}.") |
| 102 | +elseif(ZEROMQ_LIBRARIES) |
| 103 | + # ZeroMQ libraries found in system, but headers were not. |
| 104 | + message(STATUS "ZeroMQ headers not found. Please install the development package and the cppzmq interface. Disabling ZeroMQ support.") |
| 105 | +else() |
| 106 | + message(STATUS "ZeroMQ not found. Disabling ZeroMQ support.") |
| 107 | +endif() |
0 commit comments