Skip to content

Commit

Permalink
Added onnxruntime debug support on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
timbencker committed Aug 7, 2024
1 parent 35454c9 commit 2173b79
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
12 changes: 11 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,9 @@ if (APPLE)
message(FATAL_ERROR "CMAKE_HOST_SYSTEM_PROCESSOR not defined.")
endif()
elseif (MSVC)
set_property(TARGET onnxruntime APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE)
include(cmake/onnx-win-x86_64_debug.cmake)

set_property(TARGET onnxruntime APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE)
set_target_properties(onnxruntime PROPERTIES
IMPORTED_LINK_INTERFACE_LANGUAGES_RELEASE "CXX"
IMPORTED_LOCATION_RELEASE "${CMAKE_CURRENT_LIST_DIR}/modules/onnxruntime/lib/onnxruntime-win-x64.lib"
Expand All @@ -153,6 +154,15 @@ elseif (MSVC)
MAP_IMPORTED_CONFIG_MINSIZEREL Release
MAP_IMPORTED_CONFIG_RELWITHDEBINFO Release
)

set_property(TARGET onnxruntime APPEND PROPERTY IMPORTED_CONFIGURATIONS DEBUG)
set_target_properties(onnxruntime PROPERTIES
IMPORTED_LINK_INTERFACE_LANGUAGES_DEBUG "CXX"
IMPORTED_LOCATION_DEBUG "${CMAKE_CURRENT_LIST_DIR}/modules/onnxruntime-1.14.1-win-x86_64_Debug/onnxruntime-1.14.1-win-x86_64_Debug.lib"
)
set_target_properties(onnxruntime PROPERTIES
MAP_IMPORTED_CONFIG_DEBUG Debug
)
elseif(LINUX)
set_property(TARGET onnxruntime PROPERTY IMPORTED_LOCATION ${CMAKE_CURRENT_LIST_DIR}/modules/onnxruntime/lib/onnxruntime-linux_x86_64-static-combined.a)
endif()
Expand Down
40 changes: 40 additions & 0 deletions cmake/onnx-win-x86_64_debug.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Downloads and extracts pre-build ONNX-Runtime Debug lib for Windows

set(ONNX_RUNTIME_VERSION 1.14.1)
set(ONNX_RUNTIME_DEBUG_BASENAME onnxruntime-${ONNX_RUNTIME_VERSION}-win-x86_64_Debug)

# Define the directory path for the ONNX Runtime Debug library
set(ONNX_RUNTIME_DEBUG_DIR ${CMAKE_CURRENT_SOURCE_DIR}/modules/${ONNX_RUNTIME_DEBUG_BASENAME})
set(ONNX_RUNTIME_ZIP ${ONNX_RUNTIME_DEBUG_BASENAME}.zip)

if(EXISTS ${ONNX_RUNTIME_DEBUG_DIR})
message(STATUS "ONNX-Runtime Debug library found at ${ONNX_RUNTIME_DEBUG_DIR}")
else()
message(STATUS "ONNX-Runtime Debug library not found - downloading pre-built library.")
file(MAKE_DIRECTORY ${ONNX_RUNTIME_DEBUG_DIR})

set(ONNX_RUNTIME_LIB_TYPE "zip")

# Construct the URL for downloading the pre-built library
set(ONNX_RUNTIME_URL https://github.com/timbencker/OnnxRuntimeBuilder/releases/download/${ONNX_RUNTIME_DEBUG_BASENAME}/${ONNX_RUNTIME_ZIP})
message("Downloading from: " ${ONNX_RUNTIME_URL})

# Define the path for the downloaded library file
set(ONNX_RUNTIME_DOWNLOAD_PATH ${CMAKE_BINARY_DIR}/import/${ONNX_RUNTIME_ZIP})

# Download the pre-built library
file(DOWNLOAD ${ONNX_RUNTIME_URL} ${ONNX_RUNTIME_DOWNLOAD_PATH} STATUS ONNX_RUNTIME_DOWNLOAD_STATUS SHOW_PROGRESS)
list(GET ONNX_RUNTIME_DOWNLOAD_STATUS 0 ONNX_RUNTIME_DOWNLOAD_STATUS_NO)

file(ARCHIVE_EXTRACT
INPUT ${ONNX_RUNTIME_DOWNLOAD_PATH}
DESTINATION ${ONNX_RUNTIME_DEBUG_DIR})

if(ONNX_RUNTIME_DOWNLOAD_STATUS_NO)
message(STATUS "Pre-built library not downloaded. Error occurred, try again and check cmake/lib_onnxruntime.cmake")
file(REMOVE_RECURSE ${ONNX_RUNTIME_DEBUG_DIR})
file(REMOVE ${ONNX_RUNTIME_DOWNLOAD_PATH})
else()
message(STATUS "Linking downloaded ONNX-Runtime Debug pre-built library.")
endif()
endif()

0 comments on commit 2173b79

Please sign in to comment.