Skip to content

Commit

Permalink
Robust OpenCV (#175)
Browse files Browse the repository at this point in the history
* Fix

* Fix

* Update CMakeLists.txt

* Update CMakeLists.txt

* Fix
  • Loading branch information
umireon authored Apr 21, 2024
1 parent e146d9b commit ab491ad
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 44 deletions.
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ target_sources(
src/UpdateChecker/UpdateChecker.cpp)

include(cmake/FetchOpenCV.cmake)
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE OpenCV)
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE ${OpenCV_LIBS})
target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE ${OpenCV_INCLUDE_DIRS})

# TextRecognizer
if(APPLE)
Expand Down
63 changes: 26 additions & 37 deletions cmake/FetchOpenCV.cmake
Original file line number Diff line number Diff line change
@@ -1,63 +1,52 @@
include(FetchContent)

set(USE_SYSTEM_OPENCV
OFF
CACHE STRING "Use system OpenCV")

set(OpenCV_Version 4.9.0-4)

if(${CMAKE_BUILD_TYPE} STREQUAL Release OR ${CMAKE_BUILD_TYPE} STREQUAL RelWithDebInfo)
set(OpenCV_BUILD_TYPE Release)
else()
if(${CMAKE_BUILD_TYPE} STREQUAL Debug)
set(OpenCV_BUILD_TYPE Debug)
else()
set(OpenCV_BUILD_TYPE Release)
endif()

set(OpenCV_BASEURL "https://github.com/kaito-tokyo/kaito-tokyo-obs-dep-opencv/releases/download/${OpenCV_Version}")

if(APPLE)
if(OS_LINUX)
if(OpenCV_BUILD_TYPE STREQUAL Debug)
set(OpenCV_URL "${OpenCV_BASEURL}/opencv-linux-${OpenCV_Version}-Debug.tar.gz")
set(OpenCV_HASH SHA256=dc8ed538dd818ba1240158b307a79f7337a89b4971f5ff05561c99bb064e1543)
else()
set(OpenCV_URL "${OpenCV_BASEURL}/opencv-linux-${OpenCV_Version}-Release.tar.gz")
set(OpenCV_HASH SHA256=8f2ece673f38af3b0aab223ec00b2c5320e00dd9ad36b779397f5305aeb51060)
endif()
elseif(OS_MACOS)
if(OpenCV_BUILD_TYPE STREQUAL Debug)
set(OpenCV_URL "${OpenCV_BASEURL}/opencv-macos-${OpenCV_Version}-Debug.tar.gz")
set(OpenCV_HASH SHA256=a5fe97692232088c112b32f64ddb97f85bc5b2435f7b9b1012efd4ced1f02ca3)
else()
set(OpenCV_URL "${OpenCV_BASEURL}/opencv-macos-${OpenCV_Version}-Release.tar.gz")
set(OpenCV_HASH SHA256=3f01c2248ebb3fd7d25e17de7e56672ed45a0c140b61a25da88f8716abed0367)
endif()
elseif(MSVC)
elseif(OS_WINDOWS)
if(OpenCV_BUILD_TYPE STREQUAL Debug)
set(OpenCV_URL "${OpenCV_BASEURL}/opencv-windows-${OpenCV_Version}-Debug.zip")
set(OpenCV_HASH SHA256=e5d1126856df983277c229c604b2a3afae0c5c27f94fad1c94bf076d77b44ea6)
else()
set(OpenCV_URL "${OpenCV_BASEURL}/opencv-windows-${OpenCV_Version}-Release.zip")
set(OpenCV_HASH SHA256=8f38a041bdfc0ae7164075ccf12394e543cec6f28cf4a105e4324d0a2a630346)
endif()
else()
if(OpenCV_BUILD_TYPE STREQUAL Debug)
set(OpenCV_URL "${OpenCV_BASEURL}/opencv-linux-${OpenCV_Version}-Debug.tar.gz")
set(OpenCV_HASH SHA256=dc8ed538dd818ba1240158b307a79f7337a89b4971f5ff05561c99bb064e1543)
else()
set(OpenCV_URL "${OpenCV_BASEURL}/opencv-linux-${OpenCV_Version}-Release.tar.gz")
set(OpenCV_HASH SHA256=8f2ece673f38af3b0aab223ec00b2c5320e00dd9ad36b779397f5305aeb51060)
endif()
endif()

FetchContent_Declare(
OpenCV
URL ${OpenCV_URL}
URL_HASH ${OpenCV_HASH})
FetchContent_MakeAvailable(opencv)

