Skip to content

Commit

Permalink
CMake: Add ENABLE_OPENCV option, use targets
Browse files Browse the repository at this point in the history
  • Loading branch information
ferdnyc committed Dec 24, 2020
1 parent 5b5763e commit 5cfe52b
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 77 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Expand Up @@ -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)
Expand Down
10 changes: 0 additions & 10 deletions bindings/python/CMakeLists.txt
Expand Up @@ -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)
Expand Down
64 changes: 34 additions & 30 deletions src/CMakeLists.txt
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -464,5 +470,3 @@ endif()
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Jonathan Thomas") #required

include(CPack)


6 changes: 0 additions & 6 deletions src/protobuf_messages/compileProtobufMessages.sh

This file was deleted.

36 changes: 5 additions & 31 deletions tests/CMakeLists.txt
Expand Up @@ -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
Expand All @@ -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()

Expand All @@ -113,21 +90,18 @@ 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,
# if we aren't defining it as the coverage target
if(NOT ENABLE_COVERAGE)
add_custom_target(os_test COMMAND openshot-test)
endif()

0 comments on commit 5cfe52b

Please sign in to comment.