Commit a144865d authored by gaoqiong's avatar gaoqiong
Browse files

update v1.14.0

parent cf1acfd2
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
if (CMAKE_CXX_STANDARD_LIBRARIES MATCHES kernel32.lib)
message(FATAL_ERROR "WinML is only supported on WCOS")
endif()
include(precompiled_header.cmake)
include(target_delayload.cmake)
include(winml_sdk_helpers.cmake)
include(winml_cppwinrt.cmake)
include(nuget_helpers.cmake)
# get the current nuget sdk kit directory
get_sdk(sdk_folder sdk_version)
get_sdk_include_folder(${sdk_folder} ${sdk_version} sdk_include_folder)
set(dxcore_header "${sdk_include_folder}/um/dxcore.h")
set(target_folder ONNXRuntime/winml)
set(winml_adapter_dir ${REPO_ROOT}/winml/adapter)
set(winml_api_root ${REPO_ROOT}/winml/api)
set(winml_dll_dir ${REPO_ROOT}/winml/dll)
set(winml_lib_dir ${REPO_ROOT}/winml/lib)
set(winml_lib_api_dir ${REPO_ROOT}/winml/lib/api)
set(winml_lib_api_experimental_dir ${REPO_ROOT}/winml/lib/api.experimental)
set(winml_lib_api_image_dir ${REPO_ROOT}/winml/lib/api.image)
set(winml_lib_api_ort_dir ${REPO_ROOT}/winml/lib/api.ort)
set(winml_lib_common_dir ${REPO_ROOT}/winml/lib/common)
set(winml_lib_telemetry_dir ${REPO_ROOT}/winml/lib/telemetry)
# Retrieve the version of cppwinrt nuget
package_version(
Microsoft.Windows.CppWinRT
CppWinRT_version
${PROJECT_SOURCE_DIR}/../packages.config
)
# Override and use the the cppwinrt from NuGet package as opposed to the one in the SDK.
set(winml_CPPWINRT_EXE_PATH_OVERRIDE ${CMAKE_CURRENT_BINARY_DIR}/../packages/Microsoft.Windows.CppWinRT.${CppWinRT_version}/bin/cppwinrt.exe)
# add custom target to fetch the nugets
add_fetch_nuget_target(
RESTORE_NUGET_PACKAGES # target name
winml_CPPWINRT_EXE_PATH_OVERRIDE # cppwinrt is the target package
)
set(winml_is_inbox OFF)
if (onnxruntime_WINML_NAMESPACE_OVERRIDE)
set(output_name "${onnxruntime_WINML_NAMESPACE_OVERRIDE}.AI.MachineLearning")
set(experimental_output_name "${onnxruntime_WINML_NAMESPACE_OVERRIDE}.AI.MachineLearning.Experimental")
set(idl_native_output_name "${onnxruntime_WINML_NAMESPACE_OVERRIDE}.AI.MachineLearning.Native")
set(idl_native_internal_output_name "${onnxruntime_WINML_NAMESPACE_OVERRIDE}.AI.MachineLearning.Native.Internal")
if (onnxruntime_WINML_NAMESPACE_OVERRIDE STREQUAL "Windows")
set(winml_midl_defines "/DBUILD_INBOX=1")
set(winml_is_inbox ON)
endif()
set(winml_root_ns "${onnxruntime_WINML_NAMESPACE_OVERRIDE}")
set(BINARY_NAME "${onnxruntime_WINML_NAMESPACE_OVERRIDE}.AI.MachineLearning.dll")
set(winml_api_use_ns_prefix false)
else()
set(output_name "Microsoft.AI.MachineLearning")
set(experimental_output_name "Microsoft.AI.MachineLearning.Experimental")
set(idl_native_output_name "Microsoft.AI.MachineLearning.Native")
set(idl_native_internal_output_name "Microsoft.AI.MachineLearning.Native.Internal")
set(winml_midl_defines "/DROOT_NS=Microsoft")
set(winml_root_ns "Microsoft")
set(BINARY_NAME "Microsoft.AI.MachineLearning.dll")
set(winml_api_use_ns_prefix true)
endif()
get_filename_component(exclusions "${winml_api_root}/exclusions.txt" ABSOLUTE)
convert_forward_slashes_to_back(${exclusions} CPPWINRT_COMPONENT_EXCLUSION_LIST)
# For winrt idl files:
# 1) the file name must match the casing of the file on disk.
# 2) for winrt idls the casing must match the namespaces within exactly (Window.AI.MachineLearning).
# target_cppwinrt will attempt to create a winmd with the name and same casing as the supplied
# idl file. If the name of the winmd file does not match the contained namespaces, cppwinrt.exe
# will generate component template files with fully qualified names, which will not match the existing
# generated component files.
#
# For native idl files there are no casing restrictions.
get_filename_component(winrt_idl "${winml_api_root}/Windows.AI.MachineLearning.idl" ABSOLUTE)
get_filename_component(winrt_experimental_idl "${winml_api_root}/Microsoft.AI.MachineLearning.Experimental.idl" ABSOLUTE)
get_filename_component(idl_native "${winml_api_root}/windows.ai.machineLearning.native.idl" ABSOLUTE)
get_filename_component(idl_native_internal "${winml_api_root}/windows.ai.machineLearning.native.internal.idl" ABSOLUTE)
get_filename_component(winrt_winmd "${CMAKE_CURRENT_BINARY_DIR}/${winml_root_ns}.AI.MachineLearning.winmd" ABSOLUTE)
# generate cppwinrt sdk
add_generate_cppwinrt_sdk_headers_target(
winml_sdk_cppwinrt # the target name
${sdk_folder} # location of sdk folder
${sdk_version} # sdk version
${CMAKE_CURRENT_BINARY_DIR}/winml/sdk/cppwinrt/include # output folder relative to CMAKE_BINARY_DIR where the generated sdk will be placed in the
${target_folder} # folder where this target will be placed
)
add_dependencies(winml_sdk_cppwinrt RESTORE_NUGET_PACKAGES)
# generate winml headers from idl
target_cppwinrt(winml_api
${winrt_idl} # winml winrt idl to compile
${output_name} # outputs name
${winml_lib_api_dir} # location for cppwinrt generated component sources
${sdk_folder} # location of sdk folder
${sdk_version} # sdk version
${target_folder} # the folder this target will be placed under
"${winml_midl_defines}" # the midl compiler defines
${winml_api_use_ns_prefix} # set ns_prefix
"" # set additional cppwinrt ref path
)
add_dependencies(winml_api RESTORE_NUGET_PACKAGES)
# generate winml.experimental headers from idl
target_cppwinrt(winml_api_experimental
${winrt_experimental_idl} # winml winrt idl to compile
${experimental_output_name} # outputs name
${winml_lib_api_dir} # location for cppwinrt generated component sources
${sdk_folder} # location of sdk folder
${sdk_version} # sdk version
${target_folder} # the folder this target will be placed under
${winml_midl_defines} # the midl compiler defines
${winml_api_use_ns_prefix} # set ns_prefix
${winrt_winmd} # set additional cppwinrt ref path
)
add_dependencies(winml_api_experimental RESTORE_NUGET_PACKAGES)
add_dependencies(winml_api_experimental winml_api)
target_midl(winml_api_native
${idl_native} # winml native idl to compile
${idl_native_output_name} # outputs name
${sdk_folder} # location of sdk folder
${sdk_version} # sdk version
${target_folder} # the folder this target will be placed under
"${winml_midl_defines}" # the midl compiler defines
)
add_dependencies(winml_api_native RESTORE_NUGET_PACKAGES)
target_midl(winml_api_native_internal
${idl_native_internal} # winml internal native idl to compile
${idl_native_internal_output_name} # outputs name
${sdk_folder} # location of sdk folder
${sdk_version} # sdk version
${target_folder} # the folder this target will be placed under
"${winml_midl_defines}" # the midl compiler defines
)
add_dependencies(winml_api_native_internal RESTORE_NUGET_PACKAGES)
###########################
# Add winml_lib_telemetry
###########################
# Add static library that will be archived/linked for both static/dynamic library
onnxruntime_add_static_library(winml_lib_telemetry
${winml_lib_telemetry_dir}/inc/TelemetryEvent.h
${ONNXRUNTIME_INCLUDE_DIR}/core/platform/windows/TraceLoggingConfig.h
${winml_lib_common_dir}/inc/WinMLTelemetryHelper.h
${winml_lib_telemetry_dir}/Telemetry.cpp
${winml_lib_telemetry_dir}/TelemetryEvent.cpp
${winml_lib_telemetry_dir}/WinMLTelemetryHelper.cpp
${winml_lib_telemetry_dir}/pch.h
)
# Compiler options
target_compile_features(winml_lib_telemetry PRIVATE cxx_std_17)
target_compile_options(winml_lib_telemetry PRIVATE /GR- /await /wd4238)
if (onnxruntime_USE_TELEMETRY)
set_target_properties(winml_lib_telemetry PROPERTIES COMPILE_FLAGS "/FI${ONNXRUNTIME_INCLUDE_DIR}/core/platform/windows/TraceLoggingConfigPrivate.h")
endif()
# Compiler flags
target_compile_definitions(winml_lib_telemetry PRIVATE WINML_ROOT_NS=${winml_root_ns})
target_compile_definitions(winml_lib_telemetry PRIVATE PLATFORM_WINDOWS)
target_compile_definitions(winml_lib_telemetry PRIVATE _SCL_SECURE_NO_WARNINGS) # remove warnings about unchecked iterators
target_compile_definitions(winml_lib_telemetry PRIVATE BINARY_NAME=\"${BINARY_NAME}\")
# Specify the usage of a precompiled header
target_precompiled_header(winml_lib_telemetry lib/Telemetry/pch.h)
# Includes
target_include_directories(winml_lib_telemetry PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) # windows machine learning generated component headers
target_include_directories(winml_lib_telemetry PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/winml_api) # windows machine learning generated component headers
target_include_directories(winml_lib_telemetry PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/winml_api/comp_generated) # windows machine learning generated component headers
target_include_directories(winml_lib_telemetry PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/winml/sdk/cppwinrt/include) # sdk cppwinrt headers
target_include_directories(winml_lib_telemetry PRIVATE ${CMAKE_SOURCE_DIR}/common/inc)
target_include_directories(winml_lib_telemetry PRIVATE ${winml_lib_telemetry_dir})
target_include_directories(winml_lib_telemetry PRIVATE ${winml_lib_common_dir}/inc)
target_include_directories(winml_lib_telemetry PRIVATE ${ONNXRUNTIME_INCLUDE_DIR}/core/platform/windows)
target_include_directories(winml_lib_telemetry PRIVATE ${REPO_ROOT}/winml)
target_include_directories(winml_lib_telemetry PRIVATE ${GSL_INCLUDE_DIR})
# Properties
set_target_properties(winml_lib_telemetry
PROPERTIES
FOLDER
${target_folder})
# Add deps
add_dependencies(winml_lib_telemetry winml_sdk_cppwinrt)
add_dependencies(winml_lib_telemetry winml_api)
add_dependencies(winml_lib_telemetry winml_api_native)
add_dependencies(winml_lib_telemetry winml_api_native_internal)
# Link libraries
target_link_libraries(winml_lib_telemetry PRIVATE wil)
###########################
# Add winml_lib_ort
###########################
list(APPEND winml_lib_api_ort_files
${winml_lib_api_ort_dir}/inc/OnnxruntimeProvider.h
${winml_lib_api_ort_dir}/OnnxruntimeCpuSessionBuilder.h
${winml_lib_api_ort_dir}/OnnxruntimeCpuSessionBuilder.cpp
${winml_lib_api_ort_dir}/OnnxruntimeDescriptorConverter.h
${winml_lib_api_ort_dir}/OnnxruntimeDescriptorConverter.cpp
${winml_lib_api_ort_dir}/OnnxruntimeEngine.h
${winml_lib_api_ort_dir}/OnnxruntimeEngine.cpp
${winml_lib_api_ort_dir}/OnnxruntimeEngineBuilder.h
${winml_lib_api_ort_dir}/OnnxruntimeEngineBuilder.cpp
${winml_lib_api_ort_dir}/OnnxruntimeEnvironment.h
${winml_lib_api_ort_dir}/OnnxruntimeEnvironment.cpp
${winml_lib_api_ort_dir}/OnnxruntimeModel.h
${winml_lib_api_ort_dir}/OnnxruntimeModel.cpp
${winml_lib_api_ort_dir}/OnnxruntimeSessionBuilder.h
${winml_lib_api_ort_dir}/pch.h
)
if (onnxruntime_USE_DML)
list(APPEND winml_lib_api_ort_files
${winml_lib_api_ort_dir}/OnnxruntimeDmlSessionBuilder.h
${winml_lib_api_ort_dir}/OnnxruntimeDmlSessionBuilder.cpp
)
endif()
# Add static library that will be archived/linked for both static/dynamic library
onnxruntime_add_static_library(winml_lib_ort ${winml_lib_api_ort_files})
# Compiler options
target_compile_features(winml_lib_ort PRIVATE cxx_std_17)
target_compile_options(winml_lib_ort PRIVATE /GR- /await /wd4238)
# Compiler definitions
target_compile_definitions(winml_lib_ort PRIVATE WINML_ROOT_NS=${winml_root_ns})
target_compile_definitions(winml_lib_ort PRIVATE PLATFORM_WINDOWS)
target_compile_definitions(winml_lib_ort PRIVATE _SCL_SECURE_NO_WARNINGS) # remove warnings about unchecked iterators
if (onnxruntime_WINML_NAMESPACE_OVERRIDE STREQUAL "Windows")
target_compile_definitions(winml_lib_ort PRIVATE "BUILD_INBOX=1")
endif()
# Specify the usage of a precompiled header
target_precompiled_header(winml_lib_ort lib/Api.Ort/pch.h)
# Includes
target_include_directories(winml_lib_ort PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/winml_api) # windows machine learning generated component headers
target_include_directories(winml_lib_ort PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/winml_api/comp_generated) # windows machine learning generated component headers
target_include_directories(winml_lib_ort PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/winml/sdk/cppwinrt/include) # sdk cppwinrt headers
target_include_directories(winml_lib_ort PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
target_include_directories(winml_lib_ort PRIVATE ${REPO_ROOT}/winml)
target_include_directories(winml_lib_ort PRIVATE ${winml_lib_api_dir}) # needed for generated headers
target_include_directories(winml_lib_ort PRIVATE ${winml_lib_api_core_dir})
target_include_directories(winml_lib_ort PRIVATE ${winml_lib_api_ort_dir})
target_include_directories(winml_lib_ort PRIVATE ${winml_lib_common_dir}/inc)
target_include_directories(winml_lib_ort PRIVATE ${ONNXRUNTIME_INCLUDE_DIR})
target_include_directories(winml_lib_ort PRIVATE ${ONNXRUNTIME_ROOT})
target_include_directories(winml_lib_ort PRIVATE ${GSL_INCLUDE_DIR})
set_target_properties(winml_lib_ort
PROPERTIES
FOLDER
${target_folder})
# Add deps
add_dependencies(winml_lib_ort winml_sdk_cppwinrt)
add_dependencies(winml_lib_ort winml_api)
add_dependencies(winml_lib_ort winml_api_native)
add_dependencies(winml_lib_ort winml_api_native_internal)
# Link libraries
if (onnxruntime_USE_DML)
target_add_dml(winml_lib_ort)
endif()
target_link_libraries(winml_lib_ort PRIVATE wil)
target_link_libraries(winml_lib_ort INTERFACE winml_lib_api)
target_link_libraries(winml_lib_ort INTERFACE winml_lib_telemetry)
###########################
# Add winml_adapter
###########################
list(APPEND winml_adapter_files
${winml_adapter_dir}/pch.h
${winml_adapter_dir}/winml_adapter_apis.h
${winml_adapter_dir}/winml_adapter_c_api.h
${winml_adapter_dir}/winml_adapter_c_api.cpp
${winml_adapter_dir}/winml_adapter_dml.cpp
${winml_adapter_dir}/winml_adapter_environment.cpp
${winml_adapter_dir}/winml_adapter_execution_provider.cpp
${winml_adapter_dir}/winml_adapter_model.cpp
${winml_adapter_dir}/winml_adapter_model.h
${winml_adapter_dir}/winml_adapter_session.cpp
)
if (onnxruntime_USE_DML)
list(APPEND winml_adapter_files
${winml_adapter_dir}/abi_custom_registry_impl.cpp
${winml_adapter_dir}/abi_custom_registry_impl.h
)
endif()
onnxruntime_add_static_library(winml_adapter ${winml_adapter_files})
if (onnxruntime_WINML_NAMESPACE_OVERRIDE STREQUAL "Windows")
target_compile_definitions(winml_adapter PRIVATE "BUILD_INBOX=1")
endif()
# wil requires C++17
set_target_properties(winml_adapter PROPERTIES CXX_STANDARD 17)
set_target_properties(winml_adapter PROPERTIES CXX_STANDARD_REQUIRED ON)
# Compiler definitions
onnxruntime_add_include_to_target(winml_adapter onnxruntime_common onnxruntime_framework onnx onnx_proto ${PROTOBUF_LIB} flatbuffers)
target_include_directories(winml_adapter PRIVATE ${ONNXRUNTIME_ROOT} ${eigen_INCLUDE_DIRS})
add_dependencies(winml_adapter ${onnxruntime_EXTERNAL_DEPENDENCIES})
# Specify the usage of a precompiled header
target_precompiled_header(winml_adapter adapter/pch.h)
# Includes
target_include_directories(winml_adapter PRIVATE ${REPO_ROOT}/winml)
target_include_directories(winml_adapter PRIVATE ${winml_adapter_dir})
target_include_directories(winml_adapter PRIVATE ${winml_lib_common_dir}/inc)
set_target_properties(winml_adapter
PROPERTIES
FOLDER
${target_folder})
# Link libraries
target_link_libraries(winml_adapter PRIVATE wil)
if (onnxruntime_USE_DML)
target_add_dml(winml_adapter)
endif()
# add it to the onnxruntime shared library
set(onnxruntime_winml winml_adapter)
list(APPEND onnxruntime_EXTERNAL_DEPENDENCIES winml_adapter)
###########################
# Add winml_lib_image
###########################
# Add static library that will be archived/linked for both static/dynamic library
onnxruntime_add_static_library(winml_lib_image
${winml_lib_api_image_dir}/inc/ConverterResourceStore.h
${winml_lib_api_image_dir}/inc/D3DDeviceCache.h
${winml_lib_api_image_dir}/inc/DeviceHelpers.h
${winml_lib_api_image_dir}/inc/DisjointBufferHelpers.h
${winml_lib_api_image_dir}/inc/ImageConversionHelpers.h
${winml_lib_api_image_dir}/inc/ImageConversionTypes.h
${winml_lib_api_image_dir}/inc/ImageConverter.h
${winml_lib_api_image_dir}/inc/TensorToVideoFrameConverter.h
${winml_lib_api_image_dir}/inc/VideoFrameToTensorConverter.h
${winml_lib_api_image_dir}/inc/NominalRangeConverter.h
${winml_lib_api_image_dir}/CpuDetensorizer.h
${winml_lib_api_image_dir}/CpuTensorizer.h
${winml_lib_api_image_dir}/pch.h
${winml_lib_api_image_dir}/ConverterResourceStore.cpp
${winml_lib_api_image_dir}/D3DDeviceCache.cpp
${winml_lib_api_image_dir}/DeviceHelpers.cpp
${winml_lib_api_image_dir}/DisjointBufferHelpers.cpp
${winml_lib_api_image_dir}/ImageConversionHelpers.cpp
${winml_lib_api_image_dir}/ImageConverter.cpp
${winml_lib_api_image_dir}/TensorToVideoFrameConverter.cpp
${winml_lib_api_image_dir}/VideoFrameToTensorConverter.cpp
${winml_lib_api_image_dir}/NominalRangeConverter.cpp
)
# Compiler options
target_compile_features(winml_lib_image PRIVATE cxx_std_17)
target_compile_options(winml_lib_image PRIVATE /GR- /await /wd4238 /wd5205)
# Compiler flags
target_compile_definitions(winml_lib_image PRIVATE WINML_ROOT_NS=${winml_root_ns})
target_compile_definitions(winml_lib_image PRIVATE ONNX_NAMESPACE=onnx)
target_compile_definitions(winml_lib_image PRIVATE ONNX_ML)
target_compile_definitions(winml_lib_image PRIVATE LOTUS_LOG_THRESHOLD=2)
target_compile_definitions(winml_lib_image PRIVATE LOTUS_ENABLE_STDERR_LOGGING)
target_compile_definitions(winml_lib_image PRIVATE PLATFORM_WINDOWS)
target_compile_definitions(winml_lib_image PRIVATE _SCL_SECURE_NO_WARNINGS) # remove warnings about unchecked iterators
# Specify the usage of a precompiled header
target_precompiled_header(winml_lib_image lib/Api.Image/pch.h)
# Includes
target_include_directories(winml_lib_image PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) # windows machine learning generated component headers
target_include_directories(winml_lib_image PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/winml_api) # windows machine learning generated component headers
target_include_directories(winml_lib_image PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/winml_api/comp_generated) # windows machine learning generated component headers
target_include_directories(winml_lib_image PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/winml/sdk/cppwinrt/include) # sdk cppwinrt headers
target_include_directories(winml_lib_image PRIVATE ${ONNXRUNTIME_ROOT}/core/providers/dml/DmlExecutionProvider/src/External/D3DX12) # for d3dx12.h
target_include_directories(winml_lib_image PRIVATE ${winml_lib_api_dir}) # needed for generated headers
target_include_directories(winml_lib_image PRIVATE ${winml_lib_api_image_dir})
target_include_directories(winml_lib_image PRIVATE ${winml_lib_common_dir}/inc)
target_include_directories(winml_lib_image PRIVATE ${ONNXRUNTIME_ROOT})
target_include_directories(winml_lib_image PRIVATE ${ONNXRUNTIME_INCLUDE_DIR}) # for status.h
onnxruntime_add_include_to_target(winml_lib_image ${PROTOBUF_LIB} onnx onnx_proto)
target_include_directories(winml_lib_image PRIVATE ${ONNXRUNTIME_INCLUDE_DIR}/core/platform/windows)
target_include_directories(winml_lib_image PRIVATE ${REPO_ROOT}/cmake/external/flatbuffers/include)
target_include_directories(winml_lib_image PRIVATE ${REPO_ROOT}/cmake/external/mp11/include)
target_include_directories(winml_lib_image PRIVATE ${REPO_ROOT}/winml)
target_include_directories(winml_lib_image PRIVATE ${GSL_INCLUDE_DIR})
# Properties
set_target_properties(winml_lib_image
PROPERTIES
FOLDER
${target_folder})
# Add deps
add_dependencies(winml_lib_image winml_sdk_cppwinrt)
add_dependencies(winml_lib_image winml_api)
add_dependencies(winml_lib_image winml_api_native)
add_dependencies(winml_lib_image winml_api_native_internal)
# Link libraries
target_link_libraries(winml_lib_image PRIVATE dxgi d3d11 d3d12 wil winml_lib_common)
get_target_property(winml_lib_image_include_directories winml_lib_image INCLUDE_DIRECTORIES)
if (onnxruntime_USE_DML)
target_add_dml(winml_lib_image)
endif(onnxruntime_USE_DML)
###########################
# Add winml_lib_api
###########################
# Add static library that will be archived/linked for both static/dynamic library
onnxruntime_add_static_library(winml_lib_api
${winml_lib_api_dir}/impl/FeatureCompatibility.h
${winml_lib_api_dir}/impl/IData.h
${winml_lib_api_dir}/impl/IMapFeatureValue.h
${winml_lib_api_dir}/impl/ISequenceFeatureValue.h
${winml_lib_api_dir}/impl/MapBase.h
${winml_lib_api_dir}/impl/NumericData.h
${winml_lib_api_dir}/impl/SequenceBase.h
${winml_lib_api_dir}/impl/StringData.h
${winml_lib_api_dir}/impl/Tensor.h
${winml_lib_api_dir}/impl/TensorBase.h
${winml_lib_api_dir}/impl/TensorKindFrom.h
${winml_lib_api_dir}/impl/TensorMemoryBufferReference.h
${winml_lib_api_dir}/NumericData.cpp
${winml_lib_api_dir}/ImageFeatureDescriptor.cpp
${winml_lib_api_dir}/ImageFeatureDescriptor.h
${winml_lib_api_dir}/ImageFeatureValue.cpp
${winml_lib_api_dir}/ImageFeatureValue.h
${winml_lib_api_dir}/LearningModel.cpp
${winml_lib_api_dir}/LearningModel.h
${winml_lib_api_dir}/LearningModelBinding.cpp
${winml_lib_api_dir}/LearningModelBinding.h
${winml_lib_api_dir}/LearningModelDevice.cpp
${winml_lib_api_dir}/LearningModelDevice.h
${winml_lib_api_dir}/LearningModelEvaluationResult.cpp
${winml_lib_api_dir}/LearningModelEvaluationResult.h
${winml_lib_api_dir}/LearningModelSession.cpp
${winml_lib_api_dir}/LearningModelSession.h
${winml_lib_api_dir}/LearningModelSessionOptions.cpp
${winml_lib_api_dir}/LearningModelSessionOptions.h
${winml_lib_api_dir}/MapFeatureDescriptor.cpp
${winml_lib_api_dir}/MapFeatureDescriptor.h
${winml_lib_api_dir}/SequenceFeatureDescriptor.cpp
${winml_lib_api_dir}/SequenceFeatureDescriptor.h
${winml_lib_api_dir}/StringData.cpp
${winml_lib_api_dir}/TensorFeatureDescriptor.cpp
${winml_lib_api_dir}/TensorFeatureDescriptor.h
${winml_lib_api_dir}/VectorBackedBuffer.h
${winml_lib_api_dir}/VectorBackedBuffer.cpp
${winml_lib_api_dir}/pch/pch.h
)
# Compiler options
target_compile_features(winml_lib_api PRIVATE cxx_std_17)
target_compile_options(winml_lib_api PRIVATE /GR- /await /bigobj /wd4238 /wd5205)
# Compiler flags
target_compile_definitions(winml_lib_api PRIVATE WINML_ROOT_NS=${winml_root_ns})
target_compile_definitions(winml_lib_api PRIVATE ONNX_NAMESPACE=onnx)
target_compile_definitions(winml_lib_api PRIVATE ONNX_ML)
target_compile_definitions(winml_lib_api PRIVATE LOTUS_LOG_THRESHOLD=2)
target_compile_definitions(winml_lib_api PRIVATE LOTUS_ENABLE_STDERR_LOGGING)
target_compile_definitions(winml_lib_api PRIVATE PLATFORM_WINDOWS)
target_compile_definitions(winml_lib_api PRIVATE _SCL_SECURE_NO_WARNINGS) # remove warnings about unchecked iterators
# Specify the usage of a precompiled header
target_precompiled_header(winml_lib_api lib/Api/pch/pch.h)
# Includes
target_include_directories(winml_lib_api PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/winml_api) # windows machine learning generated component headers
target_include_directories(winml_lib_api PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/winml_api/comp_generated) # windows machine learning generated component headers
target_include_directories(winml_lib_api PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/winml/sdk/cppwinrt/include) # sdk cppwinrt headers
target_include_directories(winml_lib_api PRIVATE ${winml_lib_api_dir})
target_include_directories(winml_lib_api PRIVATE ${winml_lib_api_dir}/pch)
target_include_directories(winml_lib_api PRIVATE ${winml_adapter_dir})
target_include_directories(winml_lib_api PRIVATE ${winml_lib_api_image_dir}/inc)
target_include_directories(winml_lib_api PRIVATE ${winml_lib_api_ort_dir}/inc)
target_include_directories(winml_lib_api PRIVATE ${winml_lib_telemetry_dir}/inc)
target_include_directories(winml_lib_api PRIVATE ${winml_lib_common_dir}/inc)
target_include_directories(winml_lib_api PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
target_include_directories(winml_lib_api PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/external/date/include)
target_include_directories(winml_lib_api PRIVATE ${ONNXRUNTIME_INCLUDE_DIR})
target_include_directories(winml_lib_api PRIVATE ${ONNXRUNTIME_INCLUDE_DIR}/core/graph)
target_include_directories(winml_lib_api PRIVATE ${ONNXRUNTIME_ROOT})
target_include_directories(winml_lib_api PRIVATE ${ONNXRUNTIME_ROOT}/core/graph)
target_include_directories(winml_lib_api PRIVATE ${REPO_ROOT}/cmake/external/eigen)
onnxruntime_add_include_to_target(winml_lib_api ${PROTOBUF_LIB} onnx onnx_proto)
target_include_directories(winml_lib_api PRIVATE ${REPO_ROOT}/cmake/external/SafeInt)
target_include_directories(winml_lib_api PRIVATE ${REPO_ROOT}/cmake/external/flatbuffers/include)
target_include_directories(winml_lib_api PRIVATE ${REPO_ROOT}/cmake/external/mp11/include)
target_include_directories(winml_lib_api PRIVATE ${REPO_ROOT}/winml)
target_include_directories(winml_lib_api PRIVATE ${GSL_INCLUDE_DIR})
# Properties
set_target_properties(winml_lib_api
PROPERTIES
FOLDER
${target_folder})
# Add deps
add_dependencies(winml_lib_api onnx)
add_dependencies(winml_lib_api winml_sdk_cppwinrt)
add_dependencies(winml_lib_api winml_api)
add_dependencies(winml_lib_api winml_api_native)
add_dependencies(winml_lib_api winml_api_native_internal)
# Link libraries
target_link_libraries(winml_lib_api PRIVATE wil winml_lib_telemetry)
if (onnxruntime_USE_DML)
target_add_dml(winml_lib_api)
endif(onnxruntime_USE_DML)
###########################
# Add winml_lib_api_experimental_dir
###########################
# Add static library that will be archived/linked for both static/dynamic library
onnxruntime_add_static_library(winml_lib_api_experimental
${winml_lib_api_experimental_dir}/LearningModelBuilder.cpp
${winml_lib_api_experimental_dir}/LearningModelBuilder.h
${winml_lib_api_experimental_dir}/LearningModelExperimental.cpp
${winml_lib_api_experimental_dir}/LearningModelExperimental.h
${winml_lib_api_experimental_dir}/LearningModelInputs.cpp
${winml_lib_api_experimental_dir}/LearningModelInputs.h
${winml_lib_api_experimental_dir}/LearningModelJoinOptions.cpp
${winml_lib_api_experimental_dir}/LearningModelJoinOptions.h
${winml_lib_api_experimental_dir}/LearningModelOutputs.cpp
${winml_lib_api_experimental_dir}/LearningModelOutputs.h
${winml_lib_api_experimental_dir}/LearningModelOperator.cpp
${winml_lib_api_experimental_dir}/LearningModelOperator.h
${winml_lib_api_experimental_dir}/LearningModelOperatorSet.cpp
${winml_lib_api_experimental_dir}/LearningModelOperatorSet.h
${winml_lib_api_experimental_dir}/LearningModelSessionExperimental.cpp
${winml_lib_api_experimental_dir}/LearningModelSessionExperimental.h
${winml_lib_api_experimental_dir}/LearningModelSessionOptionsExperimental.cpp
${winml_lib_api_experimental_dir}/LearningModelSessionOptionsExperimental.h
)
# Compiler options
target_compile_features(winml_lib_api_experimental PRIVATE cxx_std_17)
target_compile_options(winml_lib_api_experimental PRIVATE /GR- /await /bigobj /wd4238)
# Compiler flags
target_compile_definitions(winml_lib_api_experimental PRIVATE WINML_ROOT_NS=${winml_root_ns})
target_compile_definitions(winml_lib_api_experimental PRIVATE ONNX_NAMESPACE=onnx)
target_compile_definitions(winml_lib_api_experimental PRIVATE ONNX_ML)
target_compile_definitions(winml_lib_api_experimental PRIVATE LOTUS_LOG_THRESHOLD=2)
target_compile_definitions(winml_lib_api_experimental PRIVATE LOTUS_ENABLE_STDERR_LOGGING)
target_compile_definitions(winml_lib_api_experimental PRIVATE PLATFORM_WINDOWS)
target_compile_definitions(winml_lib_api_experimental PRIVATE _SCL_SECURE_NO_WARNINGS) # remove warnings about unchecked iterators
# Specify the usage of a precompiled header
target_precompiled_header(winml_lib_api_experimental lib/Api.Experimental/pch/pch.h)
# Includes
target_include_directories(winml_lib_api_experimental PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/winml_api) # windows machine learning generated component headers
target_include_directories(winml_lib_api_experimental PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/winml_api/comp_generated) # windows machine learning generated component headers
target_include_directories(winml_lib_api_experimental PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/winml_api_experimental) # windows machine learning generated component headers
target_include_directories(winml_lib_api_experimental PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/winml_api_experimental/comp_generated) # windows machine learning generated component headers
target_include_directories(winml_lib_api_experimental PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/winml/sdk/cppwinrt/include) # sdk cppwinrt headers
target_include_directories(winml_lib_api_experimental PRIVATE ${winml_lib_api_dir})
target_include_directories(winml_lib_api_experimental PRIVATE ${winml_lib_api_dir}/pch)
target_include_directories(winml_lib_api_experimental PRIVATE ${winml_adapter_dir})
target_include_directories(winml_lib_api_experimental PRIVATE ${winml_lib_api_image_dir}/inc)
target_include_directories(winml_lib_api_experimental PRIVATE ${winml_lib_api_ort_dir}/inc)
target_include_directories(winml_lib_api_experimental PRIVATE ${winml_lib_telemetry_dir}/inc)
target_include_directories(winml_lib_api_experimental PRIVATE ${winml_lib_common_dir}/inc)
target_include_directories(winml_lib_api_experimental PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
target_include_directories(winml_lib_api_experimental PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/external/date/include)
target_include_directories(winml_lib_api_experimental PRIVATE ${ONNXRUNTIME_INCLUDE_DIR})
target_include_directories(winml_lib_api_experimental PRIVATE ${ONNXRUNTIME_INCLUDE_DIR}/core/graph)
target_include_directories(winml_lib_api_experimental PRIVATE ${ONNXRUNTIME_ROOT})
target_include_directories(winml_lib_api_experimental PRIVATE ${ONNXRUNTIME_ROOT}/core/graph)
target_include_directories(winml_lib_api_experimental PRIVATE ${REPO_ROOT}/cmake/external/eigen)
onnxruntime_add_include_to_target(winml_lib_api_experimental ${PROTOBUF_LIB} onnx onnx_proto)
target_include_directories(winml_lib_api_experimental PRIVATE ${REPO_ROOT}/cmake/external/SafeInt)
target_include_directories(winml_lib_api_experimental PRIVATE ${REPO_ROOT}/cmake/external/flatbuffers/include)
target_include_directories(winml_lib_api_experimental PRIVATE ${REPO_ROOT}/cmake/external/mp11/include)
target_include_directories(winml_lib_api_experimental PRIVATE ${REPO_ROOT}/winml)
target_include_directories(winml_lib_api_experimental PRIVATE ${GSL_INCLUDE_DIR})
# Properties
set_target_properties(winml_lib_api_experimental
PROPERTIES
FOLDER
${target_folder})
# Add deps
add_dependencies(winml_lib_api_experimental onnx)
add_dependencies(winml_lib_api_experimental winml_sdk_cppwinrt)
add_dependencies(winml_lib_api_experimental winml_api)
add_dependencies(winml_lib_api_experimental winml_api_native)
add_dependencies(winml_lib_api_experimental winml_api_native_internal)
add_dependencies(winml_lib_api_experimental winml_api_experimental)
# Link libraries
target_link_libraries(winml_lib_api_experimental PRIVATE wil winml_lib_telemetry)
if (onnxruntime_USE_DML)
target_add_dml(winml_lib_api_experimental)
endif(onnxruntime_USE_DML)
###########################
# Add winml_lib_common
###########################
onnxruntime_add_static_library(winml_lib_common
${winml_lib_common_dir}/inc/common.h
${winml_lib_common_dir}/inc/CommonDeviceHelpers.h
${winml_lib_common_dir}/inc/cppwinrt_onnx.h
${winml_lib_common_dir}/inc/dx.h
${winml_lib_common_dir}/inc/errors.h
${winml_lib_common_dir}/inc/iengine.h
${winml_lib_common_dir}/inc/NamespaceAliases.h
${winml_lib_common_dir}/inc/onnx.h
${winml_lib_common_dir}/inc/PheonixSingleton.h
${winml_lib_common_dir}/inc/StringHelpers.h
${winml_lib_common_dir}/inc/WinMLTelemetryHelper.h
${winml_lib_common_dir}/inc/WinML_Lock.h
${winml_lib_common_dir}/inc/winrt_headers.h
${winml_lib_common_dir}/CommonDeviceHelpers.cpp
)
set_target_properties(winml_lib_common PROPERTIES CXX_STANDARD 17)
set_target_properties(winml_lib_common PROPERTIES CXX_STANDARD_REQUIRED ON)
target_compile_options(winml_lib_common PRIVATE /GR- /await /bigobj /wd4238)
target_link_libraries(winml_lib_common PRIVATE wil)
target_include_directories(winml_lib_common PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/winml_api)
# Compiler flags
target_compile_definitions(winml_lib_common PRIVATE BINARY_NAME=\"${BINARY_NAME}\")
target_compile_definitions(winml_lib_common PRIVATE WINML_ROOT_NS=${winml_root_ns})
target_compile_definitions(winml_lib_common PRIVATE ONNX_NAMESPACE=onnx)
target_compile_definitions(winml_lib_common PRIVATE ONNX_ML)
target_compile_definitions(winml_lib_common PRIVATE LOTUS_LOG_THRESHOLD=2)
target_compile_definitions(winml_lib_common PRIVATE LOTUS_ENABLE_STDERR_LOGGING)
target_compile_definitions(winml_lib_common PRIVATE PLATFORM_WINDOWS)
target_compile_definitions(winml_lib_common PRIVATE _SCL_SECURE_NO_WARNINGS)
add_dependencies(winml_lib_common winml_sdk_cppwinrt)
add_dependencies(winml_lib_common winml_api)
add_dependencies(winml_lib_common winml_api_native)
add_dependencies(winml_lib_common winml_api_native_internal)
target_include_directories(winml_lib_common PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/winml_api) # windows machine learning generated component headers
target_include_directories(winml_lib_common PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/winml_api/comp_generated) # windows machine learning generated component headers
target_include_directories(winml_lib_common PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/winml/sdk/cppwinrt/include) # sdk cppwinrt headers
target_include_directories(winml_lib_common PRIVATE ${winml_lib_api_dir})
target_include_directories(winml_lib_common PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
target_include_directories(winml_lib_common PRIVATE ${winml_lib_common_dir}/inc)
target_include_directories(winml_lib_common PRIVATE ${REPO_ROOT}/winml)
target_include_directories(winml_lib_common PRIVATE ${GSL_INCLUDE_DIR})
target_precompiled_header(winml_lib_common lib/Common/inc/pch.h)
# Properties
set_target_properties(winml_lib_common
PROPERTIES
FOLDER
${target_folder})
if (onnxruntime_USE_DML)
target_add_dml(winml_lib_common)
endif()
###########################
# Add winml_dll
###########################
set_source_files_properties(
${CMAKE_CURRENT_BINARY_DIR}/winml_api/comp_generated/module.g.excl.cpp
PROPERTIES
GENERATED
TRUE)
# Add library
onnxruntime_add_shared_library(winml_dll
${CMAKE_CURRENT_BINARY_DIR}/winml_api/comp_generated/module.g.excl.cpp
${winml_dll_dir}/winml.def
${winml_dll_dir}/winml.rc
${winml_dll_dir}/pch.h
${winml_dll_dir}/module.cpp
)
# Compiler options
target_compile_features(winml_dll PRIVATE cxx_std_17)
target_compile_options(winml_dll PRIVATE /GR- /await /bigobj /wd4238)
# Compiler definitions
target_compile_definitions(winml_dll PRIVATE WINML_ROOT_NS=${winml_root_ns})
target_compile_definitions(winml_dll PRIVATE ONNX_NAMESPACE=onnx)
target_compile_definitions(winml_dll PRIVATE ONNX_ML)
target_compile_definitions(winml_dll PRIVATE LOTUS_LOG_THRESHOLD=2)
target_compile_definitions(winml_dll PRIVATE LOTUS_ENABLE_STDERR_LOGGING)
target_compile_definitions(winml_dll PRIVATE PLATFORM_WINDOWS)
target_compile_definitions(winml_dll PRIVATE VER_MAJOR=${VERSION_MAJOR_PART})
target_compile_definitions(winml_dll PRIVATE VER_MINOR=${VERSION_MINOR_PART})
target_compile_definitions(winml_dll PRIVATE VER_BUILD=${VERSION_BUILD_PART})
target_compile_definitions(winml_dll PRIVATE VER_PRIVATE=${VERSION_PRIVATE_PART})
target_compile_definitions(winml_dll PRIVATE VER_STRING=\"${VERSION_STRING}\")
target_compile_definitions(winml_dll PRIVATE BINARY_NAME=\"${BINARY_NAME}\")
if (onnxruntime_WINML_NAMESPACE_OVERRIDE STREQUAL "Windows")
target_compile_definitions(winml_dll PRIVATE "BUILD_INBOX=1")
endif()
# Specify the usage of a precompiled header
target_precompiled_header(winml_dll dll/pch.h)
# Includes
target_include_directories(winml_dll PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/winml_api) # windows machine learning generated component headers
target_include_directories(winml_dll PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/winml_api/comp_generated) # windows machine learning generated component headers
target_include_directories(winml_dll PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/winml_api_experimental/comp_generated) # windows machine learning generated component headers
target_include_directories(winml_dll PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/winml/sdk/cppwinrt/include) # sdk cppwinrt headers
target_include_directories(winml_dll PRIVATE ${winml_dll_dir})
target_include_directories(winml_dll PRIVATE ${winml_lib_api_dir})
target_include_directories(winml_dll PRIVATE ${winml_lib_api_dir}/impl)
if (NOT winml_is_inbox)
target_include_directories(winml_dll PRIVATE ${winml_lib_api_experimental_dir})
endif()
target_include_directories(winml_dll PRIVATE ${winml_lib_api_ort_dir}/inc)
target_include_directories(winml_dll PRIVATE ${winml_adapter_dir})
target_include_directories(winml_dll PRIVATE ${winml_lib_api_image_dir}/inc)
target_include_directories(winml_dll PRIVATE ${winml_lib_telemetry_dir}/inc)
target_include_directories(winml_dll PRIVATE ${winml_lib_common_dir}/inc)
target_include_directories(winml_dll PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
target_include_directories(winml_dll PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/external/date/include)
target_include_directories(winml_dll PRIVATE ${ONNXRUNTIME_INCLUDE_DIR})
target_include_directories(winml_dll PRIVATE ${ONNXRUNTIME_INCLUDE_DIR}/core/graph)
target_include_directories(winml_dll PRIVATE ${ONNXRUNTIME_ROOT})
target_include_directories(winml_dll PRIVATE ${ONNXRUNTIME_ROOT}/core/graph)
onnxruntime_add_include_to_target(winml_dll ${PROTOBUF_LIB} onnx onnx_proto)
target_include_directories(winml_dll PRIVATE ${REPO_ROOT}/cmake/external/eigen)
target_include_directories(winml_dll PRIVATE ${REPO_ROOT}/cmake/external/SafeInt)
target_include_directories(winml_dll PRIVATE ${REPO_ROOT}/cmake/external/flatbuffers/include)
target_include_directories(winml_dll PRIVATE ${REPO_ROOT}/cmake/external/mp11/include)
target_include_directories(winml_dll PRIVATE ${REPO_ROOT}/winml)
target_include_directories(winml_dll PRIVATE ${GSL_INCLUDE_DIR})
# Properties
set_target_properties(winml_dll
PROPERTIES
OUTPUT_NAME ${output_name})
set(os_component_link_flags_list ${os_component_link_flags})
separate_arguments(os_component_link_flags_list)
target_link_options(winml_dll PRIVATE /DEF:${WINML_DIR}/winml.def ${os_component_link_flags_list})
target_delayload(winml_dll api-ms-win-core-libraryloader-l1-2-1.dll api-ms-win-core-threadpool-legacy-l1-1-0.dll api-ms-win-core-processtopology-obsolete-l1-1-0.dll api-ms-win-core-kernel32-legacy-l1-1-0.dll d3d12.dll d3d11.dll dxgi.dll directml.dll)
if (EXISTS ${dxcore_header})
target_delayload(winml_dll ext-ms-win-dxcore-l1-*.dll)
endif()
set_target_properties(winml_dll
PROPERTIES
FOLDER
${target_folder})
# Add deps
add_dependencies(winml_dll winml_sdk_cppwinrt)
add_dependencies(winml_dll winml_api_native)
add_dependencies(winml_dll winml_api_native_internal)
# Link libraries
target_link_libraries(winml_dll PRIVATE re2)
target_link_libraries(winml_dll PRIVATE wil)
target_link_libraries(winml_dll PRIVATE winml_lib_api)
if (NOT winml_is_inbox)
target_link_libraries(winml_dll PRIVATE winml_lib_api_experimental)
endif()
target_link_libraries(winml_dll PRIVATE winml_lib_image)
target_link_libraries(winml_dll PRIVATE winml_lib_ort)
target_link_libraries(winml_dll PRIVATE winml_lib_telemetry)
target_link_libraries(winml_dll PRIVATE RuntimeObject.lib)
target_link_libraries(winml_dll PRIVATE windowsapp.lib)
# Any project that links in debug_alloc.obj needs this lib.
# unresolved external symbol __imp_SymSetOptions
# ... __imp_SymGetLineFromAddr64
# ... __imp_SymInitialize
# ... __imp_SymFromAddr
if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug" OR "${CMAKE_BUILD_TYPE}" STREQUAL "RelWithDebInfo")
target_link_libraries(winml_dll PRIVATE dbghelp.lib)
endif()
# 1 of 3 projects that fail in link with 'failed to do memory mapped file I/O' (Only release)
# when using x86 hosted architecture. When using the LKG compiler this becomes a problem
# because it falls back to incorrectly using the public version of link.
# To avoid the scenario completely, this will tell cl/link to already start with x64 hosted,
# rather than waiting for it to fail and retry and resolve incorrectly.
if("${CMAKE_BUILD_TYPE}" STREQUAL "Release")
set_target_properties(winml_dll PROPERTIES VS_GLOBAL_PreferredToolArchitecture "x64")
endif("${CMAKE_BUILD_TYPE}" STREQUAL "Release")
option(onnxruntime_BUILD_WINML_TESTS "Build WinML tests" ON)
if (onnxruntime_BUILD_WINML_TESTS)
include(winml_unittests.cmake)
endif()
# This is needed to suppress warnings that complain that no imports are found for the delayloaded library cublas64*.lib
# When cuda is enabled in the pipeline, it sets CMAKE_SHARED_LINKER_FLAGS which affects all targets including winml_dll.
# However, there are no cuda imports in winml_dll, and the linker throws the 4199 warning.
# This is needed to allow winml_dll build with cuda enabled.
target_link_options(winml_dll PRIVATE /ignore:4199)
if (winml_is_inbox)
# Link *_x64/*_arm64 DLLs for the ARM64X forwarder
function(duplicate_shared_library target new_target)
get_target_property(sources ${target} SOURCES)
get_target_property(compile_definitions ${target} COMPILE_DEFINITIONS)
get_target_property(compile_options ${target} COMPILE_OPTIONS)
get_target_property(include_directories ${target} INCLUDE_DIRECTORIES)
get_target_property(link_libraries ${target} LINK_LIBRARIES)
get_target_property(link_options ${target} LINK_OPTIONS)
add_library(${new_target} SHARED ${sources})
add_dependencies(${target} ${new_target})
target_compile_definitions(${new_target} PRIVATE ${compile_definitions})
target_compile_options(${new_target} PRIVATE ${compile_options})
target_include_directories(${new_target} PRIVATE ${include_directories})
target_link_libraries(${new_target} PRIVATE ${link_libraries})
target_link_options(${new_target} PRIVATE ${link_options})
endfunction()
if (WAI_ARCH STREQUAL x64 OR WAI_ARCH STREQUAL arm64)
duplicate_shared_library(winml_dll Windows_AI_MachineLearning_${WAI_ARCH})
target_compile_features(Windows_AI_MachineLearning_${WAI_ARCH} PRIVATE cxx_std_17)
endif()
endif()
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# This script adds cppwinrt support for VS-generated projects.
#
# target_cppwinrt(foo bar.idl)
#
# Calling target_midl function runs midlrt.exe and produces bar.h
# Calling target_cppwinrt function does two things:
#
# 1) Adds a target "bar.cppwinrt", which performs the midl and cppwinrt
# builds and produces:
# bar.h
# bar.winmd
# bar.tlb
# module.g.cpp
#
# 2) Adds a dependency to the new custom target "bar.cppwinrt"
function(target_midl
target_name
idl_file
output_name # output name of the generated headers, winmd and tlb
sdk_folder # sdk kit directory
sdk_version # sdk version
folder_name
midl_options # defines for the midl compiler
)
if (MSVC)
# get sdk include paths for midl
get_sdk_include_folder(${sdk_folder} ${sdk_version} sdk_include_folder)
set(um_sdk_directory "${sdk_include_folder}/um")
set(shared_sdk_directory "${sdk_include_folder}/shared")
set(winrt_sdk_directory "${sdk_include_folder}/winrt")
# get sdk metadata path
get_sdk_metadata_folder(${sdk_folder} ${sdk_version} sdk_metadata_directory_forward_slashes)
convert_forward_slashes_to_back(${sdk_metadata_directory_forward_slashes} sdk_metadata_directory)
# get midl
get_sdk_midl_exe(${sdk_folder} ${sdk_version} midl_exe)
# Filename variables
set(header_filename ${output_name}.h)
convert_forward_slashes_to_back(${idl_file} idl_file_forward_slash)
# using add_custom_command trick to prevent rerunning script unless ${file} is changed
add_custom_command(
OUTPUT ${header_filename}
COMMAND ${midl_exe}
/metadata_dir ${sdk_metadata_directory}
/W1 /char signed /nologo /winrt
/no_settings_comment /no_def_idir /target "NT60"
/I ${um_sdk_directory}
/I ${shared_sdk_directory}
/I ${winrt_sdk_directory}
/I ${CMAKE_CURRENT_SOURCE_DIR}
/h ${header_filename}
${midl_options}
${idl_file_forward_slash}
DEPENDS ${idl_file}
)
add_custom_target(
${target_name}
ALL
DEPENDS ${header_filename}
)
set_target_properties(${target_name} PROPERTIES FOLDER ${folder_name})
endif()
endfunction()
function(target_cppwinrt
target_name # the name of the target to add
file # name of the idl file to compile
output_name # output name of the generated headers, winmd and tlb
out_sources_folder # path where generated sources will be placed
sdk_folder # sdk kit directory
sdk_version # sdk version
folder_name # folder this target will be placed
midl_options # defines for the midl compiler
set_ns_prefix # set ns_prefix option
add_ref # set additional cppwinrt ref path
)
if (MSVC)
# get sdk include paths for midl
get_sdk_include_folder(${sdk_folder} ${sdk_version} sdk_include_folder)
set(um_sdk_directory "${sdk_include_folder}/um")
set(shared_sdk_directory "${sdk_include_folder}/shared")
set(winrt_sdk_directory "${sdk_include_folder}/winrt")
# get sdk metadata path
get_sdk_metadata_folder(${sdk_folder} ${sdk_version} sdk_metadata_directory_forward_slashes)
convert_forward_slashes_to_back(${sdk_metadata_directory_forward_slashes} sdk_metadata_directory)
# get midl
get_sdk_midl_exe(${sdk_folder} ${sdk_version} midl_exe)
# get cppwinrt
get_sdk_cppwinrt_exe(${sdk_folder} ${sdk_version} cppwinrt_exe)
# Filename variables
set(header_filename ${output_name}.h)
set(winmd_filename ${output_name}.winmd)
set(tlb_filename ${output_name}.tlb)
# Get directory
get_filename_component(idl_source_directory ${file} DIRECTORY)
if (NOT "${add_ref}" STREQUAL "")
convert_forward_slashes_to_back(${add_ref} add_ref)
endif()
set(target_outputs ${CMAKE_CURRENT_BINARY_DIR}/${target_name})
convert_forward_slashes_to_back(${target_outputs}/comp output_dir_back_slash)
convert_forward_slashes_to_back(${target_outputs}/temp temp_dir_back_slash)
convert_forward_slashes_to_back(${target_outputs}/comp_generated generated_dir_back_slash)
convert_forward_slashes_to_back(${generated_dir_back_slash}/module.g.cpp module_g_cpp_back_slash)
convert_forward_slashes_to_back(${generated_dir_back_slash}/module.g.excl.cpp module_g_ecxl_cpp_back_slash)
if (set_ns_prefix)
set(ns_prefix "/ns_prefix")
else()
set(ns_prefix "")
endif()
# Get name
set(renamed_idl_filename ${output_name}.idl)
set(renamed_idl_fullpath ${target_outputs}/${renamed_idl_filename})
get_filename_component(idl_source_filename ${file} NAME)
set(copied_idl_fullpath ${target_outputs}/${idl_source_filename})
file(COPY ${file} DESTINATION ${target_outputs})
file(RENAME ${copied_idl_fullpath} ${renamed_idl_fullpath})
convert_forward_slashes_to_back(${renamed_idl_fullpath} renamed_idl_fullpath_back_slash)
# using add_custom_command trick to prevent rerunning script unless ${file} is changed
add_custom_command(
OUTPUT ${header_filename} ${winmd_filename}
DEPENDS ${file}
COMMAND ${midl_exe}
/metadata_dir ${sdk_metadata_directory}
/W1 /char signed /nomidl /nologo /winrt
/no_settings_comment /no_def_idir /target "NT60"
/I ${CMAKE_CURRENT_BINARY_DIR}/winml_api
/I ${idl_source_directory}
/I ${um_sdk_directory}
/I ${shared_sdk_directory}
/I ${winrt_sdk_directory}
/winmd ${winmd_filename}
${ns_prefix}
/h ${header_filename}
/tlb ${tlb_filename}
${midl_options}
${renamed_idl_fullpath_back_slash}
COMMAND
${cppwinrt_exe} -in ${winmd_filename} -comp ${output_dir_back_slash} -pch dll/pch.h -ref ${sdk_metadata_directory} ${add_ref} -out ${generated_dir_back_slash} -verbose
COMMAND
# copy the generated component files into a temporary directory where headers exclusions will be applied
xcopy ${output_dir_back_slash} ${temp_dir_back_slash}\\ /Y /D
COMMAND
# for each file in the temp directory, ensure it is not in the exclusions list.
# if it is, then we need to delete it.
cmd /C "@echo off \
for /f %I in ('dir /b ${temp_dir_back_slash}') \
do \
( \
for /f %E in (${CPPWINRT_COMPONENT_EXCLUSION_LIST}) \
do \
( \
if %E == %I \
( \
del ${temp_dir_back_slash}\\%I \
) \
) \
)"
COMMAND
# for each file in the temp directory, copy the file back into the source tree
# unless the file already exists
cmd /C "@echo off \
for /f %I in ('dir /b ${temp_dir_back_slash}') \
do \
( \
if not exist ${out_sources_folder}\\%I \
( \
copy ${temp_dir_back_slash}\\%I ${out_sources_folder}\\%I \
) \
)"
COMMAND
# open the generated module.g.cpp and strip all the includes (lines) containing excluded headers
# write the new file out to module.g.excl.cpp.
powershell -Command "& { \
$exclusions = get-content '${CPPWINRT_COMPONENT_EXCLUSION_LIST}'; \
(get-content '${module_g_cpp_back_slash}') \
| where { \
$str = $_; \
$matches = ($exclusions | where { $str -match $_ }); \
$matches.Length -eq 0 } \
| Out-File '${module_g_ecxl_cpp_back_slash}' \
}"
BYPRODUCTS
${generated_dir_back_slash}/module.g.excl.cpp
VERBATIM
)
add_custom_target(
${target_name}
ALL
DEPENDS ${header_filename} ${winmd_filename}
)
set_target_properties(${target_name} PROPERTIES FOLDER ${folder_name})
endif()
endfunction()
function(add_generate_cppwinrt_sdk_headers_target
target_name # the name of the target to add
sdk_folder # sdk kit directory
sdk_version # sdk version
sdk_directory # the name of the folder to output the sdk headers to
folder_name # folder this target will be placed
)
if (MSVC)
# get the current nuget sdk's metadata directory
get_sdk_metadata_folder(${sdk_folder} ${sdk_version} metadata_folder)
# get cppwinrt
get_sdk_cppwinrt_exe(${sdk_folder} ${sdk_version} cppwinrt_exe)
# windows.winmd is consumed by cppwinrt to produce the sdk headers
set(windows_winmd "${metadata_folder}/windows.winmd")
# base.h along with the other winrt sdk headers are produced by this command
set(base_h "${sdk_directory}/winrt/base.h")
# using add_custom_command trick to prevent rerunning script unless ${windows_winmd} is changed
add_custom_command(
OUTPUT ${base_h}
DEPENDS ${windows_winmd}
COMMAND ${cppwinrt_exe} -in \"${metadata_folder}\" -out \"${sdk_directory}\" -verbose
)
# add the target
add_custom_target(${target_name} ALL DEPENDS ${base_h})
set_target_properties(${target_name} PROPERTIES FOLDER ${folder_name})
endif()
endfunction()
\ No newline at end of file
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
cmake_minimum_required(VERSION 3.0)
# utility
function(convert_forward_slashes_to_back input output)
string(REGEX REPLACE "/" "\\\\" backwards ${input})
set(${output} ${backwards} PARENT_SCOPE)
endfunction()
# get window 10 install path from registry
function(get_installed_sdk
sdk_folder # the current sdk folder
output_sdk_version # the current sdk version
)
# return the kit path
get_filename_component(win10_sdk_root "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows Kits\\Installed Roots;KitsRoot10]" ABSOLUTE CACHE)
set(${sdk_folder} ${win10_sdk_root} PARENT_SCOPE)
# return the sdk version
if(CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION)
set(${output_sdk_version} ${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION} PARENT_SCOPE)
else()
# choose the SDK matching the system version, or fallback to the latest
file(GLOB win10_sdks RELATIVE "${win10_sdk_root}/UnionMetadata" "${win10_sdk_root}/UnionMetadata/*.*.*.*")
list(GET win10_sdks 0 latest_sdk)
foreach(sdk IN LISTS win10_sdks)
string(FIND ${sdk} ${CMAKE_SYSTEM_VERSION} is_system_version)
if(NOT ${is_system_version} EQUAL -1)
set(${output_sdk_version} ${sdk} PARENT_SCOPE)
return()
elseif(sdk VERSION_GREATER latest_sdk)
set(latest_sdk ${sdk})
endif()
endforeach()
set(${output_sdk_version} ${latest_sdk} PARENT_SCOPE)
endif()
endfunction()
# current sdk binary directory
function(get_sdk_binary_directory
sdk_folder # the kit path
sdk_version # the sdk version
binary_dir # the output folder variable
)
set(${binary_dir} "${sdk_folder}/bin/${sdk_version}" PARENT_SCOPE)
endfunction()
# current sdk include directory
function(get_sdk_include_folder
sdk_folder # the kit path
sdk_version # the sdk version
include_dir # the output folder variable
)
set(${include_dir} "${sdk_folder}/include/${sdk_version}" PARENT_SCOPE)
endfunction()
# current sdk metadata directory
function(get_sdk_metadata_folder
sdk_folder # the kit path
sdk_version # the sdk version
metadata_dir # the output folder variable
)
set(${metadata_dir} "${sdk_folder}/UnionMetadata/${sdk_version}" PARENT_SCOPE)
endfunction()
# current sdk midl exe path
function(get_sdk_midl_exe
sdk_folder # the kit path
sdk_version # the sdk version
midl_exe_path # the output exe path
)
get_sdk_binary_directory(${sdk_folder} ${sdk_version} bin_dir)
set(${midl_exe_path} "${bin_dir}/x64/midlrt.exe" PARENT_SCOPE)
endfunction()
# current cppwinrt cppwinrt exe path
function(get_installed_sdk_cppwinrt_exe
sdk_folder # the kit path
sdk_version # the sdk version
cppwinrt_exe_path # the output exe path
)
get_sdk_binary_directory(${sdk_folder} ${sdk_version} bin_dir)
set(${cppwinrt_exe_path} "${bin_dir}/x64/cppwinrt.exe" PARENT_SCOPE)
endfunction()
# current cppwinrt cppwinrt exe path
function(get_sdk_cppwinrt_exe
sdk_folder # the kit path
sdk_version # the sdk version
output_cppwinrt_exe_path # the output exe path
)
if (NOT DEFINED winml_CPPWINRT_EXE_PATH_OVERRIDE)
get_installed_sdk_cppwinrt_exe(${sdk_folder} ${sdk_version} cppwinrt_exe_path)
set(${output_cppwinrt_exe_path} ${cppwinrt_exe_path} PARENT_SCOPE)
else ()
set(${output_cppwinrt_exe_path} ${winml_CPPWINRT_EXE_PATH_OVERRIDE} PARENT_SCOPE)
endif()
endfunction()
function(get_sdk
output_sdk_folder # the path to the current sdk kit folder
output_sdk_version # the current sdk version
)
if ((NOT DEFINED winml_WINDOWS_SDK_DIR_OVERRIDE) AND
(NOT DEFINED winml_WINDOWS_SDK_VERSION_OVERRIDE))
get_installed_sdk(sdk_folder sdk_version)
set(${output_sdk_folder} ${sdk_folder} PARENT_SCOPE)
set(${output_sdk_version} ${sdk_version} PARENT_SCOPE)
elseif ((DEFINED winml_WINDOWS_SDK_DIR_OVERRIDE) AND
(DEFINED winml_WINDOWS_SDK_VERSION_OVERRIDE))
set(${output_sdk_folder} ${winml_WINDOWS_SDK_DIR_OVERRIDE} PARENT_SCOPE)
set(${output_sdk_version} ${winml_WINDOWS_SDK_VERSION_OVERRIDE} PARENT_SCOPE)
else()
message(
FATAL_ERROR
"Options winml_WINDOWS_SDK_DIR_OVERRIDE and winml_WINDOWS_SDK_VERSION_OVERRIDE must be defined together, or not at all.")
endif()
endfunction()
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
set(WINML_TEST_SRC_DIR ${REPO_ROOT}/winml/test)
set(WINML_TEST_INC_DIR
${REPO_ROOT}/winml/api
${REPO_ROOT}/winml/test/common
${REPO_ROOT}/winml/lib/Common/inc
${REPO_ROOT}/onnxruntime
${REPO_ROOT}/onnxruntime/core/providers/dml/DmlExecutionProvider/src/External/D3DX12
${REPO_ROOT}/cmake/external/googletest/googletest/include
${REPO_ROOT}/cmake/external/wil/include
${REPO_ROOT}/cmake/external/SafeInt
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_BINARY_DIR}/winml_api
${CMAKE_CURRENT_BINARY_DIR}/winml_api/comp_generated
${CMAKE_CURRENT_BINARY_DIR}/winml/sdk/cppwinrt/include
${CMAKE_CURRENT_BINARY_DIR}/winml_api_experimental
${CMAKE_CURRENT_BINARY_DIR}/winml_api_experimental/comp_generated
)
function(set_winml_target_properties target)
set_target_properties(${target} PROPERTIES
FOLDER "ONNXRuntimeTest/winml"
CXX_STANDARD 17
CXX_STANDARD_REQUIRED YES
CXX_EXTENSIONS NO
)
onnxruntime_add_include_to_target(${target} ${PROTOBUF_LIB})
target_include_directories(${target} PRIVATE ${WINML_TEST_INC_DIR})
target_compile_definitions(${target} PRIVATE WINML_ROOT_NS=${winml_root_ns})
target_compile_definitions(${target} PRIVATE BINARY_NAME=\"${BINARY_NAME}\")
endfunction()
function(add_winml_test)
# Add a test target and make it discoverable by CTest by calling add_test
cmake_parse_arguments(_UT "DYN" "TARGET" "LIBS;SOURCES;DEPENDS" ${ARGN})
if(_UT_LIBS)
list(REMOVE_DUPLICATES _UT_LIBS)
endif()
list(REMOVE_DUPLICATES _UT_SOURCES)
if (_UT_DEPENDS)
list(REMOVE_DUPLICATES _UT_DEPENDS)
endif()
onnxruntime_add_executable(${_UT_TARGET} ${_UT_SOURCES})
onnxruntime_add_include_to_target(${_UT_TARGET} onnx_proto)
source_group(TREE ${WINML_TEST_SRC_DIR} FILES ${_UT_SOURCES})
set_winml_target_properties(${_UT_TARGET})
target_compile_definitions(${_UT_TARGET} PRIVATE BUILD_GOOGLE_TEST)
target_precompiled_header(${_UT_TARGET} testPch.h)
if (_UT_DEPENDS)
add_dependencies(${_UT_TARGET} ${_UT_DEPENDS})
endif()
target_link_libraries(${_UT_TARGET} PRIVATE ${_UT_LIBS} gtest winml_google_test_lib ${onnxruntime_EXTERNAL_LIBRARIES} winml_lib_common onnxruntime windowsapp.lib)
target_compile_options(${_UT_TARGET} PRIVATE /wd5205) # workaround cppwinrt SDK bug https://github.com/microsoft/cppwinrt/issues/584
# if building inbox
if (onnxruntime_WINML_NAMESPACE_OVERRIDE STREQUAL "Windows")
target_compile_definitions(${_UT_TARGET} PRIVATE "BUILD_INBOX=1")
endif()
if (onnxruntime_BUILD_MS_EXPERIMENTAL_OPS)
target_compile_definitions(${_UT_TARGET} PRIVATE "BUILD_MS_EXPERIMENTAL_OPS=1")
endif()
add_test(NAME ${_UT_TARGET}
COMMAND ${_UT_TARGET}
WORKING_DIRECTORY $<TARGET_FILE_DIR:${_UT_TARGET}>
)
endfunction()
function(get_winml_test_scenario_src
winml_test_src_path
output_winml_test_scenario_src
output_winml_test_scenario_libs
)
if (onnxruntime_USE_DML)
file(GLOB winml_test_scenario_src CONFIGURE_DEPENDS
"${winml_test_src_path}/scenario/cppwinrt/*.h"
"${winml_test_src_path}/scenario/cppwinrt/*.cpp")
set(${output_winml_test_scenario_libs} "onnxruntime_providers_dml" PARENT_SCOPE)
else()
set(winml_test_scenario_src
"${winml_test_src_path}/scenario/cppwinrt/scenariotestscppwinrt.h"
"${winml_test_src_path}/scenario/cppwinrt/scenariotestscppwinrt.cpp"
)
endif()
set(${output_winml_test_scenario_src} ${winml_test_scenario_src} PARENT_SCOPE)
endfunction()
function(get_winml_test_api_src
winml_test_src_path
output_winml_test_api_src
)
file(GLOB winml_test_api_src CONFIGURE_DEPENDS
"${winml_test_src_path}/api/APITest.h"
"${winml_test_src_path}/api/LearningModelAPITest.h"
"${winml_test_src_path}/api/LearningModelBindingAPITest.h"
"${winml_test_src_path}/api/LearningModelSessionAPITest.h"
"${winml_test_src_path}/api/LearningModelAPITest.cpp"
"${winml_test_src_path}/api/LearningModelBindingAPITest.cpp"
"${winml_test_src_path}/api/LearningModelSessionAPITest.cpp")
set(${output_winml_test_api_src} ${winml_test_api_src} ${winml_redist_only_api_src} PARENT_SCOPE)
endfunction()
function(get_winml_test_api_redist_only_src
winml_test_src_path
output_winml_test_api_src
)
file(GLOB winml_redist_only_api_src CONFIGURE_DEPENDS
"${winml_test_src_path}/api/RawApiHelpers.h"
"${winml_test_src_path}/api/RawApiTests.h"
"${winml_test_src_path}/api/RawApiTestsGpu.h"
"${winml_test_src_path}/api/RawApiHelpers.cpp"
"${winml_test_src_path}/api/RawApiTests.cpp"
"${winml_test_src_path}/api/RawApiTestsGpu.cpp"
"${winml_test_src_path}/api/raw/*.h"
"${winml_test_src_path}/api/raw/*.cpp")
set(${output_winml_test_api_src} ${winml_test_api_src} ${winml_redist_only_api_src} PARENT_SCOPE)
endfunction()
function(get_winml_test_concurrency_src
winml_test_src_path
output_winml_test_concurrency_src
)
file(GLOB winml_test_concurrency_src CONFIGURE_DEPENDS
"${winml_test_src_path}/concurrency/*.h"
"${winml_test_src_path}/concurrency/*.cpp")
set(${output_winml_test_concurrency_src} ${winml_test_concurrency_src} PARENT_SCOPE)
endfunction()
function(get_winml_test_adapter_src
winml_test_src_path
output_winml_test_adapter_src
output_winml_test_adapter_libs
)
set(${output_winml_test_adapter_libs} onnxruntime winml_lib_ort winml_test_common PARENT_SCOPE)
file(GLOB winml_test_adapter_src CONFIGURE_DEPENDS
"${winml_test_src_path}/adapter/*.h"
"${winml_test_src_path}/adapter/*.cpp")
set(${output_winml_test_adapter_src} ${winml_test_adapter_src} PARENT_SCOPE)
endfunction()
function(get_winml_test_image_src
winml_test_src_path
output_winml_test_image_src
)
if (onnxruntime_USE_DML)
set(${output_winml_test_scenario_libs} "onnxruntime_providers_dml" PARENT_SCOPE)
endif()
file(GLOB winml_test_image_src CONFIGURE_DEPENDS
"${winml_test_src_path}/image/*.h"
"${winml_test_src_path}/image/*.cpp")
set(${output_winml_test_image_src} ${winml_test_image_src} PARENT_SCOPE)
endfunction()
function (get_winml_test_model_src
winml_test_src_path
output_winml_test_model_src
winml_test_model_libs)
file(GLOB winml_test_model_src CONFIGURE_DEPENDS
"${winml_test_src_path}/model/*.h"
"${winml_test_src_path}/model/*.cpp")
set(${output_winml_test_model_src} ${winml_test_model_src} PARENT_SCOPE)
set(${winml_test_model_libs} onnx_test_data_proto onnx_test_runner_common onnxruntime_common onnxruntime_mlas
onnxruntime_graph onnxruntime_test_utils onnxruntime_framework onnxruntime_util onnxruntime_flatbuffers PARENT_SCOPE)
endfunction()
file(GLOB winml_test_common_src CONFIGURE_DEPENDS
"${WINML_TEST_SRC_DIR}/common/*.h"
"${WINML_TEST_SRC_DIR}/common/*.cpp")
onnxruntime_add_static_library(winml_test_common ${winml_test_common_src})
target_compile_options(winml_test_common PRIVATE /wd5205) # workaround cppwinrt SDK bug https://github.com/microsoft/cppwinrt/issues/584
if (onnxruntime_WINML_NAMESPACE_OVERRIDE STREQUAL "Windows")
target_compile_definitions(winml_test_common PRIVATE "BUILD_INBOX=1")
endif()
add_dependencies(winml_test_common
onnx
winml_api
winml_dll
)
onnxruntime_add_include_to_target(winml_test_common onnx_proto ${GSL_TARGET})
onnxruntime_add_static_library(winml_google_test_lib ${WINML_TEST_SRC_DIR}/common/googletest/main.cpp)
set_winml_target_properties(winml_google_test_lib)
set_winml_target_properties(winml_test_common)
get_winml_test_api_src(${WINML_TEST_SRC_DIR} winml_test_api_src)
if (NOT ${winml_is_inbox})
get_winml_test_api_redist_only_src(${WINML_TEST_SRC_DIR} winml_test_api_redist_only_src)
endif()
add_winml_test(
TARGET winml_test_api
SOURCES ${winml_test_api_src} ${winml_test_api_redist_only_src}
LIBS winml_test_common
)
target_delayload(winml_test_api dxgi.dll d3d12.dll api-ms-win-core-file-l1-2-2.dll api-ms-win-core-synch-l1-2-1.dll)
if (onnxruntime_USE_DML)
target_delayload(winml_test_api DirectML.dll)
endif()
if (EXISTS ${dxcore_header})
target_delayload(winml_test_api ext-ms-win-dxcore-l1-*.dll)
endif()
get_winml_test_scenario_src(${WINML_TEST_SRC_DIR} winml_test_scenario_src winml_test_scenario_libs)
add_winml_test(
TARGET winml_test_scenario
SOURCES ${winml_test_scenario_src}
LIBS winml_test_common ${winml_test_scenario_libs}
)
target_delayload(winml_test_scenario d2d1.dll d3d11.dll dxgi.dll d3d12.dll api-ms-win-core-libraryloader-l1-2-1.dll api-ms-win-core-file-l1-2-2.dll api-ms-win-core-synch-l1-2-1.dll)
if (onnxruntime_USE_DML)
target_delayload(winml_test_scenario DirectML.dll)
endif()
if (EXISTS ${dxcore_header})
target_delayload(winml_test_scenario ext-ms-win-dxcore-l1-*.dll)
endif()
# necessary for winml_test_scenario because of a still unknown reason, api-ms-win-core-libraryloader-l1-2-1.dll is linked against
# on dev machines but not on the aiinfra agent pool
target_link_options(winml_test_scenario PRIVATE /ignore:4199)
get_winml_test_image_src(${WINML_TEST_SRC_DIR} winml_test_image_src winml_test_image_libs)
add_winml_test(
TARGET winml_test_image
SOURCES ${winml_test_image_src}
LIBS winml_test_common ${winml_test_image_libs}
)
target_precompiled_header(winml_test_image testPch.h)
if(onnxruntime_RUN_MODELTEST_IN_DEBUG_MODE)
target_compile_definitions(winml_test_image PUBLIC -DRUN_MODELTEST_IN_DEBUG_MODE)
endif()
target_delayload(winml_test_image d3d12.dll api-ms-win-core-file-l1-2-2.dll api-ms-win-core-synch-l1-2-1.dll)
get_winml_test_concurrency_src(${WINML_TEST_SRC_DIR} winml_test_concurrency_src)
add_winml_test(
TARGET winml_test_concurrency
SOURCES ${winml_test_concurrency_src}
LIBS winml_test_common
)
target_include_directories(winml_test_concurrency PRIVATE ${ONNXRUNTIME_ROOT}/core/graph)
target_include_directories(winml_test_concurrency PRIVATE ${ONNXRUNTIME_ROOT}/winml/lib/Api.Ort)
get_winml_test_adapter_src(${WINML_TEST_SRC_DIR} winml_test_adapter_src winml_test_adapter_libs)
add_winml_test(
TARGET winml_test_adapter
SOURCES ${winml_test_adapter_src}
LIBS ${winml_test_adapter_libs}
)
target_include_directories(winml_test_adapter PRIVATE ${REPO_ROOT}/winml/adapter)
target_include_directories(winml_test_adapter PRIVATE ${REPO_ROOT}/winml/lib/Api.Ort)
target_include_directories(winml_test_adapter PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/winml_api) # windows machine learning generated component headers
target_include_directories(winml_test_adapter PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/winml_api/comp_generated) # windows machine learning generated component headers
target_include_directories(winml_test_adapter PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/winml/sdk/cppwinrt/include) # sdk cppwinrt headers
target_include_directories(winml_test_adapter PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
target_include_directories(winml_test_adapter PRIVATE ${REPO_ROOT}/winml ${REPO_ROOT}/winml/lib/Api/inc)
target_include_directories(winml_test_adapter PRIVATE ${winml_lib_api_dir}) # needed for generated headers
target_include_directories(winml_test_adapter PRIVATE ${winml_lib_api_core_dir})
target_include_directories(winml_test_adapter PRIVATE ${winml_lib_api_ort_dir})
target_include_directories(winml_test_adapter PRIVATE ${winml_lib_common_dir}/inc)
target_include_directories(winml_test_adapter PRIVATE ${ONNXRUNTIME_INCLUDE_DIR})
target_include_directories(winml_test_adapter PRIVATE ${ONNXRUNTIME_ROOT})
onnxruntime_add_include_to_target(winml_test_adapter onnxruntime_common onnxruntime_framework onnx onnx_proto ${PROTOBUF_LIB} flatbuffers)
target_include_directories(winml_test_adapter PRIVATE ${ONNXRUNTIME_ROOT} ${eigen_INCLUDE_DIRS})
add_dependencies(winml_test_adapter ${onnxruntime_EXTERNAL_DEPENDENCIES})
target_include_directories(winml_test_adapter PRIVATE ${winml_adapter_dir})
target_include_directories(winml_test_adapter PRIVATE ${winml_lib_common_dir}/inc)
# Onnxruntime memory leak checker doesn't work well with GTest static mutexes that create critical sections that cannot be freed prematurely.
if(NOT onnxruntime_ENABLE_MEMLEAK_CHECKER)
get_winml_test_model_src(${WINML_TEST_SRC_DIR} winml_test_model_src winml_test_model_libs)
add_winml_test(
TARGET winml_test_model
SOURCES ${winml_test_model_src}
LIBS winml_test_common ${winml_test_model_libs}
)
if (EXISTS ${dxcore_header})
target_delayload(winml_test_model ext-ms-win-dxcore-l1-*.dll)
endif()
target_precompiled_header(winml_test_model testPch.h)
endif()
# During build time, copy any modified collaterals.
# configure_file(source destination COPYONLY), which configures CMake to copy the file whenever source is modified,
# can't be used here because we don't know the destination during configure time (in multi-configuration generators,
# such as VS, one can switch between Debug/Release builds in the same build tree, and the destination depends on the
# build mode).
function(add_winml_collateral source)
get_filename_component(source_directory ${source} DIRECTORY)
file(GLOB_RECURSE collaterals RELATIVE ${source_directory} ${source})
foreach(collateral ${collaterals})
set(collateral_path ${source_directory}/${collateral})
if(NOT IS_DIRECTORY ${collateral_path})
add_custom_command(TARGET winml_test_common
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${collateral_path} "$<TARGET_FILE_DIR:winml_test_common>/${collateral}")
endif()
endforeach()
endfunction()
add_winml_collateral("${WINML_TEST_SRC_DIR}/api/models/*.onnx")
add_winml_collateral("${WINML_TEST_SRC_DIR}/collateral/images/*.jpg")
add_winml_collateral("${WINML_TEST_SRC_DIR}/collateral/images/*.png")
add_winml_collateral("${WINML_TEST_SRC_DIR}/collateral/models/*.onnx")
add_winml_collateral("${WINML_TEST_SRC_DIR}/common/testdata/squeezenet/*")
add_winml_collateral("${WINML_TEST_SRC_DIR}/image/images/*.jpg")
add_winml_collateral("${WINML_TEST_SRC_DIR}/image/images/*.png")
add_winml_collateral("${WINML_TEST_SRC_DIR}/image/groundTruth/*.jpg")
add_winml_collateral("${WINML_TEST_SRC_DIR}/image/groundTruth/*.png")
add_winml_collateral("${WINML_TEST_SRC_DIR}/image/batchGroundTruth/*.jpg")
add_winml_collateral("${WINML_TEST_SRC_DIR}/image/batchGroundTruth/*.png")
add_winml_collateral("${WINML_TEST_SRC_DIR}/image/models/*.onnx")
add_winml_collateral("${WINML_TEST_SRC_DIR}/scenario/cppwinrt/*.onnx")
add_winml_collateral("${WINML_TEST_SRC_DIR}/scenario/models/*.onnx")
add_winml_collateral("${REPO_ROOT}/onnxruntime/test/testdata/sequence_length.onnx")
add_winml_collateral("${REPO_ROOT}/onnxruntime/test/testdata/sequence_construct.onnx")
---
# clang-format settings for the C# code
BasedOnStyle: Microsoft
BreakBeforeBraces: Custom
BraceWrapping:
AfterCaseLabel: true
BeforeWhile: true
SplitEmptyFunction: false
SplitEmptyRecord: false
# unfortunately there's no config option for handling the 'get' or 'set' of properties
IndentCaseLabels: true
KeepEmptyLinesAtTheStartOfBlocks: false
SpacesInContainerLiterals: false
\ No newline at end of file
###############
# folder #
###############
/**/DROP/
/**/TEMP/
/**/packages/
/**/bin/
/**/obj/
csharp
*.txt
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="docfx.console" Version="2.59.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<Folder Include="images\" />
</ItemGroup>
<ItemGroup>
<Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" />
</ItemGroup>
</Project>
// Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. See LICENSE file in the project root for full license information.
var common = require('./common.js');
var classCategory = 'class';
var namespaceCategory = 'ns';
exports.transform = function (model) {
if (!model) return null;
langs = model.langs;
handleItem(model, model._gitContribute, model._gitUrlPattern);
if (model.children) {
model.children.forEach(function (item) {
handleItem(item, model._gitContribute, model._gitUrlPattern);
});
}
if (model.type) {
switch (model.type.toLowerCase()) {
case 'namespace':
model.isNamespace = true;
if (model.children) groupChildren(model, namespaceCategory);
model[getTypePropertyName(model.type)] = true;
break;
case 'class':
case 'interface':
case 'struct':
case 'delegate':
case 'enum':
model.isClass = true;
if (model.children) groupChildren(model, classCategory);
model[getTypePropertyName(model.type)] = true;
break;
default:
break;
}
}
return model;
}
exports.getBookmarks = function (model, ignoreChildren) {
if (!model || !model.type || model.type.toLowerCase() === "namespace") return null;
var bookmarks = {};
if (typeof ignoreChildren == 'undefined' || ignoreChildren === false) {
if (model.children) {
model.children.forEach(function (item) {
bookmarks[item.uid] = common.getHtmlId(item.uid);
if (item.overload && item.overload.uid) {
bookmarks[item.overload.uid] = common.getHtmlId(item.overload.uid);
}
});
}
}
// Reference's first level bookmark should have no anchor
bookmarks[model.uid] = "";
return bookmarks;
}
exports.groupChildren = groupChildren;
exports.getTypePropertyName = getTypePropertyName;
exports.getCategory = getCategory;
function groupChildren(model, category) {
if (!model || !model.type) {
return;
}
var typeChildrenItems = getDefinitions(category);
var grouped = {};
model.children.forEach(function (c) {
if (c.isEii) {
var type = "eii";
} else {
var type = c.type.toLowerCase();
}
if (!grouped.hasOwnProperty(type)) {
grouped[type] = [];
}
// special handle for field
if (type === "field" && c.syntax) {
c.syntax.fieldValue = c.syntax.return;
c.syntax.return = undefined;
}
// special handle for property
if ((type === "property" || type === "attachedproperty") && c.syntax) {
c.syntax.propertyValue = c.syntax.return;
c.syntax.return = undefined;
}
// special handle for event
if ((type === "event" || type === "attachedevent") && c.syntax) {
c.syntax.eventType = c.syntax.return;
c.syntax.return = undefined;
}
grouped[type].push(c);
})
var children = [];
for (var key in typeChildrenItems) {
if (typeChildrenItems.hasOwnProperty(key) && grouped.hasOwnProperty(key)) {
var typeChildrenItem = typeChildrenItems[key];
var items = grouped[key];
if (items && items.length > 0) {
var item = {};
for (var itemKey in typeChildrenItem) {
if (typeChildrenItem.hasOwnProperty(itemKey)) {
item[itemKey] = typeChildrenItem[itemKey];
}
}
item.children = items;
children.push(item);
}
}
}
model.children = children;
}
function getTypePropertyName(type) {
if (!type) {
return undefined;
}
var loweredType = type.toLowerCase();
var definition = getDefinition(loweredType);
if (definition) {
return definition.typePropertyName;
}
return undefined;
}
function getCategory(type) {
var classItems = getDefinitions(classCategory);
if (classItems.hasOwnProperty(type)) {
return classCategory;
}
var namespaceItems = getDefinitions(namespaceCategory);
if (namespaceItems.hasOwnProperty(type)) {
return namespaceCategory;
}
return undefined;
}
function getDefinition(type) {
var classItems = getDefinitions(classCategory);
if (classItems.hasOwnProperty(type)) {
return classItems[type];
}
var namespaceItems = getDefinitions(namespaceCategory);
if (namespaceItems.hasOwnProperty(type)) {
return namespaceItems[type];
}
return undefined;
}
function getDefinitions(category) {
var namespaceItems = {
"namespace": { inNamespace: true, typePropertyName: "inNamespace", id: "namespaces" },
"class": { inClass: true, typePropertyName: "inClass", id: "classes" },
"struct": { inStruct: true, typePropertyName: "inStruct", id: "structs" },
"interface": { inInterface: true, typePropertyName: "inInterface", id: "interfaces" },
"enum": { inEnum: true, typePropertyName: "inEnum", id: "enums" },
"delegate": { inDelegate: true, typePropertyName: "inDelegate", id: "delegates" }
};
var classItems = {
"constructor": { inConstructor: true, typePropertyName: "inConstructor", id: "constructors" },
"field": { inField: true, typePropertyName: "inField", id: "fields" },
"property": { inProperty: true, typePropertyName: "inProperty", id: "properties" },
"attachedproperty": { inAttachedProperty: true, typePropertyName: "inAttachedProperty", id: "attachedProperties" },
"method": { inMethod: true, typePropertyName: "inMethod", id: "methods" },
"event": { inEvent: true, typePropertyName: "inEvent", id: "events" },
"attachedevent": { inAttachedEvent: true, typePropertyName: "inAttachedEvent", id: "attachedEvents" },
"operator": { inOperator: true, typePropertyName: "inOperator", id: "operators" },
"eii": { inEii: true, typePropertyName: "inEii", id: "eii" }
};
if (category === 'class') {
return classItems;
}
if (category === 'ns') {
return namespaceItems;
}
console.err("category '" + category + "' is not valid.");
return undefined;
}
function handleItem(vm, gitContribute, gitUrlPattern) {
// get contribution information
vm.docurl = common.getImproveTheDocHref(vm, gitContribute, gitUrlPattern);
vm.sourceurl = common.getViewSourceHref(vm, null, gitUrlPattern);
// set to null incase mustache looks up
vm.summary = vm.summary || null;
vm.remarks = vm.remarks || null;
vm.conceptual = vm.conceptual || null;
vm.syntax = vm.syntax || null;
vm.implements = vm.implements || null;
vm.example = vm.example || null;
common.processSeeAlso(vm);
// id is used as default template's bookmark
vm.id = common.getHtmlId(vm.uid);
if (vm.overload && vm.overload.uid) {
vm.overload.id = common.getHtmlId(vm.overload.uid);
}
if (vm.supported_platforms) {
vm.supported_platforms = transformDictionaryToArray(vm.supported_platforms);
}
if (vm.requirements) {
var type = vm.type.toLowerCase();
if (type == "method") {
vm.requirements_method = transformDictionaryToArray(vm.requirements);
} else {
vm.requirements = transformDictionaryToArray(vm.requirements);
}
}
if (vm && langs) {
if (shouldHideTitleType(vm)) {
vm.hideTitleType = true;
} else {
vm.hideTitleType = false;
}
if (shouldHideSubtitle(vm)) {
vm.hideSubtitle = true;
} else {
vm.hideSubtitle = false;
}
}
function shouldHideTitleType(vm) {
var type = vm.type.toLowerCase();
return ((type === 'namespace' && langs.length == 1 && (langs[0] === 'objectivec' || langs[0] === 'java' || langs[0] === 'c'))
|| ((type === 'class' || type === 'enum') && langs.length == 1 && langs[0] === 'c'));
}
function shouldHideSubtitle(vm) {
var type = vm.type.toLowerCase();
return (type === 'class' || type === 'namespace') && langs.length == 1 && langs[0] === 'c';
}
function transformDictionaryToArray(dic) {
var array = [];
for (var key in dic) {
if (dic.hasOwnProperty(key)) {
array.push({ "name": key, "value": dic[key] })
}
}
return array;
}
}
\ No newline at end of file
// Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. See LICENSE file in the project root for full license information.
/**
* This method will be called at the start of exports.transform in ManagedReference.html.primary.js
*/
exports.preTransform = function (model) {
return model;
}
/**
* This method will be called at the end of exports.transform in ManagedReference.html.primary.js
*/
exports.postTransform = function (model) {
return model;
}
\ No newline at end of file
// Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. See LICENSE file in the project root for full license information.
var mrefCommon = require('./ManagedReference.common.js');
var extension = require('./ManagedReference.extension.js');
var overwrite = require('./ManagedReference.overwrite.js');
exports.transform = function (model) {
if (overwrite && overwrite.transform) {
return overwrite.transform(model);
}
if (extension && extension.preTransform) {
model = extension.preTransform(model);
}
if (mrefCommon && mrefCommon.transform) {
model = mrefCommon.transform(model);
}
if (model.type.toLowerCase() === "enum") {
model.isClass = false;
model.isEnum = true;
}
model._disableToc = model._disableToc || !model._tocPath || (model._navPath === model._tocPath);
if (extension && extension.postTransform) {
model = extension.postTransform(model);
}
return model;
}
exports.getOptions = function (model) {
if (overwrite && overwrite.getOptions) {
return overwrite.getOptions(model);
}
return {
"bookmarks": mrefCommon.getBookmarks(model)
};
}
\ No newline at end of file
{{!Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. See LICENSE file in the project root for full license information.}}
{{!master(layout/_master.tmpl)}}
{{#isNamespace}}
{{>partials/namespace}}
{{/isNamespace}}
{{#isClass}}
{{>partials/class}}
{{/isClass}}
{{#isEnum}}
{{>partials/enum}}
{{/isEnum}}
{{>partials/customMREFContent}}
\ No newline at end of file
// Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. See LICENSE file in the project root for full license information.
var common = require('./common.js');
exports.transform = function (model) {
var _fileNameWithoutExt = common.path.getFileNameWithoutExtension(model._path);
model._jsonPath = _fileNameWithoutExt + ".swagger.json";
model.title = model.title || model.name;
model.docurl = model.docurl || common.getImproveTheDocHref(model, model._gitContribute, model._gitUrlPattern);
model.sourceurl = model.sourceurl || common.getViewSourceHref(model, null, model._gitUrlPattern);
model.htmlId = common.getHtmlId(model.uid);
if (model.children) {
for (var i = 0; i < model.children.length; i++) {
var child = model.children[i];
child.docurl = child.docurl || common.getImproveTheDocHref(child, model._gitContribute, model._gitUrlPattern);
if (child.operation) {
child.operation = child.operation.toUpperCase();
}
child.path = appendQueryParamsToPath(child.path, child.parameters);
child.sourceurl = child.sourceurl || common.getViewSourceHref(child, null, model._gitUrlPattern);
child.conceptual = child.conceptual || ''; // set to empty incase mustache looks up
child.summary = child.summary || ''; // set to empty incase mustache looks up
child.description = child.description || ''; // set to empty incase mustache looks up
child.footer = child.footer || ''; // set to empty incase mustache looks up
child.remarks = child.remarks || ''; // set to empty incase mustache looks up
child.htmlId = common.getHtmlId(child.uid);
formatExample(child.responses);
resolveAllOf(child);
transformReference(child);
};
if (!model.tags || model.tags.length === 0) {
var childTags = [];
for (var i = 0; i < model.children.length; i++) {
var child = model.children[i];
if (child.tags && child.tags.length > 0) {
for (var k = 0; k < child.tags.length; k++) {
// for each tag in child, add unique tag string into childTags
if (childTags.indexOf(child.tags[k]) === -1) {
childTags.push(child.tags[k]);
}
}
}
}
// sort alphabetically
childTags.sort();
if (childTags.length > 0) {
model.tags = [];
for (var i = 0; i < childTags.length; i++) {
// add tags into model
model.tags.push({ "name": childTags[i] });
}
}
}
if (model.tags) {
for (var i = 0; i < model.tags.length; i++) {
var children = getChildrenByTag(model.children, model.tags[i].name);
if (children) {
// set children into tag section
model.tags[i].children = children;
}
model.tags[i].conceptual = model.tags[i].conceptual || ''; // set to empty incase mustache looks up
if (model.tags[i]["x-bookmark-id"]) {
model.tags[i].htmlId = model.tags[i]["x-bookmark-id"];
} else if (model.tags[i].uid) {
model.tags[i].htmlId = common.getHtmlId(model.tags[i].uid);
}
}
for (var i = 0; i < model.children.length; i++) {
var child = model.children[i];
if (child.includedInTags) {
// set child to undefined, which is already moved to tag section
model.children[i] = undefined;
if (!model.isTagLayout) {
// flags to indicate the model is tag layout
model.isTagLayout = true;
}
}
}
// remove undefined child
model.children = model.children.filter(function (o) { return o; });
}
}
return model;
function getChildrenByTag(children, tag) {
if (!children) return;
return children.filter(function (child) {
if (child.tags && child.tags.indexOf(tag) > -1) {
child.includedInTags = true;
return true;
}
})
}
function formatExample(responses) {
if (!responses) return;
for (var i = responses.length - 1; i >= 0; i--) {
var examples = responses[i].examples;
if (!examples) continue;
for (var j = examples.length - 1; j >= 0; j--) {
var content = examples[j].content;
if (!content) continue;
var mimeType = examples[j].mimeType;
if (mimeType === 'application/json') {
try {
var json = JSON.parse(content)
responses[i].examples[j].content = JSON.stringify(json, null, ' ');
} catch (e) {
console.warn("example is not a valid JSON object.");
}
}
}
}
}
function resolveAllOf(obj) {
if (Array.isArray(obj)) {
for (var i = 0; i < obj.length; i++) {
resolveAllOf(obj[i]);
}
}
else if (typeof obj === "object") {
for (var key in obj) {
if (obj.hasOwnProperty(key)) {
if (key === "allOf" && Array.isArray(obj[key])) {
// find 'allOf' array and process
processAllOfArray(obj[key], obj);
// delete 'allOf' value
delete obj[key];
} else {
resolveAllOf(obj[key]);
}
}
}
}
}
function processAllOfArray(allOfArray, originalObj) {
// for each object in 'allOf' array, merge the values to those in the same level with 'allOf'
for (var i = 0; i < allOfArray.length; i++) {
var item = allOfArray[i];
for (var key in item) {
if (originalObj.hasOwnProperty(key)) {
mergeObjByKey(originalObj[key], item[key]);
} else {
originalObj[key] = item[key];
}
}
}
}
function mergeObjByKey(targetObj, sourceObj) {
for (var key in sourceObj) {
// merge only when target object doesn't define the key
if (!targetObj.hasOwnProperty(key)) {
targetObj[key] = sourceObj[key];
}
}
}
function transformReference(obj) {
if (Array.isArray(obj)) {
for (var i = 0; i < obj.length; i++) {
transformReference(obj[i]);
}
}
else if (typeof obj === "object") {
for (var key in obj) {
if (obj.hasOwnProperty(key)) {
if (key === "schema") {
// transform schema.properties from obj to key value pair
transformProperties(obj[key]);
} else {
transformReference(obj[key]);
}
}
}
}
}
function transformProperties(obj) {
if (obj.properties) {
if (obj.required && Array.isArray(obj.required)) {
for (var i = 0; i < obj.required.length; i++) {
var field = obj.required[i];
if (obj.properties[field]) {
// add required field as property
obj.properties[field].required = true;
}
}
delete obj.required;
}
var array = [];
for (var key in obj.properties) {
if (obj.properties.hasOwnProperty(key)) {
var value = obj.properties[key];
// set description to null incase mustache looks up
value.description = value.description || null;
transformPropertiesValue(value);
array.push({ key: key, value: value });
}
}
obj.properties = array;
}
}
function transformPropertiesValue(obj) {
if (obj.type === "array" && obj.items) {
// expand array to transformProperties
obj.items.properties = obj.items.properties || null;
obj.items['x-internal-ref-name'] = obj.items['x-internal-ref-name'] || null;
obj.items['x-internal-loop-ref-name'] = obj.items['x-internal-loop-ref-name'] || null;
transformProperties(obj.items);
} else if (obj.properties && !obj.items) {
// fill obj.properties into obj.items.properties, to be rendered in the same way with array
obj.items = {};
obj.items.properties = obj.properties || null;
delete obj.properties;
if (obj.required) {
obj.items.required = obj.required;
delete obj.required;
}
obj.items['x-internal-ref-name'] = obj['x-internal-ref-name'] || null;
obj.items['x-internal-loop-ref-name'] = obj['x-internal-loop-ref-name'] || null;
transformProperties(obj.items);
}
}
function appendQueryParamsToPath(path, parameters) {
if (!path || !parameters) return path;
var requiredQueryParams = parameters.filter(function (p) { return p.in === 'query' && p.required; });
if (requiredQueryParams.length > 0) {
path = formatParams(path, requiredQueryParams, true);
}
var optionalQueryParams = parameters.filter(function (p) { return p.in === 'query' && !p.required; });
if (optionalQueryParams.length > 0) {
path += "[";
path = formatParams(path, optionalQueryParams, requiredQueryParams.length === 0);
path += "]";
}
return path;
}
function formatParams(path, parameters, isFirst) {
for (var i = 0; i < parameters.length; i++) {
if (i === 0 && isFirst) {
path += "?";
} else {
path += "&";
}
path += parameters[i].name;
}
return path;
}
}
exports.getBookmarks = function (model) {
if (!model) return null;
var bookmarks = {};
bookmarks[model.uid] = "";
if (model.tags) {
model.tags.forEach(function (tag) {
if (tag.uid) {
bookmarks[tag.uid] = tag["x-bookmark-id"] ? tag["x-bookmark-id"] : common.getHtmlId(tag.uid);
}
if (tag.children) {
tag.children.forEach(function (child) {
if (child.uid) {
bookmarks[child.uid] = common.getHtmlId(child.uid);
}
})
}
})
}
if (model.children) {
model.children.forEach(function (child) {
if (child.uid) {
bookmarks[child.uid] = common.getHtmlId(child.uid);
}
});
}
return bookmarks;
}
// Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. See LICENSE file in the project root for full license information.
/**
* This method will be called at the start of exports.transform in RestApi.html.primary.js
*/
exports.preTransform = function (model) {
return model;
}
/**
* This method will be called at the end of exports.transform in RestApi.html.primary.js
*/
exports.postTransform = function (model) {
return model;
}
\ No newline at end of file
// Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. See LICENSE file in the project root for full license information.
var restApiCommon = require('./RestApi.common.js');
var extension = require('./RestApi.extension.js')
exports.transform = function (model) {
if (extension && extension.preTransform) {
model = extension.preTransform(model);
}
if (restApiCommon && restApiCommon.transform) {
model = restApiCommon.transform(model);
}
model._disableToc = model._disableToc || !model._tocPath || (model._navPath === model._tocPath);
if (extension && extension.postTransform) {
model = extension.postTransform(model);
}
return model;
}
exports.getOptions = function (model) {
return { "bookmarks": restApiCommon.getBookmarks(model) };
}
\ No newline at end of file
{{!Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. See LICENSE file in the project root for full license information.}}
{{!master(layout/_master.tmpl)}}
{{>partials/rest}}
\ No newline at end of file
// Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. See LICENSE file in the project root for full license information.
var common = require('./common.js');;
var classCategory = 'class';
var namespaceCategory = 'ns';
exports.transform = function (model) {
if (!model) return
handleItem(model, model._gitContribute, model._gitUrlPattern);
if (model.children) {
normalizeLanguageValuePairs(model.children).forEach(function (item) {
handleItem(item, model._gitContribute, model._gitUrlPattern);
});
};
if (model.type) {
switch (model.type.toLowerCase()) {
// packages and namespaces are both containers for other elements
case 'package':
case 'namespace':
model.isNamespace = true;
if (model.children) groupChildren(model, namespaceCategory);
model[getTypePropertyName(model.type)] = true;
break;
case 'class':
case 'interface':
case 'struct':
case 'delegate':
model.isClass = true;
if (model.children) groupChildren(model, classCategory);
model[getTypePropertyName(model.type)] = true;
break;
case 'enum':
model.isEnum = true;
if (model.children) groupChildren(model, classCategory);
model[getTypePropertyName(model.type)] = true;
break;
default:
break;
}
}
return model;
}
exports.getBookmarks = function (model, ignoreChildren) {
if (!model || !model.type || model.type.toLowerCase() === "namespace") return null;
var bookmarks = {};
if (typeof ignoreChildren == 'undefined' || ignoreChildren === false) {
if (model.children) {
normalizeLanguageValuePairs(model.children).forEach(function (item) {
bookmarks[item.uid] = common.getHtmlId(item.uid);
if (item.overload && item.overload.uid) {
bookmarks[item.overload.uid] = common.getHtmlId(item.overload.uid);
}
});
}
}
// Reference's first level bookmark should have no anchor
bookmarks[model.uid] = "";
return bookmarks;
}
function handleItem(vm, gitContribute, gitUrlPattern) {
// get contribution information
vm.docurl = common.getImproveTheDocHref(vm, gitContribute, gitUrlPattern);
vm.sourceurl = common.getViewSourceHref(vm, null, gitUrlPattern);
// set to null incase mustache looks up
vm.summary = vm.summary || null;
vm.remarks = vm.remarks || null;
vm.conceptual = vm.conceptual || null;
vm.syntax = vm.syntax || null;
vm.implements = vm.implements || null;
vm.example = vm.example || null;
vm.inheritance = vm.inheritance || null;
if (vm.inheritance) {
normalizeLanguageValuePairs(vm.inheritance).forEach(handleInheritance);
}
common.processSeeAlso(vm);
// id is used as default template's bookmark
vm.id = common.getHtmlId(vm.uid);
if (vm.overload && vm.overload.uid) {
vm.overload.id = common.getHtmlId(vm.overload.uid);
}
// concatenate multiple types with `|`
if (vm.syntax) {
var syntax = vm.syntax;
if (syntax.parameters) {
syntax.parameters = syntax.parameters.map(function (p) {
return joinType(p);
})
syntax.parameters = groupParameters(syntax.parameters);
}
if (syntax.return) {
syntax.return = joinType(syntax.return);
}
}
}
function handleInheritance(tree) {
tree.type = tree.type || null;
tree.inheritance = tree.inheritance || null;
if (tree.inheritance) {
tree.inheritance.forEach(handleInheritance);
}
}
function joinType(parameter) {
// change type in syntax from array to string
var joinTypeProperty = function (type, key) {
if (!type || !type[0] || !type[0][key]) return null;
var value = type.map(function (t) {
if (!t) return null;
if (!t[key]) return t.uid;
return t[key][0].value;
}).join(' | ');
return [{
lang: type[0][key][0].lang,
value: value
}];
};
if (parameter.type) {
parameter.type = {
name: joinTypeProperty(parameter.type, "name"),
nameWithType: joinTypeProperty(parameter.type, "nameWithType"),
fullName: joinTypeProperty(parameter.type, "fullName"),
specName: joinTypeProperty(parameter.type, "specName")
}
}
return parameter;
}
function groupParameters(parameters) {
// group parameter with properties
if (!parameters || parameters.length == 0) return parameters;
var groupedParameters = [];
var stack = [];
for (var i = 0; i < parameters.length; i++) {
var parameter = parameters[i];
parameter.properties = null;
var prefixLength = 0;
while (stack.length > 0) {
var top = stack.pop();
var prefix = top.id + '.';
if (parameter.id.indexOf(prefix) == 0) {
prefixLength = prefix.length;
if (!top.parameter.properties) {
top.parameter.properties = [];
}
top.parameter.properties.push(parameter);
stack.push(top);
break;
}
if (stack.length == 0) {
groupedParameters.push(top.parameter);
}
}
stack.push({ id: parameter.id, parameter: parameter });
parameter.id = parameter.id.substring(prefixLength);
}
while (stack.length > 0) {
top = stack.pop();
}
groupedParameters.push(top.parameter);
return groupedParameters;
}
function groupChildren(model, category, typeChildrenItems) {
if (!model || !model.type) {
return;
}
if (!typeChildrenItems) {
var typeChildrenItems = getDefinitions(category);
}
var grouped = {};
normalizeLanguageValuePairs(model.children).forEach(function (c) {
if (c.isEii) {
var type = "eii";
} else {
var type = c.type.toLowerCase();
}
if (!grouped.hasOwnProperty(type)) {
grouped[type] = [];
}
// special handle for field
if (type === "field" && c.syntax) {
c.syntax.fieldValue = c.syntax.return;
c.syntax.return = undefined;
}
// special handle for property
if (type === "property" && c.syntax) {
c.syntax.propertyValue = c.syntax.return;
c.syntax.return = undefined;
}
// special handle for event
if (type === "event" && c.syntax) {
c.syntax.eventType = c.syntax.return;
c.syntax.return = undefined;
}
if (type === "variable" && c.syntax) {
c.syntax.variableValue = c.syntax.return;
c.syntax.return = undefined;
}
if (type === "typealias" && c.syntax) {
c.syntax.typeAliasType = c.syntax.return;
c.syntax.return = undefined;
}
grouped[type].push(c);
})
var children = [];
for (var key in typeChildrenItems) {
if (typeChildrenItems.hasOwnProperty(key) && grouped.hasOwnProperty(key)) {
var typeChildrenItem = typeChildrenItems[key];
var items = grouped[key];
if (items && items.length > 0) {
var item = {};
for (var itemKey in typeChildrenItem) {
if (typeChildrenItem.hasOwnProperty(itemKey)){
item[itemKey] = typeChildrenItem[itemKey];
}
}
item.children = items;
children.push(item);
}
}
}
model.children = children;
}
function getTypePropertyName(type) {
if (!type) {
return undefined;
}
var loweredType = type.toLowerCase();
var definition = getDefinition(loweredType);
if (definition) {
return definition.typePropertyName;
}
return undefined;
}
function getDefinition(type) {
var classItems = getDefinitions(classCategory);
if (classItems.hasOwnProperty(type)) {
return classItems[type];
}
var namespaceItems = getDefinitions(namespaceCategory);
if (namespaceItems.hasOwnProperty(type)) {
return namespaceItems[type];
}
return undefined;
}
function getDefinitions(category) {
var namespaceItems = {
"package": { inPackage: true, typePropertyName: "inPackage", id: "packages" },
"namespace": { inNamespace: true, typePropertyName: "inNamespace", id: "namespaces" },
"class": { inClass: true, typePropertyName: "inClass", id: "classes" },
"struct": { inStruct: true, typePropertyName: "inStruct", id: "structs" },
"interface": { inInterface: true, typePropertyName: "inInterface", id: "interfaces" },
"enum": { inEnum: true, typePropertyName: "inEnum", id: "enums" },
"delegate": { inDelegate: true, typePropertyName: "inDelegate", id: "delegates" },
"function": { inFunction: true, typePropertyName: "inFunction", id: "functions", isEmbedded: true },
"variable": { inVariable: true, typePropertyName: "inVariable", id: "variables", isEmbedded: true },
"typealias": { inTypeAlias: true, typePropertyName: "inTypeAlias", id: "typealiases", isEmbedded: true },
};
var classItems = {
"constructor": { inConstructor: true, typePropertyName: "inConstructor", id: "constructors" },
"field": { inField: true, typePropertyName: "inField", id: "fields" },
"property": { inProperty: true, typePropertyName: "inProperty", id: "properties" },
"method": { inMethod: true, typePropertyName: "inMethod", id: "methods" },
"event": { inEvent: true, typePropertyName: "inEvent", id: "events" },
"operator": { inOperator: true, typePropertyName: "inOperator", id: "operators" },
"eii": { inEii: true, typePropertyName: "inEii", id: "eii" },
"member": { inMember: true, typePropertyName: "inMember", id: "members"},
"function": { inFunction: true, typePropertyName: "inFunction", id: "functions" }
};
if (category === 'class') {
return classItems;
}
if (category === 'ns') {
return namespaceItems;
}
console.err("category '" + category + "' is not valid.");
return undefined;
}
function normalizeLanguageValuePairs(list) {
if (list[0] && list[0].lang && list[0].value) {
return list[0].value;
}
return list;
}
// Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. See LICENSE file in the project root for full license information.
/**
* This method will be called at the start of exports.transform in UniversalReference.html.primary.js
*/
exports.preTransform = function (model) {
return model;
}
/**
* This method will be called at the end of exports.transform in UniversalReference.html.primary.js
*/
exports.postTransform = function (model) {
return model;
}
\ No newline at end of file
// Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. See LICENSE file in the project root for full license information.
var urefCommon = require('./UniversalReference.common.js');
var extension = require('./UniversalReference.extension.js');
exports.transform = function (model) {
if (extension && extension.preTransform) {
model = extension.preTransform(model);
}
if (urefCommon && urefCommon.transform) {
model = urefCommon.transform(model);
}
model._disableToc = model._disableToc || !model._tocPath || (model._navPath === model._tocPath);
if (extension && extension.postTransform) {
model = extension.postTransform(model);
}
return model;
}
exports.getOptions = function (model) {
return {
"bookmarks": urefCommon.getBookmarks(model)
};
}
\ No newline at end of file
{{!Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. See LICENSE file in the project root for full license information.}}
{{!master(layout/_master.tmpl)}}
{{#isNamespace}}
{{>partials/uref/namespace}}
{{/isNamespace}}
{{#isClass}}
{{>partials/uref/class}}
{{/isClass}}
{{#isEnum}}
{{>partials/enum}}
{{/isEnum}}
// Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. See LICENSE file in the project root for full license information.
exports.path = {};
exports.path.getFileNameWithoutExtension = getFileNameWithoutExtension;
exports.path.getDirectoryName = getDirectoryName;
exports.getHtmlId = getHtmlId;
exports.getViewSourceHref = getViewSourceHref;
exports.getImproveTheDocHref = getImproveTheDocHref;
exports.processSeeAlso = processSeeAlso;
exports.isAbsolutePath = isAbsolutePath;
exports.isRelativePath = isRelativePath;
function getFileNameWithoutExtension(path) {
if (!path || path[path.length - 1] === '/' || path[path.length - 1] === '\\') return '';
var fileName = path.split('\\').pop().split('/').pop();
return fileName.slice(0, fileName.lastIndexOf('.'));
}
function getDirectoryName(path) {
if (!path) return '';
var index = path.lastIndexOf('/');
return path.slice(0, index + 1);
}
function getHtmlId(input) {
if (!input) return '';
return input.replace(/\W/g, '_');
}
// Note: the parameter `gitContribute` won't be used in this function
function getViewSourceHref(item, gitContribute, gitUrlPattern) {
if (!item || !item.source || !item.source.remote) return '';
return getRemoteUrl(item.source.remote, item.source.startLine - '0' + 1, null, gitUrlPattern);
}
function getImproveTheDocHref(item, gitContribute, gitUrlPattern) {
if (!item) return '';
if (!item.documentation || !item.documentation.remote) {
return getNewFileUrl(item, gitContribute, gitUrlPattern);
} else {
return getRemoteUrl(item.documentation.remote, item.documentation.startLine + 1, gitContribute, gitUrlPattern);
}
}
function processSeeAlso(item) {
if (item.seealso) {
for (var key in item.seealso) {
addIsCref(item.seealso[key]);
}
}
item.seealso = item.seealso || null;
}
function isAbsolutePath(path) {
return /^(\w+:)?\/\//g.test(path);
}
function isRelativePath(path) {
if (!path) return false;
return !exports.isAbsolutePath(path);
}
var gitUrlPatternItems = {
'github': {
// HTTPS form: https://github.com/{org}/{repo}.git
// SSH form: git@github.com:{org}/{repo}.git
// generate URL: https://github.com/{org}/{repo}/blob/{branch}/{path}
'testRegex': /^(https?:\/\/)?(\S+\@)?(\S+\.)?github\.com(\/|:).*/i,
'generateUrl': function (gitInfo) {
var url = normalizeGitUrlToHttps(gitInfo.repo);
url = getRepoWithoutGitExtension(url);
url += '/blob' + '/' + gitInfo.branch + '/' + gitInfo.path;
if (gitInfo.startLine && gitInfo.startLine > 0) {
url += '/#L' + gitInfo.startLine;
}
return url;
},
'generateNewFileUrl': function (gitInfo, uid) {
var url = normalizeGitUrlToHttps(gitInfo.repo);
url = getRepoWithoutGitExtension(url);
url += '/new';
url += '/' + gitInfo.branch;
url += '/' + getOverrideFolder(gitInfo.apiSpecFolder);
url += '/new?filename=' + getHtmlId(uid) + '.md';
url += '&value=' + encodeURIComponent(getOverrideTemplate(uid));
return url;
}
},
'vso': {
// HTTPS form: https://{account}@dev.azure.com/{account}/{project}/_git/{repo}
// HTTPS form: https://{user}.visualstudio.com/{org}/_git/{repo}
// SSH form: git@ssh.dev.azure.com:v3/{account}/{project}/{repo}
// SSH form: ssh://{user}@{user}.visualstudio.com:22/{org}/_git/{repo}
// generated URL under branch: https://{account}@dev.azure.com/{account}/{project}/_git/{repo}?version=GB{branch}
// generated URL under branch: https://{user}.visualstudio.com/{org}/_git/{repo}?path={path}&version=GB{branch}
// generated URL under detached HEAD: https://{user}.visualstudio.com/{org}/_git/{repo}?path={path}&version=GC{commit}
'testRegex': /^(https?:\/\/)?(ssh:\/\/\S+\@)?(\S+@)?(\S+\.)?(dev\.azure|visualstudio)\.com(\/|:).*/i,
'generateUrl': function (gitInfo) {
var url = normalizeGitUrlToHttps(gitInfo.repo);
var branchPrefix = /[0-9a-fA-F]{40}/.test(gitInfo.branch) ? 'GC' : 'GB';
url += '?path=' + gitInfo.path + '&version=' + branchPrefix + gitInfo.branch;
if (gitInfo.startLine && gitInfo.startLine > 0) {
url += '&line=' + gitInfo.startLine;
}
return url;
},
'generateNewFileUrl': function (gitInfo, uid) {
return '';
}
},
'bitbucket': {
// HTTPS form: https://{user}@bitbucket.org/{org}/{repo}.git
// SSH form: git@bitbucket.org:{org}/{repo}.git
// generate URL: https://bitbucket.org/{org}/{repo}/src/{branch}/{path}
'testRegex': /^(https?:\/\/)?(\S+\@)?(\S+\.)?bitbucket\.org(\/|:).*/i,
'generateUrl': function (gitInfo) {
var url = normalizeGitUrlToHttps(gitInfo.repo);
url = getRepoWithoutGitExtension(url);
url += '/src' + '/' + gitInfo.branch + '/' + gitInfo.path;
if (gitInfo.startLine && gitInfo.startLine > 0) {
url += '#lines-' + gitInfo.startLine;
}
return url;
},
'generateNewFileUrl': function (gitInfo, uid) {
return '';
}
}
}
function getRepoWithoutGitExtension(repo) {
if (repo.substr(-4) === '.git') {
repo = repo.substr(0, repo.length - 4);
}
return repo;
}
function normalizeGitUrlToHttps(repo) {
var pos = repo.indexOf('@');
if (pos == -1) return repo;
return 'https://' + repo.substr(pos + 1).replace(/:[0-9]+/g, '').replace(/:/g, '/');
}
function getNewFileUrl(item, gitContribute, gitUrlPattern) {
// do not support VSO for now
if (!item.source) {
return '';
}
var gitInfo = getGitInfo(gitContribute, item.source.remote);
if (!gitInfo.repo || !gitInfo.branch || !gitInfo.path) {
return '';
}
var patternName = getPatternName(gitInfo.repo, gitUrlPattern);
if (!patternName) return patternName;
return gitUrlPatternItems[patternName].generateNewFileUrl(gitInfo, item.uid);
}
function getRemoteUrl(remote, startLine, gitContribute, gitUrlPattern) {
var gitInfo = getGitInfo(gitContribute, remote);
if (!gitInfo.repo || !gitInfo.branch || !gitInfo.path) {
return '';
}
var patternName = getPatternName(gitInfo.repo, gitUrlPattern);
if (!patternName) return '';
gitInfo.startLine = startLine;
return gitUrlPatternItems[patternName].generateUrl(gitInfo);
}
function getGitInfo(gitContribute, gitRemote) {
// apiSpecFolder defines the folder contains overwrite files for MRef, the default value is apiSpec
var defaultApiSpecFolder = 'apiSpec';
var result = {};
if (gitContribute && gitContribute.apiSpecFolder) {
result.apiSpecFolder = gitContribute.apiSpecFolder;
} else {
result.apiSpecFolder = defaultApiSpecFolder;
}
mergeKey(gitContribute, gitRemote, result, 'repo');
mergeKey(gitContribute, gitRemote, result, 'branch');
mergeKey(gitContribute, gitRemote, result, 'path');
return result;
function mergeKey(source, sourceFallback, dest, key) {
if (source && source.hasOwnProperty(key)) {
dest[key] = source[key];
} else if (sourceFallback && sourceFallback.hasOwnProperty(key)) {
dest[key] = sourceFallback[key];
}
}
}
function getPatternName(repo, gitUrlPattern) {
if (gitUrlPattern && gitUrlPattern.toLowerCase() in gitUrlPatternItems) {
return gitUrlPattern.toLowerCase();
} else {
for (var p in gitUrlPatternItems) {
if (gitUrlPatternItems[p].testRegex.test(repo)) {
return p;
}
}
}
return '';
}
function getOverrideFolder(path) {
if (!path) return "";
path = path.replace(/\\/g, '/');
if (path.charAt(path.length - 1) == '/') path = path.substring(0, path.length - 1);
return path;
}
function getOverrideTemplate(uid) {
if (!uid) return "";
var content = "";
content += "---\n";
content += "uid: " + uid + "\n";
content += "summary: '*You can override summary for the API here using *MARKDOWN* syntax'\n";
content += "---\n";
content += "\n";
content += "*Please type below more information about this API:*\n";
content += "\n";
return content;
}
function addIsCref(seealso) {
if (!seealso.linkType || seealso.linkType.toLowerCase() == "cref") {
seealso.isCref = true;
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment