@@ -472,6 +472,7 @@ def convert_arg_line_to_args(self, arg_line):
472472 parser .add_argument (
473473 "--use_vcpkg" ,
474474 action = "store_true" ,
475+ default = is_windows () and ("VCPKG_INSTALLATION_ROOT" in os .environ ),
475476 help = "Use vcpkg to search dependencies. Requires CMAKE_TOOLCHAIN_FILE for vcpkg.cmake" ,
476477 )
477478
@@ -1109,6 +1110,34 @@ def generate_build_tree(
11091110 "-DRISCV_QEMU_PATH:PATH=" + args .riscv_qemu_path ,
11101111 "-DCMAKE_TOOLCHAIN_FILE=" + os .path .join (source_dir , "cmake" , "riscv64.toolchain.cmake" ),
11111112 ]
1113+ if args .use_vcpkg :
1114+ # Setup CMake flags for vcpkg
1115+ vcpkg_install_options = ['--x-feature=tests' ]
1116+ vcpkg_installation_root = os .environ .get ("VCPKG_INSTALLATION_ROOT" )
1117+ if vcpkg_installation_root is None :
1118+ run_subprocess (["git" , "clone" , "https://github.com/microsoft/vcpkg.git" , "--recursive" ], cwd = build_dir )
1119+ vcpkg_installation_root = os .path .join (build_dir , 'vcpkg' )
1120+ vcpkg_toolchain_path = os .path .join (vcpkg_installation_root , 'scripts' ,'buildsystems' ,'vcpkg.cmake' )
1121+ add_default_definition (cmake_extra_defines , "CMAKE_TOOLCHAIN_FILE" , vcpkg_toolchain_path );
1122+ if args .use_binskim_compliant_compile_flags :
1123+ overlay_triplets_dir = os .path .join (source_dir , 'cmake' ,'custom-triplets' );
1124+ vcpkg_install_options .append ("--overlay-triplets=%s" % overlay_triplets_dir )
1125+ # VCPKG_INSTALL_OPTIONS is a CMake list. It must be joined by semicolons
1126+ add_default_definition (cmake_extra_defines , "VCPKG_INSTALL_OPTIONS" , ';' .join (vcpkg_install_options ))
1127+ # Choose the cmake triplet
1128+ if is_windows () and not args .build_wasm :
1129+ target_arch = platform .machine ()
1130+ cpu_arch = platform .architecture ()[0 ]
1131+ if target_arch == "AMD64" :
1132+ if cpu_arch == "32bit" or args .x86 :
1133+ triplet = "x86-windows-static" if args .enable_msvc_static_runtime else "x86-windows-static-md"
1134+ else :
1135+ triplet = "x64-windows-static" if args .enable_msvc_static_runtime else "x64-windows-static-md"
1136+ elif target_arch == "ARM64" :
1137+ triplet = "arm64-windows-static" if args .enable_msvc_static_runtime else "arm64-windows-static-md"
1138+ else :
1139+ raise BuildError ("unknown python arch" )
1140+ add_default_definition (cmake_extra_defines , "VCPKG_TARGET_TRIPLET" , triplet )
11121141
11131142 # By default on Windows we currently support only cross compiling for ARM/ARM64
11141143 # (no native compilation supported through this script).
@@ -1659,7 +1688,7 @@ def generate_build_tree(
16591688 f"-DCMAKE_BUILD_TYPE={ config } " ,
16601689 (
16611690 f"-DCMAKE_PREFIX_PATH={ build_dir } /{ config } /installed"
1662- if preinstalled_dir .exists () and not (args .arm64 or args .arm64ec or args .arm )
1691+ if preinstalled_dir .exists () and not (args .arm64 or args .arm64ec or args .arm or args . use_vcpkg )
16631692 else ""
16641693 ),
16651694 ],
@@ -2550,7 +2579,9 @@ def main():
25502579 args = parse_arguments ()
25512580
25522581 print (args )
2553-
2582+ if args .ios or args .android or args .build_wasm :
2583+ # Not supported yet
2584+ args .use_vcpkg = False
25542585 if os .getenv ("ORT_BUILD_WITH_CACHE" ) == "1" :
25552586 args .use_cache = True
25562587
0 commit comments