From e7a92a5389b99a8465f50a0c9ce710850b4ceca7 Mon Sep 17 00:00:00 2001 From: "FeRD (Frank Dana)" Date: Wed, 2 Oct 2019 09:30:06 -0400 Subject: [PATCH 1/2] Bindings: Pick up include dirs from targets --- src/bindings/python/CMakeLists.txt | 9 ++++++++- src/bindings/ruby/CMakeLists.txt | 7 +++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/bindings/python/CMakeLists.txt b/src/bindings/python/CMakeLists.txt index 5c143e0b..bc07571f 100644 --- a/src/bindings/python/CMakeLists.txt +++ b/src/bindings/python/CMakeLists.txt @@ -55,6 +55,13 @@ if (PYTHONLIBS_FOUND AND PYTHONINTERP_FOUND) separate_arguments(sw_flags UNIX_COMMAND ${SWIG_CXX_FLAGS}) set_property(SOURCE openshot.i PROPERTY GENERATED_COMPILE_OPTIONS ${sw_flags}) + ### Take include dirs from target, automatically if possible + if (CMAKE_VERSION VERSION_GREATER 3.13) + set_property(SOURCE openshot.i PROPERTY USE_TARGET_INCLUDE_DIRECTORIES True) + else () + set_property(SOURCE openshot.i PROPERTY INCLUDE_DIRECTORIES $) + endif () + ### Add the SWIG interface file (which defines all the SWIG methods) if (CMAKE_VERSION VERSION_LESS 3.8.0) swig_add_module(pyopenshot python openshot.i) @@ -68,7 +75,7 @@ if (PYTHONLIBS_FOUND AND PYTHONINTERP_FOUND) ### Link the new python wrapper library with libopenshot target_link_libraries(${SWIG_MODULE_pyopenshot_REAL_NAME} - ${PYTHON_LIBRARIES} openshot) + PUBLIC ${PYTHON_LIBRARIES} openshot) ### Check if the following Debian-friendly python module path exists SET(PYTHON_MODULE_PATH "${CMAKE_INSTALL_PREFIX}/lib/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}/site-packages") diff --git a/src/bindings/ruby/CMakeLists.txt b/src/bindings/ruby/CMakeLists.txt index c7eb1d78..0a9fe6de 100644 --- a/src/bindings/ruby/CMakeLists.txt +++ b/src/bindings/ruby/CMakeLists.txt @@ -56,6 +56,13 @@ IF (RUBY_FOUND) separate_arguments(sw_flags UNIX_COMMAND ${SWIG_CXX_FLAGS}) set_property(SOURCE openshot.i PROPERTY GENERATED_COMPILE_OPTIONS ${sw_flags}) + ### Take include dirs from target, automatically if possible + if (CMAKE_VERSION VERSION_GREATER 3.13) + set_property(SOURCE openshot.i PROPERTY USE_TARGET_INCLUDE_DIRECTORIES True) + else () + set_property(SOURCE openshot.i PROPERTY INCLUDE_DIRECTORIES $) + endif () + ### Add the SWIG interface file (which defines all the SWIG methods) if (CMAKE_VERSION VERSION_LESS 3.8.0) swig_add_module(rbopenshot ruby openshot.i) From a1034046a2c17df4c6d0bb01f447597b590bb2b1 Mon Sep 17 00:00:00 2001 From: "FeRD (Frank Dana)" Date: Sat, 26 Oct 2019 06:44:48 -0400 Subject: [PATCH 2/2] ZeroMQ: Use IMPORTED targets - Adopt FindZeroMQ.cmake from cppzmq, and use its `libzmq` target - Also use `cppzmq` target, if created --- cmake/Modules/FindZeroMQ.cmake | 39 ++++++++++++++++++++++++++++++++++ src/CMakeLists.txt | 29 +++++++++++++------------ tests/CMakeLists.txt | 14 ------------ 3 files changed, 54 insertions(+), 28 deletions(-) create mode 100644 cmake/Modules/FindZeroMQ.cmake 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 398d6154..d6aae2ce 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -138,19 +138,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) @@ -291,6 +278,21 @@ 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} @@ -298,7 +300,6 @@ SET ( REQUIRED_LIBRARIES ${QT_LIBRARIES} ${PROFILER} ${JSONCPP_LIBRARY} - ${ZMQ_LIBRARIES} ) IF (RESVG_FOUND) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 0bfd56d8..d8ba0bce 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -128,20 +128,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)