Skip to content

Commit f4c0c5e

Browse files
committed
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
1 parent 249b4a0 commit f4c0c5e

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

CMakeLists.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@ find_package(ZeroMQ QUIET)
55

66
# libzmq autotools install: fallback to pkg-config
77
if(NOT ZeroMQ_FOUND)
8-
include(${CMAKE_CURRENT_LIST_DIR}/libzmqPkgConfigFallback.cmake)
9-
endif()
10-
11-
if(NOT ZeroMQ_FOUND)
12-
message(FATAL_ERROR "ZeroMQ was NOT found!")
8+
# try again with pkg-config (normal install of zeromq)
9+
list (APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/libzmq-pkg-config)
10+
find_package(ZeroMQ REQUIRED)
1311
endif()
1412

1513
if (ZeroMQ_FOUND AND (NOT TARGET libzmq OR NOT TARGET libzmq-static))
@@ -60,5 +58,7 @@ install(EXPORT ${PROJECT_NAME}-targets
6058
DESTINATION ${CPPZMQ_CMAKECONFIG_INSTALL_DIR})
6159
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
6260
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
63-
${CMAKE_SOURCE_DIR}/libzmqPkgConfigFallback.cmake
61+
${CMAKE_SOURCE_DIR}/libzmq-pkg-config/FindZeroMQ.cmake
6462
DESTINATION ${CPPZMQ_CMAKECONFIG_INSTALL_DIR})
63+
install(FILES ${CMAKE_SOURCE_DIR}/libzmq-pkg-config/FindZeroMQ.cmake
64+
DESTINATION ${CPPZMQ_CMAKECONFIG_INSTALL_DIR}/libzmq-pkg-config)

libzmqPkgConfigFallback.cmake renamed to libzmq-pkg-config/FindZeroMQ.cmake

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,19 @@ find_library(ZeroMQ_LIBRARY NAMES libzmq.so libzmq.dylib libzmq.dll
77
find_library(ZeroMQ_STATIC_LIBRARY NAMES libzmq.a libzmq.dll.a
88
PATHS ${PC_LIBZMQ_LIBDIR} ${PC_LIBZMQ_LIBRARY_DIRS})
99

10+
if(ZeroMQ_LIBRARY AND ZeroMQ_STATIC_LIBRARY)
11+
set(ZeroMQ_FOUND ON)
12+
endif()
13+
14+
if (TARGET libzmq)
15+
# avoid errors defining targets twice
16+
return()
17+
endif()
18+
1019
add_library(libzmq SHARED IMPORTED)
1120
set_property(TARGET libzmq PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${PC_LIBZMQ_INCLUDE_DIRS})
1221
set_property(TARGET libzmq PROPERTY IMPORTED_LOCATION ${ZeroMQ_LIBRARY})
1322

1423
add_library(libzmq-static STATIC IMPORTED ${PC_LIBZMQ_INCLUDE_DIRS})
1524
set_property(TARGET libzmq-static PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${PC_LIBZMQ_INCLUDE_DIRS})
1625
set_property(TARGET libzmq-static PROPERTY IMPORTED_LOCATION ${ZeroMQ_STATIC_LIBRARY})
17-
18-
if(ZeroMQ_LIBRARY AND ZeroMQ_STATIC_LIBRARY)
19-
set(ZeroMQ_FOUND ON)
20-
endif()

0 commit comments

Comments
 (0)