call pkg-config fallback FindZeroMQ.cmake

and add it to CMAKE_MODULE_PATH on failed load

this allows downstream packages that have loaded cppzmq to call find_package(ZeroMQ) and succeed without shipping their own copy of the fallback.

Additionally, a check for if the libzmq target is defined avoids duplicate definitions when called multiple times
This commit is contained in:
Min RK 2018-01-13 14:13:38 -08:00
parent 249b4a09a7
commit f4c0c5e6a3
2 changed files with 15 additions and 10 deletions

View File

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

View File

@ -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()