add_library(OpenCV INTERFACE)
if(MSVC)
target_link_libraries(
OpenCV
INTERFACE ${opencv_SOURCE_DIR}/x64/vc17/staticlib/opencv_features2d490.lib
${opencv_SOURCE_DIR}/x64/vc17/staticlib/opencv_imgcodecs490.lib
${opencv_SOURCE_DIR}/x64/vc17/staticlib/opencv_imgproc490.lib
${opencv_SOURCE_DIR}/x64/vc17/staticlib/opencv_core490.lib
${opencv_SOURCE_DIR}/x64/vc17/staticlib/libpng.lib
${opencv_SOURCE_DIR}/x64/vc17/staticlib/zlib.lib)
target_include_directories(OpenCV SYSTEM INTERFACE ${opencv_SOURCE_DIR}/include)
else()
target_link_libraries(
OpenCV
INTERFACE ${opencv_SOURCE_DIR}/lib/libopencv_features2d.a ${opencv_SOURCE_DIR}/lib/libopencv_imgcodecs.a
${opencv_SOURCE_DIR}/lib/libopencv_imgproc.a ${opencv_SOURCE_DIR}/lib/libopencv_core.a
${opencv_SOURCE_DIR}/lib/opencv4/3rdparty/liblibpng.a ${opencv_SOURCE_DIR}/lib/opencv4/3rdparty/libzlib.a)
target_include_directories(OpenCV SYSTEM INTERFACE ${opencv_SOURCE_DIR}/include/opencv4)
if(NOT USE_SYSTEM_OPENCV)
FetchContent_Declare(
opencv
URL ${OpenCV_URL}
URL_HASH ${OpenCV_HASH})
FetchContent_MakeAvailable(opencv)
endif()

set(OpenCV_STATIC ON)
find_package(OpenCV REQUIRED COMPONENTS core imgproc imgcodecs features2d HINTS "${opencv_SOURCE_DIR}")
5 changes: 3 additions & 2 deletions src/TextRecognizer/TesseractTextRecognizer/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
add_library(TesseractTextRecognizer TesseractTextRecognizer.cpp)
target_link_libraries(TesseractTextRecognizer PRIVATE OBS::libobs plugin-support OpenCV)
target_include_directories(TesseractTextRecognizer PRIVATE "${CMAKE_SOURCE_DIR}/src")

target_link_libraries(TesseractTextRecognizer PRIVATE OBS::libobs plugin-support ${OpenCV_LIBS})
target_include_directories(TesseractTextRecognizer PRIVATE "${CMAKE_SOURCE_DIR}/src" ${OpenCV_INCLUDE_DIRS})
8 changes: 6 additions & 2 deletions src/TextRecognizer/VisionTextRecognizer/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
add_library(VisionTextRecognizer VisionTextRecognizer.mm)
target_link_libraries(VisionTextRecognizer PRIVATE OBS::libobs plugin-support OpenCV "-framework Vision"

target_link_libraries(VisionTextRecognizer PRIVATE)
target_include_directories(VisionTextRecognizer PRIVATE)

target_link_libraries(VisionTextRecognizer PRIVATE OBS::libobs plugin-support ${OpenCV_LIBS} "-framework Vision"
"-framework CoreVideo" "-framework VideoToolbox")
target_include_directories(VisionTextRecognizer PRIVATE "${CMAKE_SOURCE_DIR}/src")
target_include_directories(VisionTextRecognizer PRIVATE "${CMAKE_SOURCE_DIR}/src" ${OpenCV_INCLUDE_DIRS})
4 changes: 2 additions & 2 deletions src/TextRecognizer/WinRTTextRecognizer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ set_target_properties(
CXX_EXTENSIONS OFF
VS_GLOBAL_CppWinRTOptimized true
VS_GLOBAL_CppWinRTRootNamespaceAutoMerge true)
target_link_libraries(WinRTTextRecognizer PRIVATE OBS::libobs plugin-support OpenCV)
target_include_directories(WinRTTextRecognizer PRIVATE "${CMAKE_SOURCE_DIR}/src")
target_link_libraries(WinRTTextRecognizer PRIVATE OBS::libobs plugin-support ${OpenCV_LIBS})
target_include_directories(WinRTTextRecognizer PRIVATE "${CMAKE_SOURCE_DIR}/src" ${OpenCV_INCLUDE_DIRS})

0 comments on commit ab491ad

Please sign in to comment.