From 8f619470e95bab5c101e98892e2ff1edebca57e8 Mon Sep 17 00:00:00 2001 From: Changming Sun Date: Thu, 19 Dec 2024 14:08:35 -0800 Subject: [PATCH] update --- cmake/CMakeLists.txt | 11 +++++++--- cmake/onnxruntime_unittests.cmake | 5 +++++ tools/ci_build/build.py | 35 +++++++++++++++++++++++++++++-- 3 files changed, 46 insertions(+), 5 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index d2fe7e7457983..058607dd49cf0 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -890,7 +890,7 @@ if (onnxruntime_USE_QNN) if (MSVC OR ${CMAKE_SYSTEM_NAME} STREQUAL "Linux") file(GLOB QNN_LIB_FILES LIST_DIRECTORIES false "${onnxruntime_QNN_HOME}/lib/${QNN_ARCH_ABI}/libQnn*.so" - "${onnxruntime_QNN_HOME}/lib/${QNN_ARCH_ABI}/Qnn*.dll" + "${onnxruntime_QNN_HOME}/lib/${QNN_ARCH_ABI}/Qnn*.dll" "${onnxruntime_QNN_HOME}/lib/${QNN_ARCH_ABI}/libHtpPrepare.so" "${onnxruntime_QNN_HOME}/lib/${QNN_ARCH_ABI}/HtpPrepare.dll") if (${QNN_ARCH_ABI} STREQUAL "aarch64-windows-msvc" OR ${QNN_ARCH_ABI} STREQUAL "arm64x-windows-msvc") @@ -1054,7 +1054,10 @@ function(onnxruntime_set_compile_flags target_name) foreach(CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORY ${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES}) target_compile_options(${target_name} PRIVATE "$<$:/external:I${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORY}>") endforeach() - + if(VCPKG_INSTALLED_DIR) + cmake_path(NATIVE_PATH VCPKG_INSTALLED_DIR NORMALIZE VCPKG_INSTALLED_DIR_native) + target_compile_options(${target_name} PRIVATE "$<$:SHELL:/external:I ${VCPKG_INSTALLED_DIR}>") + endif() foreach(onnxruntime_external_lib IN LISTS onnxruntime_EXTERNAL_LIBRARIES) #TODO: the list contains cmake keywords like "debug". We should exclude them. if(TARGET ${onnxruntime_external_lib}) @@ -1084,7 +1087,9 @@ function(onnxruntime_set_compile_flags target_name) # We do not treat warnings from 3rd-party libraries as errors. In order to do that, we need to add their header files locations to /external:I. target_compile_options(${target_name} PRIVATE "$<$:/experimental:external>" "$<$:SHELL:--compiler-options /experimental:external>") target_compile_options(${target_name} PRIVATE "$<$:/external:W0>" "$<$:SHELL:--compiler-options /external:W0>") - target_compile_options(${target_name} PRIVATE "$<$:/external:templates->" "$<$:SHELL:--compiler-options /external:templates->") + #if(NOT onnxruntime_USE_VCPKG) + # target_compile_options(${target_name} PRIVATE "$<$:/external:templates->" "$<$:SHELL:--compiler-options /external:templates->") + #endif() target_compile_options(${target_name} PRIVATE "$<$:/external:I${CMAKE_CURRENT_SOURCE_DIR}>" "$<$:SHELL:--compiler-options /external:I${CMAKE_CURRENT_SOURCE_DIR}>") target_compile_options(${target_name} PRIVATE "$<$:/external:I${CMAKE_CURRENT_BINARY_DIR}>" "$<$:SHELL:--compiler-options /external:I${CMAKE_CURRENT_BINARY_DIR}>") if (onnxruntime_ENABLE_STATIC_ANALYSIS) diff --git a/cmake/onnxruntime_unittests.cmake b/cmake/onnxruntime_unittests.cmake index e822f0a3655fc..b022340b036e3 100644 --- a/cmake/onnxruntime_unittests.cmake +++ b/cmake/onnxruntime_unittests.cmake @@ -1007,6 +1007,11 @@ add_dependencies(onnx_test_data_proto onnx_proto ${onnxruntime_EXTERNAL_DEPENDEN #onnx_proto target should mark this definition as public, instead of private target_compile_definitions(onnx_test_data_proto PRIVATE "-DONNX_API=") onnxruntime_add_include_to_target(onnx_test_data_proto onnx_proto) +if (MSVC) + # Cutlass code has an issue with the following: + # warning C4100: 'magic': unreferenced formal parameter + target_compile_options(onnx_test_data_proto PRIVATE "/wd4100") +endif() target_include_directories(onnx_test_data_proto PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) set_target_properties(onnx_test_data_proto PROPERTIES FOLDER "ONNXRuntimeTest") if(NOT DEFINED onnx_SOURCE_DIR) diff --git a/tools/ci_build/build.py b/tools/ci_build/build.py index 3527a89ca7a7b..93a6385adec52 100644 --- a/tools/ci_build/build.py +++ b/tools/ci_build/build.py @@ -471,6 +471,7 @@ def convert_arg_line_to_args(self, arg_line): parser.add_argument( "--use_vcpkg", action="store_true", + default=is_windows() and ("VCPKG_INSTALLATION_ROOT" in os.environ), help="Use vcpkg to search dependencies. Requires CMAKE_TOOLCHAIN_FILE for vcpkg.cmake", ) @@ -1107,6 +1108,34 @@ def generate_build_tree( "-DRISCV_QEMU_PATH:PATH=" + args.riscv_qemu_path, "-DCMAKE_TOOLCHAIN_FILE=" + os.path.join(source_dir, "cmake", "riscv64.toolchain.cmake"), ] + if args.use_vcpkg: + # Setup CMake flags for vcpkg + vcpkg_install_options = ['--x-feature=tests'] + vcpkg_installation_root = os.environ.get("VCPKG_INSTALLATION_ROOT") + if vcpkg_installation_root is None: + run_subprocess(["git", "clone", "https://github.com/microsoft/vcpkg.git", "--recursive"], cwd=build_dir) + vcpkg_installation_root = os.path.join(build_dir, 'vcpkg') + vcpkg_toolchain_path = os.path.join(vcpkg_installation_root, 'scripts','buildsystems','vcpkg.cmake') + add_default_definition(cmake_extra_defines, "CMAKE_TOOLCHAIN_FILE", vcpkg_toolchain_path); + if args.use_binskim_compliant_compile_flags: + overlay_triplets_dir = os.path.join(source_dir, 'cmake','custom-triplets'); + vcpkg_install_options.append("--overlay-triplets=%s" % overlay_triplets_dir) + # VCPKG_INSTALL_OPTIONS is a CMake list. It must be joined by semicolons + add_default_definition(cmake_extra_defines, "VCPKG_INSTALL_OPTIONS", ';'.join(vcpkg_install_options)) + # Choose the cmake triplet + if is_windows() and not args.build_wasm: + target_arch = platform.machine() + cpu_arch = platform.architecture()[0] + if target_arch == "AMD64": + if cpu_arch == "32bit" or args.x86: + triplet = "x86-windows-static" if args.enable_msvc_static_runtime else "x86-windows-static-md" + else: + triplet = "x64-windows-static" if args.enable_msvc_static_runtime else "x64-windows-static-md" + elif target_arch == "ARM64": + triplet = "arm64-windows-static" if args.enable_msvc_static_runtime else "arm64-windows-static-md" + else: + raise BuildError("unknown python arch") + add_default_definition(cmake_extra_defines, "VCPKG_TARGET_TRIPLET", triplet) # By default on Windows we currently support only cross compiling for ARM/ARM64 # (no native compilation supported through this script). @@ -1657,7 +1686,7 @@ def generate_build_tree( f"-DCMAKE_BUILD_TYPE={config}", ( f"-DCMAKE_PREFIX_PATH={build_dir}/{config}/installed" - if preinstalled_dir.exists() and not (args.arm64 or args.arm64ec or args.arm) + if preinstalled_dir.exists() and not (args.arm64 or args.arm64ec or args.arm or args.use_vcpkg) else "" ), ], @@ -2548,7 +2577,9 @@ def main(): args = parse_arguments() print(args) - + if args.ios or args.android or args.build_wasm: + # Not supported yet + args.use_vcpkg = False if os.getenv("ORT_BUILD_WITH_CACHE") == "1": args.use_cache = True