diff --git a/CMakeLists.txt b/CMakeLists.txt index c4d00166b..291b19164 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,6 +12,8 @@ include(cmake/project_version.cmake) #functions to add compiler flags include(cmake/SlsAddFlag.cmake) +include(cmake/SlsFindZeroMQ.cmake) + # Include additional modules that are used unconditionally include(GNUInstallDirs) @@ -186,42 +188,11 @@ install(TARGETS slsProjectOptions slsProjectWarnings rapidjson set(CMAKE_POSITION_INDEPENDENT_CODE ON) set(CMAKE_INSTALL_RPATH $ORIGIN) -# set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE) set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE) -set(ZeroMQ_HINT "" CACHE STRING "Hint where ZeroMQ could be found") -#Adapted from: https://github.com/zeromq/cppzmq/ -if (NOT TARGET libzmq) - if(ZeroMQ_HINT) - message(STATUS "Looking for ZeroMQ in: ${ZeroMQ_HINT}") - find_package(ZeroMQ 4 - NO_DEFAULT_PATH - HINTS ${ZeroMQ_DIR} - ) - else() - find_package(ZeroMQ 4 QUIET) - endif() - - # libzmq autotools install: fallback to pkg-config - if(NOT ZeroMQ_FOUND) - message(STATUS "CMake libzmq package not found, trying again with pkg-config (normal install of zeromq)") - list (APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/libzmq-pkg-config) - find_package(ZeroMQ 4 REQUIRED) - endif() +custom_find_zmq() - # TODO "REQUIRED" above should already cause a fatal failure if not found, but this doesn't seem to work - if(NOT ZeroMQ_FOUND) - message(FATAL_ERROR "ZeroMQ was not found, neither as a CMake package nor via pkg-config") - endif() - - if (ZeroMQ_FOUND AND NOT TARGET libzmq) - message(FATAL_ERROR "ZeroMQ version not supported!") - endif() -endif() - -get_target_property(VAR libzmq INTERFACE_INCLUDE_DIRECTORIES) -message(STATUS "zmq: ${VAR}") if (SLS_USE_TESTS) enable_testing() diff --git a/cmake/SlsFindZeroMQ.cmake b/cmake/SlsFindZeroMQ.cmake new file mode 100644 index 000000000..74b4ce1bb --- /dev/null +++ b/cmake/SlsFindZeroMQ.cmake @@ -0,0 +1,38 @@ +function(custom_find_zmq) + set(ZeroMQ_HINT "" CACHE STRING "Hint where ZeroMQ could be found") + #Adapted from: https://github.com/zeromq/cppzmq/ + if (NOT TARGET libzmq) + if(ZeroMQ_HINT) + message(STATUS "Looking for ZeroMQ in: ${ZeroMQ_HINT}") + find_package(ZeroMQ 4 + NO_DEFAULT_PATH + HINTS ${ZeroMQ_DIR} + ) + else() + find_package(ZeroMQ 4 QUIET) + endif() + + # libzmq autotools install: fallback to pkg-config + if(ZeroMQ_FOUND) + message(STATUS "Found libzmq using find_package") + else() + message(STATUS "CMake libzmq package not found, trying again with pkg-config (normal install of zeromq)") + list (APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake/libzmq-pkg-config) + find_package(ZeroMQ 4 REQUIRED) + endif() + + # TODO "REQUIRED" above should already cause a fatal failure if not found, but this doesn't seem to work + if(NOT ZeroMQ_FOUND) + message(FATAL_ERROR "ZeroMQ was not found, neither as a CMake package nor via pkg-config") + endif() + + if (ZeroMQ_FOUND AND NOT TARGET libzmq) + message(FATAL_ERROR "ZeroMQ version not supported!") + endif() + endif() + + get_target_property(VAR libzmq IMPORTED_LOCATION) + message(STATUS "Using libzmq: ${VAR}") + + +endfunction() \ No newline at end of file diff --git a/libzmq-pkg-config/FindZeroMQ.cmake b/cmake/libzmq-pkg-config/FindZeroMQ.cmake similarity index 95% rename from libzmq-pkg-config/FindZeroMQ.cmake rename to cmake/libzmq-pkg-config/FindZeroMQ.cmake index 9d9a4dfbf..76fb69dd0 100755 --- a/libzmq-pkg-config/FindZeroMQ.cmake +++ b/cmake/libzmq-pkg-config/FindZeroMQ.cmake @@ -11,6 +11,7 @@ find_library(ZeroMQ_STATIC_LIBRARY NAMES libzmq-static.a libzmq.a libzmq.dll.a if(ZeroMQ_LIBRARY OR ZeroMQ_STATIC_LIBRARY) set(ZeroMQ_FOUND ON) + message(STATUS "Found libzmq using PkgConfig") endif() if (TARGET libzmq)