From 5cfe52b9f7701a209f4fc380396bf4a91f7f1ca0 Mon Sep 17 00:00:00 2001 From: "FeRD (Frank Dana)" Date: Thu, 24 Dec 2020 10:07:08 -0500 Subject: [PATCH] CMake: Add ENABLE_OPENCV option, use targets --- CMakeLists.txt | 1 + bindings/python/CMakeLists.txt | 10 --- src/CMakeLists.txt | 64 ++++++++++--------- .../compileProtobufMessages.sh | 6 -- tests/CMakeLists.txt | 36 ++--------- 5 files changed, 40 insertions(+), 77 deletions(-) delete mode 100644 src/protobuf_messages/compileProtobufMessages.sh diff --git a/CMakeLists.txt b/CMakeLists.txt index 294639bf3..ff71dde75 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -79,6 +79,7 @@ option(ENABLE_COVERAGE "Scan test coverage using gcov and report" OFF) option(ENABLE_DOCS "Build API documentation (requires Doxygen)" ON) option(APPIMAGE_BUILD "Build to install in an AppImage (Linux only)" OFF) option(ENABLE_MAGICK "Use ImageMagick, if available" ON) +option(ENABLE_OPENCV "Build with OpenCV algorithms (requires Boost, Protobuf 3)" ON) # Legacy commandline override if (DISABLE_TESTS) diff --git a/bindings/python/CMakeLists.txt b/bindings/python/CMakeLists.txt index defbd9bdb..b020592bd 100644 --- a/bindings/python/CMakeLists.txt +++ b/bindings/python/CMakeLists.txt @@ -54,16 +54,6 @@ if (CMAKE_VERSION VERSION_LESS 3.12) "${PROJECT_BINARY_DIR}/src") endif() -################ OPENCV ################## -find_package( OpenCV 4 ) -if (OpenCV_FOUND) - message("\nCOMPILING WITH OPENCV\n") - set(CMAKE_SWIG_FLAGS "-DUSE_OPENCV=1") - add_definitions( -DUSE_OPENCV=1 ) -else() - message("\nOPENCV NOT FOUND, SOME FUNCTIONALITIES WILL BE DISABLED\n") -endif() - ### Enable C++ in SWIG set_property(SOURCE openshot.i PROPERTY CPLUSPLUS ON) set_property(SOURCE openshot.i PROPERTY SWIG_MODULE_NAME openshot) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 12eab3b62..0ae1c2ff4 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -392,36 +392,39 @@ if (ENABLE_BLACKMAGIC) endif() ################## OPENCV ################### - -find_package( OpenCV 4 ) -if (OpenCV_FOUND) - message("\nCOMPILING WITH OPENCV\n") - list(APPEND CMAKE_SWIG_FLAGS -DUSE_OPENCV=1) - target_compile_definitions(openshot PUBLIC USE_OPENCV=1) -else() - message("\nOPENCV NOT FOUND, SOME FUNCTIONALITIES WILL BE DISABLED\n") -endif() - -################## PROTOBUF ################## -if (OpenCV_FOUND) - find_package(Protobuf 3) - - if (NOT Protobuf_FOUND) - # Protobuf is required when compiling with opencv - message(FATAL_ERROR "\nPLEASE INSTALL PROTOBUF. Protobuf is required when compiling with opencv.\n") +if(ENABLE_OPENCV) + find_package(OpenCV 4) + if(NOT OpenCV_FOUND) + set(ENABLE_OPENCV FALSE CACHE BOOL + "Build with OpenCV algorithms (requires Boost, Protobuf 3)" FORCE) + else() + find_package(Protobuf 3 REQUIRED) + find_package(Boost REQUIRED) + set(PROTOBUF_SOURCE_FILES + protobuf_messages/objdetectdata.proto + protobuf_messages/stabilizedata.proto + protobuf_messages/trackerdata.proto + ) + protobuf_generate_cpp(ProtoSources ProtoHeaders ${PROTOBUF_SOURCE_FILES}) + # Add OpenCV source files and generated protobuf sources + target_sources(openshot PRIVATE + ${OPENSHOT_CV_SOURCES} + ${ProtoSources} + ${ProtoHeaders} + ) + list(APPEND CMAKE_SWIG_FLAGS -DUSE_OPENCV=1) + target_compile_definitions(openshot PUBLIC USE_OPENCV=1) + target_link_libraries(openshot PUBLIC + opencv_core + opencv_video + opencv_highgui + opencv_dnn + opencv_tracking + protobuf::libprotobuf + ) endif() - - add_subdirectory(protobuf_messages) - - target_include_directories(openshot PUBLIC ${ProtobufMessagePath}) - - # Add OpenCV target sources - target_sources(openshot PRIVATE - ${OPENSHOT_CV_SOURCES}) - - # Link libopenshot with OpenCV libs - target_link_libraries(openshot PUBLIC ProtoMessages ${OpenCV_LIBS} ${PROTOBUF_LIBRARY} ${Protobuf_INCLUDE_DIRS}) endif() +add_feature_info("OpenCV algorithms" ENABLE_OPENCV "Use OpenCV algorithms") ############### LINK LIBRARY ################# # Link remaining dependency libraries @@ -450,6 +453,9 @@ install( DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/libopenshot FILES_MATCHING PATTERN "*.h" ) +install(FILES ${ProtobufHeaders} + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/libopenshot +) ############### CPACK PACKAGING ############## if(MINGW) @@ -464,5 +470,3 @@ endif() set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Jonathan Thomas") #required include(CPack) - - diff --git a/src/protobuf_messages/compileProtobufMessages.sh b/src/protobuf_messages/compileProtobufMessages.sh deleted file mode 100644 index df127ef2e..000000000 --- a/src/protobuf_messages/compileProtobufMessages.sh +++ /dev/null @@ -1,6 +0,0 @@ -protoc -I=./ --cpp_out=./ stabilizedata.proto -protoc -I=./ --cpp_out=./ trackerdata.proto -protoc -I=./ --cpp_out=./ objdetectdata.proto - -mv *.cc ../ -mv *.h ../ diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index f480b6d30..a928bbb66 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -56,25 +56,6 @@ if(ENABLE_BLACKMAGIC) endif() endif() -####################### OPENCV ########################## -find_package( OpenCV 4 ) -if (OpenCV_FOUND) - add_definitions( -DUSE_OPENCV=1 ) -else() - message("\nOPENCV NOT FOUND, OPENCV RELATED TESTS ARE DISABLED\n") -endif() - -################ PROTOBUF ################## -if (OpenCV_FOUND) - find_package(Protobuf 3) - - if (NOT Protobuf_FOUND) - # Protobuf is required when compiling with opencv - message(FATAL_ERROR "\nPLEASE INSTALL PROTOBUF. Protobuf is required when compiling with opencv.\n") - endif() - include_directories(${PROTOBUF_INCLUDE_DIR}) -endif() - ############### SET TEST SOURCE FILES ################# set(OPENSHOT_TEST_FILES Cache_Tests.cpp @@ -95,15 +76,11 @@ set(OPENSHOT_TEST_FILES Timeline_Tests.cpp) ########## SET OPENCV RELATED TEST FILES ############### -if(OpenCV_FOUND) - set(OPENSHOT_CV_TEST_FILES +if(ENABLE_OPENCV) + list(APPEND OPENSHOT_TEST_FILES CVTracker_Tests.cpp CVStabilizer_Tests.cpp # CVObjectDetection_Tests.cpp - ) - set(OPENSHOT_CV_LIBRARIES - ${OpenCV_LIBS} - ${PROTOBUF_LIBRARY} ) endif() @@ -113,16 +90,14 @@ message (STATUS "Tests enabled, test executable will be built as tests/openshot- add_executable(openshot-test tests.cpp - ${OPENSHOT_TEST_FILES} - ${OPENSHOT_CV_TEST_FILES} - ) + ${OPENSHOT_TEST_FILES} +) # Link libraries to the new executable target_link_libraries(openshot-test openshot ${UnitTest++_LIBRARIES} - ${OPENSHOT_CV_LIBRARIES} - ) +) ##### RUNNING TESTS (make os_test / make test) ##### # Hook up the 'make os_test' target to the 'openshot-test' executable, @@ -130,4 +105,3 @@ target_link_libraries(openshot-test if(NOT ENABLE_COVERAGE) add_custom_target(os_test COMMAND openshot-test) endif() -