Skip to content

Commit a103404

Browse files
committed
ZeroMQ: Use IMPORTED targets
- Adopt FindZeroMQ.cmake from cppzmq, and use its `libzmq` target - Also use `cppzmq` target, if created
1 parent e7a92a5 commit a103404

File tree

3 files changed

+54
-28
lines changed

3 files changed

+54
-28
lines changed

cmake/Modules/FindZeroMQ.cmake

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
set(PKG_CONFIG_USE_CMAKE_PREFIX_PATH ON)
2+
find_package(PkgConfig)
3+
pkg_check_modules(PC_LIBZMQ QUIET libzmq)
4+
5+
set(ZeroMQ_VERSION ${PC_LIBZMQ_VERSION})
6+
find_path(ZeroMQ_INCLUDE_DIR zmq.h PATHS ${PC_LIBZMQ_INCLUDE_DIRS} $ENV{ZMQDIR})
7+
8+
find_library(ZeroMQ_LIBRARY NAMES libzmq.so libzmq.dylib libzmq.dll
9+
PATHS ${PC_LIBZMQ_LIBDIR} ${PC_LIBZMQ_LIBRARY_DIRS} $ENV{ZMQDIR})
10+
find_library(ZeroMQ_STATIC_LIBRARY NAMES libzmq-static.a libzmq.a libzmq.dll.a
11+
PATHS ${PC_LIBZMQ_LIBDIR} ${PC_LIBZMQ_LIBRARY_DIRS} $ENV{ZMQDIR})
12+
13+
if(ZeroMQ_LIBRARY OR ZeroMQ_STATIC_LIBRARY)
14+
set(ZeroMQ_FOUND ON)
15+
endif()
16+
17+
if (TARGET libzmq)
18+
# avoid errors defining targets twice
19+
return()
20+
endif()
21+
22+
set(ZeroMQ_INCLUDE_DIRS ${ZeroMQ_INCLUDE_DIR})
23+
list(APPEND ZeroMQ_INCLUDE_DIRS ${PC_LIBZMQ_INCLUDE_DIRS})
24+
list(REMOVE_DUPLICATES ZeroMQ_INCLUDE_DIRS)
25+
26+
add_library(libzmq SHARED IMPORTED)
27+
set_property(TARGET libzmq PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${ZeroMQ_INCLUDE_DIRS})
28+
set_property(TARGET libzmq PROPERTY IMPORTED_LOCATION ${ZeroMQ_LIBRARY})
29+
30+
add_library(libzmq-static STATIC IMPORTED ${ZeroMQ_INCLUDE_DIRS})
31+
set_property(TARGET libzmq-static PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${ZeroMQ_INCLUDE_DIRS})
32+
set_property(TARGET libzmq-static PROPERTY IMPORTED_LOCATION ${ZeroMQ_STATIC_LIBRARY})
33+
34+
include(FindPackageHandleStandardArgs)
35+
find_package_handle_standard_args(ZeroMQ
36+
REQUIRED_VARS
37+
ZeroMQ_LIBRARY ZeroMQ_INCLUDE_DIRS
38+
VERSION_VAR
39+
ZeroMQ_VERSION)

src/CMakeLists.txt

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -138,19 +138,6 @@ IF (ENABLE_BLACKMAGIC)
138138
ENDIF (BLACKMAGIC_FOUND)
139139
ENDIF (ENABLE_BLACKMAGIC)
140140

141-
################### ZEROMQ #####################
142-
# Find ZeroMQ library (used for socket communication & logging)
143-
144-
# Some platforms package the header-only cppzmq C++ bindings separately,
145-
# others (Ubuntu) bundle them in with libzmq itself
146-
find_package(cppzmq QUIET)
147-
find_package(ZMQ REQUIRED)
148-
149-
# Include ZeroMQ headers (needed for compile)
150-
include_directories(${ZMQ_INCLUDE_DIRS})
151-
if (cppzmq_FOUND)
152-
include_directories(${cppzmq_INCLUDE_DIRS})
153-
endif()
154141

155142
################### RESVG #####################
156143
# Find resvg library (used for rendering svg files)
@@ -291,14 +278,28 @@ endif()
291278

292279
target_link_libraries(openshot PUBLIC OpenMP::OpenMP_CXX)
293280

281+
################### ZEROMQ #####################
282+
# Find ZeroMQ library (used for socket communication & logging)
283+
find_package(ZeroMQ REQUIRED) # Creates libzmq target
284+
285+
# Some platforms package the header-only cppzmq C++ bindings separately,
286+
# others (Ubuntu) bundle them in with libzmq itself
287+
find_package(cppzmq QUIET) # Creates cppzmq target
288+
289+
# Include ZeroMQ headers (needed for compile)
290+
target_link_libraries(openshot PUBLIC libzmq)
291+
if (TARGET cppzmq)
292+
target_link_libraries(openshot PUBLIC cppzmq)
293+
endif()
294+
295+
294296
############### LINK LIBRARY #################
295297
SET ( REQUIRED_LIBRARIES
296298
${LIBOPENSHOT_AUDIO_LIBRARIES}
297299
${FF_LIBRARIES}
298300
${QT_LIBRARIES}
299301
${PROFILER}
300302
${JSONCPP_LIBRARY}
301-
${ZMQ_LIBRARIES}
302303
)
303304

304305
IF (RESVG_FOUND)

tests/CMakeLists.txt

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -128,20 +128,6 @@ IF (ENABLE_BLACKMAGIC)
128128
ENDIF (ENABLE_BLACKMAGIC)
129129

130130

131-
################### ZEROMQ #####################
132-
# Find ZeroMQ library (used for socket communication & logging)
133-
134-
# Some platforms package the header-only cppzmq C++ bindings separately,
135-
# others (Ubuntu) bundle them in with libzmq itself
136-
find_package(cppzmq QUIET)
137-
FIND_PACKAGE(ZMQ REQUIRED)
138-
139-
# Include ZeroMQ headers (needed for compile)
140-
include_directories(${ZMQ_INCLUDE_DIRS})
141-
if (cppzmq_FOUND)
142-
include_directories(${cppzmq_INCLUDE_DIRS})
143-
endif()
144-
145131
################### RESVG #####################
146132
# Find resvg library (used for rendering svg files)
147133
FIND_PACKAGE(RESVG)

0 commit comments

Comments
 (0)