Skip to content

Commit

Permalink
Use prebuilt library on Windows (#249)
Browse files Browse the repository at this point in the history
  • Loading branch information
umireon authored Apr 12, 2023
1 parent e2d9a11 commit 322a098
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
5 changes: 1 addition & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ if(USE_SYSTEM_ONNXRUNTIME)
message(FATAL_ERROR "System ONNX Runtime is only supported on Linux!")
endif()
else()
if(OS_MACOS)
if(OS_MACOS OR OS_WINDOWS)
include(cmake/FetchOnnxruntime.cmake)
else()
include(cmake/BuildMyOnnxruntime.cmake)
Expand All @@ -86,9 +86,6 @@ else()
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE OpenCV)
endif()

if(OS_WINDOWS)
install(IMPORTED_RUNTIME_ARTIFACTS Onnxruntime::DirectML DESTINATION "${OBS_PLUGIN_DESTINATION}")
endif()
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin|iOS")
foreach(flags CMAKE_CXX_FLAGS CMAKE_OBJC_FLAGS CMAKE_OBJCXX_FLAGS)
string(APPEND ${flags} " -fvisibility=hidden -fvisibility-inlines-hidden")
Expand Down
18 changes: 18 additions & 0 deletions cmake/FetchOnnxruntime.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
include(FetchContent)

set(Onnxruntime_VERSION "1.14.1")
set(Onnxruntime_DirectML_VERSION "1.9.0")
if(OS_MACOS)
FetchContent_Declare(
Onnxruntime
Expand All @@ -19,4 +20,21 @@ if(OS_MACOS)
${CMAKE_INSTALL_NAME_TOOL} -change "@rpath/libonnxruntime.${Onnxruntime_VERSION}.dylib"
"@loader_path/../Frameworks/libonnxruntime.${Onnxruntime_VERSION}.dylib"
$<TARGET_FILE:${CMAKE_PROJECT_NAME}>)
elseif(OS_WINDOWS)
FetchContent_Declare(
Onnxruntime
URL "https://github.com/microsoft/onnxruntime/releases/download/v${Onnxruntime_VERSION}/Microsoft.ML.OnnxRuntime.DirectML.${Onnxruntime_VERSION}.zip"
URL_HASH MD5=dfdb875999b119f2b85a1f4d75b3e131)
FetchContent_Declare(
DirectML
URL "https://globalcdn.nuget.org/packages/microsoft.ai.directml.${Onnxruntime_DirectML_VERSION}.nupkg"
URL_HASH MD5=59dad6fc48cfd052bf0fdccfa7b35b72)
FetchContent_MakeAvailable(Onnxruntime DirectML)
set(Onnxruntime_LIB "${onnxruntime_SOURCE_DIR}/runtimes/win-x64/native/onnxruntime.dll")
set(Onnxruntime_IMPLIB "${onnxruntime_SOURCE_DIR}/runtimes/win-x64/native/onnxruntime.lib")
set(DirectML_LIB "${directml_SOURCE_DIR}/bin/x64-win/DirectML.dll")
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE "${Onnxruntime_IMPLIB}")
target_include_directories(${CMAKE_PROJECT_NAME} SYSTEM
PUBLIC "${onnxruntime_SOURCE_DIR}/build/native/include")
install(FILES "${Onnxruntime_LIB}" "${DirectML_LIB}" DESTINATION "${OBS_PLUGIN_DESTINATION}")
endif()

0 comments on commit 322a098

Please sign in to comment.