Skip to content

Commit 387733c

Browse files
authored
Fix Windows build with ONNX Runtime (#664)
* Refactor ONNX Runtime integration for platform support Updated CMakeLists.txt to improve ONNX Runtime linking for Apple and MSVC platforms, including explicit handling of shared libraries and provider dependencies. Commented out DML provider code in ort-session-utils.cpp for Windows, likely due to build or compatibility issues. * Update CMakeLists.txt * Update CMakeLists.txt * Update CMakeLists.txt * Add Module.cpp for plugin lifecycle and DLL loading Introduces src/Module.cpp to handle plugin load/unload events and custom DLL delay loading on Windows. Updates CMakeLists.txt to include the new source file and removes 'delayimp' from link libraries. Modifies plugin-main.c to call PluginLoaded and PluginUnloaded during module load/unload. * Rename Module.cpp to DelayLoad.cpp and update references Renamed src/Module.cpp to src/DelayLoad.cpp and updated CMakeLists.txt to reference the new filename. Removed PluginLoaded and PluginUnloaded calls from plugin-main.c to streamline plugin load/unload logic. * Update DLL install and delay load handling for Windows Adds installation of ONNX Runtime DLLs and PDBs to the Windows build in CMakeLists.txt. Refactors DelayLoad.cpp to resolve and load onnxruntime.dll from a specific plugin directory, improving reliability of DLL loading for the plugin. * Update DelayLoad.cpp * Refactor DelayLoad.cpp formatting and CMake install block Reformatted DelayLoad.cpp for consistent indentation and style. Updated CMakeLists.txt to improve readability of the install() command by reformatting the file list. * Remove DirectML support and related files Deleted CMake scripts for ONNX Runtime integration and removed DirectML (DML) support from code, localization files, and documentation. This simplifies GPU provider options and cleans up unused Windows-specific code paths.
1 parent de72cf1 commit 387733c

23 files changed

+81
-252
lines changed

CMakeLists.txt

Lines changed: 48 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -105,25 +105,60 @@ if(USE_SYSTEM_ONNXRUNTIME)
105105
else()
106106
message(FATAL_ERROR "System ONNX Runtime is only supported on Linux!")
107107
endif()
108+
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE onnxruntime::onnxruntime)
109+
elseif(APPLE)
110+
list(PREPEND CMAKE_PREFIX_PATH "${CMAKE_SOURCE_DIR}/onnxruntime")
111+
find_package(onnxruntime CONFIG REQUIRED)
112+
get_target_property(ONNXRUNTIME_DYLIB_PATH onnxruntime::onnxruntime IMPORTED_LOCATION_RELEASE)
113+
target_sources(${CMAKE_PROJECT_NAME} PRIVATE "${ONNXRUNTIME_DYLIB_PATH}")
114+
set_property(SOURCE "${ONNXRUNTIME_DYLIB_PATH}" PROPERTY MACOSX_PACKAGE_LOCATION Frameworks)
115+
set_target_properties(
116+
${CMAKE_PROJECT_NAME}
117+
PROPERTIES XCODE_ATTRIBUTE_LD_RUNPATH_SEARCH_PATHS "@loader_path/../Frameworks"
118+
)
119+
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE onnxruntime::onnxruntime)
120+
elseif(MSVC)
121+
set(ONNXRUNTIME_ROOT "${CMAKE_SOURCE_DIR}/onnxruntime")
122+
123+
add_library(onnxruntime::onnxruntime_provider_shared SHARED IMPORTED)
124+
set_target_properties(
125+
onnxruntime::onnxruntime_provider_shared
126+
PROPERTIES
127+
IMPORTED_IMPLIB "${ONNXRUNTIME_ROOT}/lib/onnxruntime_providers_shared.lib"
128+
IMPORTED_LOCATION "${ONNXRUNTIME_ROOT}/lib/onnxruntime_providers_shared.dll"
129+
INTERFACE_INCLUDE_DIRECTORIES "${ONNXRUNTIME_ROOT}/include"
130+
)
131+
132+
add_library(onnxruntime::onnxruntime SHARED IMPORTED)
133+
set_target_properties(
134+
onnxruntime::onnxruntime
135+
PROPERTIES
136+
IMPORTED_IMPLIB "${ONNXRUNTIME_ROOT}/lib/onnxruntime.lib"
137+
IMPORTED_LOCATION "${ONNXRUNTIME_ROOT}/lib/onnxruntime.dll"
138+
INTERFACE_INCLUDE_DIRECTORIES "${ONNXRUNTIME_ROOT}/include"
139+
INTERFACE_LINK_OPTIONS "/DELAYLOAD:onnxruntime.dll"
140+
)
141+
target_link_libraries(onnxruntime::onnxruntime INTERFACE onnxruntime::onnxruntime_provider_shared)
142+
143+
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE onnxruntime::onnxruntime)
144+
target_sources(${CMAKE_PROJECT_NAME} PRIVATE src/DelayLoad.cpp)
145+
146+
install(
147+
FILES
148+
"${ONNXRUNTIME_ROOT}/lib/onnxruntime.dll"
149+
"${ONNXRUNTIME_ROOT}/lib/onnxruntime.pdb"
150+
"${ONNXRUNTIME_ROOT}/lib/onnxruntime_providers_shared.dll"
151+
"${ONNXRUNTIME_ROOT}/lib/onnxruntime_providers_shared.pdb"
152+
DESTINATION "${CMAKE_PROJECT_NAME}/bin/64bit/obs-backgroundremoval"
153+
)
108154
else()
109155
list(PREPEND CMAKE_PREFIX_PATH "${CMAKE_SOURCE_DIR}/onnxruntime")
110156
find_package(onnxruntime CONFIG REQUIRED)
111-
if(APPLE)
112-
get_target_property(ONNXRUNTIME_DYLIB_PATH onnxruntime::onnxruntime IMPORTED_LOCATION_RELEASE)
113-
target_sources(${CMAKE_PROJECT_NAME} PRIVATE "${ONNXRUNTIME_DYLIB_PATH}")
114-
set_property(SOURCE "${ONNXRUNTIME_DYLIB_PATH}" PROPERTY MACOSX_PACKAGE_LOCATION Frameworks)
115-
set_target_properties(
116-
${CMAKE_PROJECT_NAME}
117-
PROPERTIES XCODE_ATTRIBUTE_LD_RUNPATH_SEARCH_PATHS "@loader_path/../Frameworks"
118-
)
119-
endif()
157+
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE onnxruntime::onnxruntime)
120158
endif()
121159

