diff --git a/cmake/Modules/FindZeroMQ.cmake b/cmake/Modules/FindZeroMQ.cmake new file mode 100644 index 00000000..38f522f3 --- /dev/null +++ b/cmake/Modules/FindZeroMQ.cmake @@ -0,0 +1,39 @@ +set(PKG_CONFIG_USE_CMAKE_PREFIX_PATH ON) +find_package(PkgConfig) +pkg_check_modules(PC_LIBZMQ QUIET libzmq) + +set(ZeroMQ_VERSION ${PC_LIBZMQ_VERSION}) +find_path(ZeroMQ_INCLUDE_DIR zmq.h PATHS ${PC_LIBZMQ_INCLUDE_DIRS} $ENV{ZMQDIR}) + +find_library(ZeroMQ_LIBRARY NAMES libzmq.so libzmq.dylib libzmq.dll +PATHS ${PC_LIBZMQ_LIBDIR} ${PC_LIBZMQ_LIBRARY_DIRS} $ENV{ZMQDIR}) +find_library(ZeroMQ_STATIC_LIBRARY NAMES libzmq-static.a libzmq.a libzmq.dll.a + PATHS ${PC_LIBZMQ_LIBDIR} ${PC_LIBZMQ_LIBRARY_DIRS} $ENV{ZMQDIR}) + +if(ZeroMQ_LIBRARY OR ZeroMQ_STATIC_LIBRARY) + set(ZeroMQ_FOUND ON) +endif() + +if (TARGET libzmq) + # avoid errors defining targets twice + return() +endif() + +set(ZeroMQ_INCLUDE_DIRS ${ZeroMQ_INCLUDE_DIR}) +list(APPEND ZeroMQ_INCLUDE_DIRS ${PC_LIBZMQ_INCLUDE_DIRS}) +list(REMOVE_DUPLICATES ZeroMQ_INCLUDE_DIRS) + +add_library(libzmq SHARED IMPORTED) +set_property(TARGET libzmq PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${ZeroMQ_INCLUDE_DIRS}) +set_property(TARGET libzmq PROPERTY IMPORTED_LOCATION ${ZeroMQ_LIBRARY}) + +add_library(libzmq-static STATIC IMPORTED ${ZeroMQ_INCLUDE_DIRS}) +set_property(TARGET libzmq-static PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${ZeroMQ_INCLUDE_DIRS}) +set_property(TARGET libzmq-static PROPERTY IMPORTED_LOCATION ${ZeroMQ_STATIC_LIBRARY}) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(ZeroMQ + REQUIRED_VARS + ZeroMQ_LIBRARY ZeroMQ_INCLUDE_DIRS + VERSION_VAR + ZeroMQ_VERSION) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9e53a212..c7c097c3 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -123,19 +123,6 @@ IF (ENABLE_BLACKMAGIC) ENDIF (BLACKMAGIC_FOUND) ENDIF (ENABLE_BLACKMAGIC) -################### ZEROMQ ##################### -# Find ZeroMQ library (used for socket communication & logging) - -# Some platforms package the header-only cppzmq C++ bindings separately, -# others (Ubuntu) bundle them in with libzmq itself -find_package(cppzmq QUIET) -find_package(ZMQ REQUIRED) - -# Include ZeroMQ headers (needed for compile) -include_directories(${ZMQ_INCLUDE_DIRS}) -if (cppzmq_FOUND) - include_directories(${cppzmq_INCLUDE_DIRS}) -endif() ################### RESVG ##################### # Find resvg library (used for rendering svg files) @@ -330,13 +317,26 @@ endif() target_link_libraries(openshot PUBLIC OpenMP::OpenMP_CXX) +################### ZEROMQ ##################### +# Find ZeroMQ library (used for socket communication & logging) +find_package(ZeroMQ REQUIRED) # Creates libzmq target + +# Some platforms package the header-only cppzmq C++ bindings separately, +# others (Ubuntu) bundle them in with libzmq itself +find_package(cppzmq QUIET) # Creates cppzmq target + +# Include ZeroMQ headers (needed for compile) +target_link_libraries(openshot PUBLIC libzmq) +if (TARGET cppzmq) + target_link_libraries(openshot PUBLIC cppzmq) +endif() + ############### LINK LIBRARY ################# SET ( REQUIRED_LIBRARIES ${LIBOPENSHOT_AUDIO_LIBRARIES} ${QT_LIBRARIES} ${PROFILER} - ${ZMQ_LIBRARIES} ) IF (RESVG_FOUND) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index b309284a..50360bf3 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -114,20 +114,6 @@ IF (ENABLE_BLACKMAGIC) ENDIF (ENABLE_BLACKMAGIC) -################### ZEROMQ ##################### -# Find ZeroMQ library (used for socket communication & logging) - -# Some platforms package the header-only cppzmq C++ bindings separately, -# others (Ubuntu) bundle them in with libzmq itself -find_package(cppzmq QUIET) -FIND_PACKAGE(ZMQ REQUIRED) - -# Include ZeroMQ headers (needed for compile) -include_directories(${ZMQ_INCLUDE_DIRS}) -if (cppzmq_FOUND) - include_directories(${cppzmq_INCLUDE_DIRS}) -endif() - ################### RESVG ##################### # Find resvg library (used for rendering svg files) FIND_PACKAGE(RESVG)