Skip to content

Commit 4311b89

Browse files
authored
Merge pull request #348 from ferdnyc/zmq-targets
ZeroMQ: Use IMPORTED targets
2 parents 43bc0eb + 5c40094 commit 4311b89

File tree

3 files changed

+53
-28
lines changed

3 files changed

+53
-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: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -123,19 +123,6 @@ IF (ENABLE_BLACKMAGIC)
123123
ENDIF (BLACKMAGIC_FOUND)
124124
ENDIF (ENABLE_BLACKMAGIC)
125125

126-
################### ZEROMQ #####################
127-
# Find ZeroMQ library (used for socket communication & logging)
128-
129-
# Some platforms package the header-only cppzmq C++ bindings separately,
130-
# others (Ubuntu) bundle them in with libzmq itself
131-
find_package(cppzmq QUIET)
132-
find_package(ZMQ REQUIRED)
133-
134-
# Include ZeroMQ headers (needed for compile)
135-
include_directories(${ZMQ_INCLUDE_DIRS})
136-
if (cppzmq_FOUND)
137-
include_directories(${cppzmq_INCLUDE_DIRS})
138-
endif()
139126

140127
################### RESVG #####################
141128
# Find resvg library (used for rendering svg files)
@@ -330,13 +317,26 @@ endif()
330317

331318
target_link_libraries(openshot PUBLIC OpenMP::OpenMP_CXX)
332319

320+
################### ZEROMQ #####################
321+
# Find ZeroMQ library (used for socket communication & logging)
322+
find_package(ZeroMQ REQUIRED) # Creates libzmq target
323+
324+
# Some platforms package the header-only cppzmq C++ bindings separately,
325+
# others (Ubuntu) bundle them in with libzmq itself
326+
find_package(cppzmq QUIET) # Creates cppzmq target
327+
328+
# Include ZeroMQ headers (needed for compile)
329+
target_link_libraries(openshot PUBLIC libzmq)
330+
if (TARGET cppzmq)
331+
target_link_libraries(openshot PUBLIC cppzmq)
332+
endif()
333+
333334

334335
############### LINK LIBRARY #################
335336
SET ( REQUIRED_LIBRARIES
336337
${LIBOPENSHOT_AUDIO_LIBRARIES}
337338
${QT_LIBRARIES}
338339
${PROFILER}
339-
${ZMQ_LIBRARIES}
340340
)
341341

342342
IF (RESVG_FOUND)

tests/CMakeLists.txt

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

116116

117-
################### ZEROMQ #####################
118-
# Find ZeroMQ library (used for socket communication & logging)
119-
120-
# Some platforms package the header-only cppzmq C++ bindings separately,
121-
# others (Ubuntu) bundle them in with libzmq itself
122-
find_package(cppzmq QUIET)
123-
FIND_PACKAGE(ZMQ REQUIRED)
124-
125-
# Include ZeroMQ headers (needed for compile)
126-
include_directories(${ZMQ_INCLUDE_DIRS})
127-
if (cppzmq_FOUND)
128-
include_directories(${cppzmq_INCLUDE_DIRS})
129-
endif()
130-
131117
################### RESVG #####################
132118
# Find resvg library (used for rendering svg files)
133119
FIND_PACKAGE(RESVG)

0 commit comments

Comments
 (0)