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 USE_SHARED_OPENCV and USE_SHARED_ONNXRUNTIME options #185

Merged
merged 6 commits into from
Mar 18, 2023
Merged
Changes from 2 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
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.16...3.21)

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_SHARED_ONNXRUNTIME
OFF
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well instead of OFF here you can simply ${OS_LINUX} and that will turn it on for Linux and off for the others

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant that using shared libraries is only for flatpak distribution and I want to keep the deb distribution don't require additional libraries.
I maybe want to rename the flags to USE_SYSTEM_FOO.

CACHE STRING "Use system ONNX Runtime")
if(USE_SHARED_ONNXRUNTIME)
if(OS_LINUX)
find_package(Onnxruntime REQUIRED)
umireon marked this conversation as resolved.
Show resolved Hide resolved
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 "Only on Linux the shared ONNX Runtime supported!")
umireon marked this conversation as resolved.
Show resolved Hide resolved
endif()
else()
include(cmake/BuildMyOnnxruntime.cmake)
endif()

set(USE_SHARED_OPENCV
OFF
CACHE STRING "Use system OpenCV")
if(USE_SHARED_OPENCV)
if(OS_LINUX)
find_package(OpenCV REQUIRED)
umireon marked this conversation as resolved.
Show resolved Hide resolved
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 "Only on Linux the shared OpenCV supported!")
umireon marked this conversation as resolved.
Show resolved Hide resolved
endif()
else()
include(cmake/BuildMyOpenCV.cmake)
endif()

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