122160
add_subdirectory(src/update-checker/CurlClient)
123-
target_link_libraries(
124-
${CMAKE_PROJECT_NAME}
125-
PRIVATE CurlClient OpenCV::opencv_core OpenCV::opencv_imgproc onnxruntime::onnxruntime
126-
)
161+
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE CurlClient OpenCV::opencv_core OpenCV::opencv_imgproc)
127162

128163
target_sources(
129164
${CMAKE_PROJECT_NAME}

cmake/FetchOnnxruntime.cmake

Lines changed: 0 additions & 138 deletions
This file was deleted.

cmake/FindOnnxruntime.cmake

Lines changed: 0 additions & 64 deletions
This file was deleted.

data/locale/ar-EG.ini

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ InferenceDevice="جهاز الإستدلال"
99
CPU="وحدة المعالجة المركزية"
1010
GPUCUDA="الوحدة المركزية - CUDA"
1111
GPUTensorRT="GPU - TensorRT"
12-
GPUDirectML="GPU - DirectML"
1312
CoreML="CoreML"
1413
SegmentationModel="نموذج التقسيم"
1514
SINet="SINet"

data/locale/bn-IN.ini

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ InferenceDevice="নিখরচনা ডিভাইস"
99
CPU="সিপিইউ"
1010
GPUCUDA="জিপিইউ - কুড়া"
1111
GPUTensorRT="জিপিইউ - টেনসরআরটি"
12-
GPUDirectML="জিপিইউ - ডিরেক্টএমএল"
1312
CoreML="কোরএমএল"
1413
SegmentationModel="সেগমেন্টেশন মডেল"
1514
SINet="এসআইনেট"

data/locale/en-US.ini

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ InferenceDevice="Inference device"
99
CPU="CPU"
1010
GPUCUDA="GPU - CUDA"
1111
GPUTensorRT="GPU - TensorRT"
12-
GPUDirectML="GPU - DirectML"
1312
CoreML="CoreML"
1413
SegmentationModel="Segmentation model"
1514
SINet="SINet"

data/locale/es-SP.ini

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ InferenceDevice="Dispositivo de inferencia"
99
CPU="CPU"
1010
GPUCUDA="GPU - CUDA"
1111
GPUTensorRT="GPU - TensorRT"
12-
GPUDirectML="GPU - DirectML"
1312
CoreML="CoreML"
1413
SegmentationModel="Modelo de segmentación"
1514
SINet="SINet"

data/locale/fr-FR.ini

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ InferenceDevice="Dispositif d'inférence"
99
CPU="CPU"
1010
GPUCUDA="GPU - CUDA"
1111
GPUTensorRT="GPU - TensorRT"
12-
GPUDirectML="GPU - DirectML"
1312
CoreML="CoreML"
1413
SegmentationModel="Modèle de segmentation"
1514
SINet="SINet"

data/locale/hi-IN.ini

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ InferenceDevice="संदर्भ डिवाइस"
99
CPU="सीपीयू"
1010
GPUCUDA="जीपीयू - क्यूडा"
1111
GPUTensorRT="जीपीयू - टेंसरआरटी"
12-
GPUDirectML="जीपीयू - डायरेक्टएमएल"
1312
CoreML="कोरएमएल"
1413
SegmentationModel="सेगमेंटेशन मॉडल"
1514
SINet="ऐसआईनेट"

data/locale/it-IT.ini

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ InferenceDevice="Dispositivo di inferenza"
99
CPU="CPU"
1010
GPUCUDA="GPU - CUDA"
1111
GPUTensorRT="GPU - TensorRT"
12-
GPUDirectML="GPU - DirectML"
1312
CoreML="CoreML"
1413
SegmentationModel="Modello di segmentazione".
1514
SINet="SINet"

0 commit comments

Comments
 (0)