diff --git a/CMakeLists.txt b/CMakeLists.txt index d6dae4e..dfdadac 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,11 +5,9 @@ find_package(ZeroMQ QUIET) # libzmq autotools install: fallback to pkg-config if(NOT ZeroMQ_FOUND) - include(${CMAKE_CURRENT_LIST_DIR}/libzmqPkgConfigFallback.cmake) -endif() - -if(NOT ZeroMQ_FOUND) - message(FATAL_ERROR "ZeroMQ was NOT found!") + # try again with pkg-config (normal install of zeromq) + list (APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/libzmq-pkg-config) + find_package(ZeroMQ REQUIRED) endif() if (ZeroMQ_FOUND AND (NOT TARGET libzmq OR NOT TARGET libzmq-static)) @@ -60,5 +58,7 @@ install(EXPORT ${PROJECT_NAME}-targets DESTINATION ${CPPZMQ_CMAKECONFIG_INSTALL_DIR}) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake - ${CMAKE_SOURCE_DIR}/libzmqPkgConfigFallback.cmake + ${CMAKE_SOURCE_DIR}/libzmq-pkg-config/FindZeroMQ.cmake DESTINATION ${CPPZMQ_CMAKECONFIG_INSTALL_DIR}) +install(FILES ${CMAKE_SOURCE_DIR}/libzmq-pkg-config/FindZeroMQ.cmake + DESTINATION ${CPPZMQ_CMAKECONFIG_INSTALL_DIR}/libzmq-pkg-config) diff --git a/libzmqPkgConfigFallback.cmake b/libzmq-pkg-config/FindZeroMQ.cmake similarity index 91% rename from libzmqPkgConfigFallback.cmake rename to libzmq-pkg-config/FindZeroMQ.cmake index eae4c7a..f30b9cf 100644 --- a/libzmqPkgConfigFallback.cmake +++ b/libzmq-pkg-config/FindZeroMQ.cmake @@ -7,6 +7,15 @@ find_library(ZeroMQ_LIBRARY NAMES libzmq.so libzmq.dylib libzmq.dll find_library(ZeroMQ_STATIC_LIBRARY NAMES libzmq.a libzmq.dll.a PATHS ${PC_LIBZMQ_LIBDIR} ${PC_LIBZMQ_LIBRARY_DIRS}) +if(ZeroMQ_LIBRARY AND ZeroMQ_STATIC_LIBRARY) + set(ZeroMQ_FOUND ON) +endif() + +if (TARGET libzmq) + # avoid errors defining targets twice + return() +endif() + add_library(libzmq SHARED IMPORTED) set_property(TARGET libzmq PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${PC_LIBZMQ_INCLUDE_DIRS}) set_property(TARGET libzmq PROPERTY IMPORTED_LOCATION ${ZeroMQ_LIBRARY}) @@ -14,7 +23,3 @@ set_property(TARGET libzmq PROPERTY IMPORTED_LOCATION ${ZeroMQ_LIBRARY}) add_library(libzmq-static STATIC IMPORTED ${PC_LIBZMQ_INCLUDE_DIRS}) set_property(TARGET libzmq-static PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${PC_LIBZMQ_INCLUDE_DIRS}) set_property(TARGET libzmq-static PROPERTY IMPORTED_LOCATION ${ZeroMQ_STATIC_LIBRARY}) - -if(ZeroMQ_LIBRARY AND ZeroMQ_STATIC_LIBRARY) - set(ZeroMQ_FOUND ON) -endif()