From 2173b796a9b7e3a0aee74eb6681b64fe0c284107 Mon Sep 17 00:00:00 2001 From: timbencker Date: Wed, 7 Aug 2024 19:09:47 +0200 Subject: [PATCH] Added onnxruntime debug support on windows --- CMakeLists.txt | 12 +++++++++- cmake/onnx-win-x86_64_debug.cmake | 40 +++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 cmake/onnx-win-x86_64_debug.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 0b1acd8..71ffea6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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" @@ -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() diff --git a/cmake/onnx-win-x86_64_debug.cmake b/cmake/onnx-win-x86_64_debug.cmake new file mode 100644 index 0000000..05d016f --- /dev/null +++ b/cmake/onnx-win-x86_64_debug.cmake @@ -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() \ No newline at end of file