Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to specify external directories for OpenCV #13

Merged
merged 6 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
[submodule "vendor/obs-ocr-deps"]
path = vendor/obs-ocr-deps
url = https://github.com/occ-ai/obs-ocr-deps.git
[submodule "vendor/obs-backgroundremoval-dep-opencv"]
path = vendor/obs-backgroundremoval-dep-opencv
url = https://github.com/occ-ai/obs-backgroundremoval-dep-opencv.git
28 changes: 22 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,30 @@ endif()
set(USE_SYSTEM_OPENCV
OFF
CACHE STRING "Use system OpenCV")
if(USE_SYSTEM_OPENCV)
if(OS_LINUX)
find_package(OpenCV REQUIRED COMPONENTS core imgproc dnn)
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE "${OpenCV_LIBRARIES}")
target_include_directories(${CMAKE_PROJECT_NAME} SYSTEM PUBLIC "${OpenCV_INCLUDE_DIRS}")
else()

set(BUILD_OPENCV_FROM_SOURCE
OFF
CACHE STRING "Build OpenCV from tarball")

if(OS_LINUX)
if(USE_SYSTEM_OPENCV AND BUILD_OPENCV_FROM_SOURCE)
message(FATAL_ERROR "Only one of USE_SYSTEM_OPENCV and BUILD_OPENCV_FROM_SOURCE can be enabled!")
endif()
else()
if(USE_SYSTEM_OPENCV)
message(FATAL_ERROR "System OpenCV is only supported on Linux!")
elseif(BUILD_OPENCV_FROM_SOURCE)
message(FATAL_ERROR "Building OpenCV from source is only supported on Linux!")
endif()
endif()

if(USE_SYSTEM_OPENCV)
find_package(OpenCV REQUIRED COMPONENTS core imgproc dnn)
umireon marked this conversation as resolved.
Show resolved Hide resolved
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE "${OpenCV_LIBRARIES}")
target_include_directories(${CMAKE_PROJECT_NAME} SYSTEM PUBLIC "${OpenCV_INCLUDE_DIRS}")
elseif(BUILD_OPENCV_FROM_SOURCE)
include(cmake/BuildOpenCV.cmake)
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE OpenCV)
else()
include(cmake/FetchOpenCV.cmake)
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE OpenCV)
Expand Down
36 changes: 36 additions & 0 deletions cmake/BuildOpenCV.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
include(FetchContent)

set(OPENCV_SOURCE_URL
""
CACHE STRING "URL of a Tesseract source tarball")

set(OPENCV_SOURCE_HASH
""
CACHE STRING "Hash of a Tesseract source tarball")

FetchContent_Declare(
opencv_source
URL ${OPENCV_SOURCE_URL}
URL_HASH ${OPENCV_SOURCE_HASH})
FetchContent_Populate(opencv_source)

set(BUILD_OPENCV_BASEDIR ${CMAKE_BINARY_DIR}/build-opencv)

set(BUILD_OPENCV_OUTPUTS
${BUILD_OPENCV_BASEDIR}/release/${CMAKE_BUILD_TYPE}/lib/libopencv_imgproc.a
${BUILD_OPENCV_BASEDIR}/release/${CMAKE_BUILD_TYPE}/lib/libopencv_core.a
${BUILD_OPENCV_BASEDIR}/release/${CMAKE_BUILD_TYPE}/lib/opencv4/3rdparty/libzlib.a)

set(BUILD_OPENCV_INCLUDE_DIR ${BUILD_OPENCV_BASEDIR}/release/${CMAKE_BUILD_TYPE}/include/opencv4)

add_custom_command(
OUTPUT ${BUILD_OPENCV_OUTPUTS}
COMMAND ${CMAKE_SOURCE_DIR}/vendor/obs-backgroundremoval-dep-opencv/build-linux.sh ${CMAKE_BUILD_TYPE} main
${opencv_source_SOURCE_DIR}
WORKING_DIRECTORY ${BUILD_OPENCV_BASEDIR})
add_custom_target(build_opencv DEPENDS ${BUILD_OPENCV_OUTPUTS})

add_library(OpenCV INTERFACE)
add_dependencies(OpenCV build_opencv)
target_link_libraries(OpenCV INTERFACE ${BUILD_OPENCV_OUTPUTS})
target_include_directories(OpenCV SYSTEM INTERFACE ${BUILD_OPENCV_INCLUDE_DIR})
1 change: 1 addition & 0 deletions vendor/obs-backgroundremoval-dep-opencv
Loading