try with custom csharp preprocessor define cmake

This commit is contained in:
carzh 2025-02-07 15:38:00 -08:00
parent e6cd1e8070
commit 55ba520c8f
3 changed files with 58 additions and 0 deletions

View file

@ -257,6 +257,8 @@ option(onnxruntime_USE_OPENVINO_INTERFACE "Build ONNXRuntime shared lib which is
option(onnxruntime_USE_VITISAI_INTERFACE "Build ONNXRuntime shared lib which is compatible with Vitis-AI EP interface" OFF)
option(onnxruntime_USE_QNN_INTERFACE "Build ONNXRuntime shared lib which is compatible with QNN EP interface" OFF)
option(onnxruntime_ADD_CSHARP_PREDEFINES "Add predefines for C# build" OFF)
# ENABLE_TRAINING includes all training functionality
# The following 2 entry points
# 1. ORTModule
@ -1820,6 +1822,11 @@ if (onnxruntime_BUILD_CSHARP)
list(APPEND ONNXRUNTIME_CMAKE_FILES onnxruntime_csharp)
endif()
if (onnxruntime_ADD_CSHARP_PREDEFINES)
message(STATUS "Generating CSharp preprocessor defines")
list(APPEND ONNXRUNTIME_CMAKE_FILES onnxruntime_csharp_predefines)
endif()
if (CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
message(STATUS "WebAssembly Build is enabled")
list(APPEND ONNXRUNTIME_CMAKE_FILES onnxruntime_webassembly)

View file

@ -0,0 +1,50 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
set (CSHARP_ROOT ${PROJECT_SOURCE_DIR}/../csharp)
if (onnxruntime_USE_CUDA)
STRING(APPEND CSHARP_PREPROCESSOR_DEFINES "USE_CUDA;")
endif()
if (onnxruntime_USE_DNNL)
STRING(APPEND CSHARP_PREPROCESSOR_DEFINES "USE_DNNL;")
endif()
if (onnxruntime_USE_DML)
STRING(APPEND CSHARP_PREPROCESSOR_DEFINES "USE_DML;")
endif()
if (onnxruntime_USE_MIGRAPHX)
STRING(APPEND CSHARP_PREPROCESSOR_DEFINES "USE_MIGRAPHX;")
endif()
if (onnxruntime_USE_NNAPI_BUILTIN)
STRING(APPEND CSHARP_PREPROCESSOR_DEFINES "USE_NNAPI;")
endif()
if (onnxruntime_USE_OPENVINO)
STRING(APPEND CSHARP_PREPROCESSOR_DEFINES "USE_OPENVINO;")
endif()
if (onnxruntime_USE_ROCM)
STRING(APPEND CSHARP_PREPROCESSOR_DEFINES "USE_ROCM;")
endif()
if (onnxruntime_USE_TENSORRT)
STRING(APPEND CSHARP_PREPROCESSOR_DEFINES "USE_TENSORRT;")
endif()
if (onnxruntime_USE_XNNPACK)
STRING(APPEND CSHARP_PREPROCESSOR_DEFINES "USE_XNNPACK;")
endif()
if (onnxruntime_ENABLE_TRAINING_APIS)
STRING(APPEND CSHARP_PREPROCESSOR_DEFINES "__TRAINING_ENABLED_NATIVE_BUILD__;")
endif()
# generate Directory.Build.props
set(DIRECTORY_BUILD_PROPS_COMMENT "WARNING: This is a generated file, please do not check it in!")
configure_file(${CSHARP_ROOT}/Directory.Build.props.in
${CSHARP_ROOT}/Directory.Build.props
@ONLY)

View file

@ -1028,6 +1028,7 @@ def generate_build_tree(
"-Donnxruntime_USE_MIMALLOC=" + ("ON" if args.use_mimalloc else "OFF"),
"-Donnxruntime_ENABLE_PYTHON=" + ("ON" if args.enable_pybind else "OFF"),
"-Donnxruntime_BUILD_CSHARP=" + ("ON" if args.build_csharp else "OFF"),
"-Donnxruntime_ADD_CSHARP_PREDEFINES=" + ("ON" if args.build_csharp or args.android else "OFF"),
"-Donnxruntime_BUILD_JAVA=" + ("ON" if args.build_java else "OFF"),
"-Donnxruntime_BUILD_NODEJS=" + ("ON" if args.build_nodejs else "OFF"),
"-Donnxruntime_BUILD_OBJC=" + ("ON" if args.build_objc else "OFF"),