onnxruntime/cmake/target_delayload.cmake
Changming Sun 66980e4646
Refactor the cmake code that is related to delay loading (#22646)
### Description
Refactor the cmake code that is related to delay loading. Provide a
cmake option to control if delay loading should be enabled or not.
Disabling the option when python is enabled, due to a known issue. 

### Motivation and Context
ONNX Runtime's python package depends on DirectML.dll, but supposedly
the DLL should be delay loaded.
This PR only refactor the code. It doesn't change the behavior.
2024-11-04 16:30:50 -08:00

17 lines
543 B
CMake

# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# Add delayloaded libraries to a target
function(target_delayload target_name)
if(NOT MSVC)
message(SEND_ERROR "Delayloading is only supported in MSVC")
endif()
if(onnxruntime_ENABLE_DELAY_LOADING_WIN_DLLS)
foreach(lib ${ARGN})
target_link_options(${target_name} PRIVATE /DELAYLOAD:"${lib}")
endforeach()
target_link_libraries(${target_name} PRIVATE delayimp.lib)
endif()
endfunction()