Skip to content

Commit

Permalink
Add USE_SHARED_OPENCV and USE_SHARED_ONNXRUNTIME options (#185)
Browse files Browse the repository at this point in the history
* Support shared libs on Linux for FlatPak

* Format

* Fix wording

* Update CMakeLists.txt

* Update CMakeLists.txt

* Change the word shared into system
  • Loading branch information
umireon committed Mar 18, 2023
1 parent dacaa4b commit a355723
Showing 1 changed file with 38 additions and 2 deletions.
40 changes: 38 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
cmake_minimum_required(VERSION 3.25.2)

set(CMAKE_CXX_STANDARD 20)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")

# Change obs-plugintemplate to your plugin's name in a machine-readable format (e.g.:
# obs-myawesomeplugin) and set
Expand Down Expand Up @@ -45,8 +46,43 @@ configure_file(src/plugin-macros.h.in ${CMAKE_SOURCE_DIR}/src/plugin-macros.gene

target_sources(${CMAKE_PROJECT_NAME} PRIVATE src/plugin-macros.generated.h)

include(cmake/BuildMyOnnxruntime.cmake)
include(cmake/BuildMyOpenCV.cmake)
set(USE_SYSTEM_ONNXRUNTIME
OFF
CACHE STRING "Use system ONNX Runtime")
if(USE_SYSTEM_ONNXRUNTIME)
if(OS_LINUX)
find_package(Onnxruntime 1.14.1 REQUIRED)
add_library(Onnxruntime SHARED IMPORTED)
set_target_properties(Onnxruntime PROPERTIES IMPORTED_LOCATION ${Onnxruntime_LIBRARIES})
set(Onnxruntime_INCLUDE_PATH
${Onnxruntime_INCLUDE_DIR} ${Onnxruntime_INCLUDE_DIR}/onnxruntime
${Onnxruntime_INCLUDE_DIR}/onnxruntime/core/session
${Onnxruntime_INCLUDE_DIR}/onnxruntime/core/providers/cpu)
set_target_properties(Onnxruntime PROPERTIES INTERFACE_INCLUDE_DIRECTORIES
"${Onnxruntime_INCLUDE_PATH}")
else()
message(FATAL_ERROR "System ONNX Runtime is only supported on Linux!")
endif()
else()
include(cmake/BuildMyOnnxruntime.cmake)
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)
add_library(OpenCV SHARED IMPORTED)
set_target_properties(OpenCV PROPERTIES IMPORTED_LOCATION ${OpenCV_LIBRARIES})
set_target_properties(OpenCV PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${OpenCV_INCLUDE_DIRS}")
else()
message(FATAL_ERROR "System OpenCV is only supported on Linux!")
endif()
else()
include(cmake/BuildMyOpenCV.cmake)
endif()

if(OS_WINDOWS)
install(IMPORTED_RUNTIME_ARTIFACTS Onnxruntime::DirectML DESTINATION "${OBS_PLUGIN_DESTINATION}")
endif()
Expand Down

0 comments on commit a355723

Please sign in to comment.