Skip to content

Commit b7d1051

Browse files
qti-hungjuiwnaomiOvad
authored andcommitted
Make local mirror of cmake dependencies configurable (microsoft#26042)
### Description <!-- Describe your changes. --> - Added support for the `--cmake_deps_mirror_dir` option to allow users to specify a custom local directory for CMake dependencies. - Improved logging to show the source of `FetchContent` in CMake. ### Motivation and Context <!-- - Why is this change required? What problem does it solve? - If it fixes an open issue, please link to the issue here. --> - Previously, ONNX Runtime searched for CMake dependencies only in the default `<repo_root>/mirror` directory. - This change enables users to configure an alternative location for storing CMake dependencies, offering greater flexibility in build environments.
1 parent 0c96542 commit b7d1051

File tree

5 files changed

+13
-6
lines changed

5 files changed

+13
-6
lines changed

cmake/CMakeLists.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,9 +287,13 @@ if (onnxruntime_ENABLE_TRAINING_APIS)
287287
endif()
288288

289289

290-
# Single output director for all binaries
290+
# Single output directory for all binaries
291291
set(RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin CACHE PATH "Single output directory for all binaries.")
292292

293+
# Local mirror directory of cmake dependencies
294+
set(REPO_ROOT ${PROJECT_SOURCE_DIR}/..)
295+
set(onnxruntime_CMAKE_DEPS_MIRROR_DIR ${REPO_ROOT}/mirror CACHE PATH "Path to the local mirror of cmake dependencies")
296+
293297

294298
include(FetchContent)
295299

@@ -425,7 +429,6 @@ if (onnxruntime_EXTENDED_MINIMAL_BUILD AND NOT onnxruntime_MINIMAL_BUILD)
425429
set(onnxruntime_MINIMAL_BUILD ON)
426430
endif()
427431

428-
set(REPO_ROOT ${PROJECT_SOURCE_DIR}/..)
429432
set(ONNXRUNTIME_ROOT ${PROJECT_SOURCE_DIR}/../onnxruntime)
430433
set(ORTTRAINING_ROOT ${PROJECT_SOURCE_DIR}/../orttraining)
431434
set(ORTTRAINING_SOURCE_DIR ${ORTTRAINING_ROOT}/orttraining)

cmake/external/helper_functions.cmake

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
# 2. Set the cmake property COMPILE_WARNING_AS_ERROR to OFF for these external projects.
55

66
function(onnxruntime_fetchcontent_declare contentName)
7+
cmake_parse_arguments(PARSE_ARGV 1 ARG "" "URL;SOURCE_SUBDIR" "")
8+
message(STATUS "Fetch ${contentName} from ${ARG_URL}")
79
FetchContent_Declare(${ARGV})
810
string(TOLOWER ${contentName} contentNameLower)
9-
list(FIND ARGN SOURCE_SUBDIR index_SOURCE_SUBDIR)
10-
if(index_SOURCE_SUBDIR GREATER_EQUAL 0)
11-
cmake_parse_arguments(PARSE_ARGV 1 ARG "" "SOURCE_SUBDIR" "")
11+
if(NOT "${ARG_SOURCE_SUBDIR}" STREQUAL "")
1212
set(onnxruntime_${contentNameLower}_cmake_src_dir "${ARG_SOURCE_SUBDIR}" PARENT_SCOPE)
1313
endif()
1414
endfunction()

cmake/external/onnxruntime_external_deps.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ foreach(ONNXRUNTIME_DEP IN LISTS ONNXRUNTIME_DEPS_LIST)
2020

2121
if(ONNXRUNTIME_DEP_URL MATCHES "^https://")
2222
# Search a local mirror folder
23-
string(REGEX REPLACE "^https://" "${REPO_ROOT}/mirror/" LOCAL_URL "${ONNXRUNTIME_DEP_URL}")
23+
string(REGEX REPLACE "^https://" "${onnxruntime_CMAKE_DEPS_MIRROR_DIR}/" LOCAL_URL "${ONNXRUNTIME_DEP_URL}")
2424

2525
if(EXISTS "${LOCAL_URL}")
2626
cmake_path(ABSOLUTE_PATH LOCAL_URL)

tools/ci_build/build.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,6 +1015,9 @@ def generate_build_tree(
10151015
if path_to_protoc_exe:
10161016
cmake_args += [f"-DONNX_CUSTOM_PROTOC_EXECUTABLE={path_to_protoc_exe}"]
10171017

1018+
if args.cmake_deps_mirror_dir:
1019+
cmake_args += [f"-Donnxruntime_CMAKE_DEPS_MIRROR_DIR={args.cmake_deps_mirror_dir}"]
1020+
10181021
if args.fuzz_testing:
10191022
if not (
10201023
args.build_shared_lib

tools/ci_build/build_args.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ def add_testing_args(parser: argparse.ArgumentParser) -> None:
204204
help="Run onnx_test_runner against test data. Only used in ONNX Runtime's CI pipelines",
205205
)
206206
parser.add_argument("--path_to_protoc_exe", help="Path to protoc executable.")
207+
parser.add_argument("--cmake_deps_mirror_dir", help="Path to the local mirror of cmake dependencies.")
207208
parser.add_argument("--fuzz_testing", action="store_true", help="Enable Fuzz testing.")
208209
parser.add_argument(
209210
"--enable_symbolic_shape_infer_tests",

0 commit comments

Comments
 (0)