Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
snnn committed Dec 19, 2024
1 parent c286b5d commit 8f61947
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 5 deletions.
11 changes: 8 additions & 3 deletions cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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 "$<$<COMPILE_LANGUAGE:CXX,C>:/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 "$<$<COMPILE_LANGUAGE:CXX,C>: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})
Expand Down Expand Up @@ -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 "$<$<COMPILE_LANGUAGE:CXX,C>:/experimental:external>" "$<$<COMPILE_LANGUAGE:CUDA>:SHELL:--compiler-options /experimental:external>")
target_compile_options(${target_name} PRIVATE "$<$<COMPILE_LANGUAGE:CXX,C>:/external:W0>" "$<$<COMPILE_LANGUAGE:CUDA>:SHELL:--compiler-options /external:W0>")
target_compile_options(${target_name} PRIVATE "$<$<COMPILE_LANGUAGE:CXX,C>:/external:templates->" "$<$<COMPILE_LANGUAGE:CUDA>:SHELL:--compiler-options /external:templates->")
#if(NOT onnxruntime_USE_VCPKG)
# target_compile_options(${target_name} PRIVATE "$<$<COMPILE_LANGUAGE:CXX,C>:/external:templates->" "$<$<COMPILE_LANGUAGE:CUDA>:SHELL:--compiler-options /external:templates->")
#endif()
target_compile_options(${target_name} PRIVATE "$<$<COMPILE_LANGUAGE:CXX,C>:/external:I${CMAKE_CURRENT_SOURCE_DIR}>" "$<$<COMPILE_LANGUAGE:CUDA>:SHELL:--compiler-options /external:I${CMAKE_CURRENT_SOURCE_DIR}>")
target_compile_options(${target_name} PRIVATE "$<$<COMPILE_LANGUAGE:CXX,C>:/external:I${CMAKE_CURRENT_BINARY_DIR}>" "$<$<COMPILE_LANGUAGE:CUDA>:SHELL:--compiler-options /external:I${CMAKE_CURRENT_BINARY_DIR}>")
if (onnxruntime_ENABLE_STATIC_ANALYSIS)
Expand Down
5 changes: 5 additions & 0 deletions cmake/onnxruntime_unittests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
35 changes: 33 additions & 2 deletions tools/ci_build/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)

Expand Down Expand Up @@ -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).
Expand Down Expand Up @@ -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 ""
),
],
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 8f61947

Please sign in to comment.