onnxruntime/cmake/CMakePresets.json
PARK DongHa f633caa0b1
Create CMake option onnxruntime_USE_VCPKG (#21348)
### Changes

1. CMake option `onnxruntime_USE_VCPKG`. It will be used in the vcpkg
port
* Unit test may fail because this option leads to a mixture of
unexpected external library versions.
     Especially ONNX, Protobuf, and Flatbuffers version can be different
2. Overhaul of `onnxruntime_external_deps.cmake`
   * Make `FetchContent_Declare` to try `find_package`.  
See
https://cmake.org/cmake/help/latest/guide/using-dependencies/index.html
* Relocated `FetchContent_Declare` and `FetchContent_MakeAvailable`(or
`onnxruntime_fetchcontent_makeavailable`) to closer lines.
It was too hard to navigate the entire file to search related
sections...
* Alias `IMPORTED` targets like build targets (e.g. `ONNX::onnx` -->
`onnx`)

```cmake
# The script uses `find_package` with the changes.
# In this case, use vcpkg to search dependencies
# See https://cmake.org/cmake/help/latest/guide/using-dependencies/index.html
include(external/onnxruntime_external_deps.cmake)
```

3. Create CMakePresets.json and presets to [run vcpkg in manifest
mode](https://learn.microsoft.com/en-us/vcpkg/concepts/manifest-mode)
   * Currently, it's NOT for training build
   * Main triplets are `x64-windows` and `x64-osx`

```pwsh
Push-Location "cmake"
    cmake --preset "x64-windows-vcpkg"
    cmake --build --preset "x64-windows-vcpkg-debug"
Pop-Location
```
```bash
pushd "cmake"
    cmake --preset "x64-osx-vcpkg"
    cmake --build --preset "x64-osx-vcpkg-debug"
popd
```

4. Updated tools/ci_build/build.py
* `--use_vcpkg` option: it needs `CMAKE_TOOLCHAIN_FILE` with
[vcpkg.cmake toolchain
script](https://github.com/microsoft/vcpkg/blob/master/scripts/buildsystems/vcpkg.cmake)
* `--compile_no_warning_as_error` is recommended because library version
differences will cause unexpected compiler warnings

```bash
python ./tools/ci_build/build.py \
    --compile_no_warning_as_error \
    --use_vcpkg \
    --cmake_extra_defines "CMAKE_TOOLCHAIN_FILE:FILEPATH=${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" \
    --cmake_extra_defines "VCPKG_TARGET_TRIPLET=..."
```

5. Created Job `Vcpkg` for Windows and macOS
   * Show how to setup and use vcpkg.  
     Similar to the CMakePresets.json usage

### Motivation and Context

* Help #7150
* Help https://github.com/microsoft/vcpkg/pull/36850
   * https://github.com/luncliff/vcpkg-registry/pull/212
   * https://github.com/microsoft/vcpkg/pull/39881
* https://github.com/luncliff/vcpkg-registry/pull/215
   * https://github.com/luncliff/vcpkg-registry/pull/216
   * https://github.com/luncliff/vcpkg-registry/pull/227
*
https://cmake.org/cmake/help/latest/guide/using-dependencies/index.html
*
https://github.com/microsoft/vcpkg/blob/master/scripts/buildsystems/vcpkg.cmake

### Future Works?

More feature coverage with the vcpkg supported libraries

* CUDA feature support
* Training feature support
2024-09-10 16:39:27 -07:00

192 lines
6.4 KiB
JSON

{
"version": 6,
"cmakeMinimumRequired": {
"major": 3,
"minor": 25,
"patch": 0
},
"configurePresets": [
{
"name": "vcpkg-manifest",
"hidden": true,
"toolchainFile": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake",
"cacheVariables": {
"VCPKG_INSTALLED_DIR": "${sourceParentDir}/.build"
},
"environment": {
"VCPKG_FEATURE_FLGAS": "manifests,versions"
}
},
{
"name": "msvc-static-runtime",
"hidden": true,
"cacheVariables": {
"ONNX_USE_MSVC_STATIC_RUNTIME": true,
"protobuf_MSVC_STATIC_RUNTIME": true,
"gtest_force_shared_crt": false,
"CMAKE_MSVC_RUNTIME_LIBRARY": "MultiThreaded$<$<CONFIG:Debug>:Debug>"
}
},
{
"name": "unit-test",
"hidden": true,
"cacheVariables": {
"onnxruntime_RUN_ONNX_TESTS": true,
"onnxruntime_BUILD_BENCHMARKS": true,
"onnxruntime_BUILD_UNIT_TESTS": true,
"onnxruntime_GENERATE_TEST_REPORTS": true
}
},
{
"name": "x64-windows",
"inherits": [
"msvc-static-runtime",
"unit-test"
],
"generator": "Visual Studio 17 2022",
"architecture": "x64",
"binaryDir": "${sourceParentDir}/cmake_build/x64-windows",
"installDir": "${sourceParentDir}/cmake_build/out",
"cacheVariables": {
"onnxruntime_USE_XNNPACK": true,
"onnxruntime_USE_DML": true,
"onnxruntime_BUILD_SHARED_LIB": true,
"CMAKE_CONFIGURATION_TYPES": "Debug;Release"
},
"vendor": {
"microsoft.com/VisualStudioSettings/CMake/1.0": {
"intelliSenseMode": "windows-msvc-x64"
}
},
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Windows"
}
},
{
"name": "x64-windows-vcpkg",
"inherits": [
"unit-test",
"vcpkg-manifest"
],
"generator": "Visual Studio 17 2022",
"architecture": "x64",
"binaryDir": "${sourceParentDir}/cmake_build/x64-windows",
"installDir": "${sourceParentDir}/cmake_build/out",
"cacheVariables": {
"onnxruntime_USE_VCPKG": true,
"onnxruntime_USE_XNNPACK": false,
"onnxruntime_USE_DML": false,
"onnxruntime_BUILD_SHARED_LIB": true,
"CMAKE_MSVC_RUNTIME_LIBRARY": "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL",
"CMAKE_CONFIGURATION_TYPES": "Debug;Release",
"VCPKG_INSTALL_OPTIONS": "--x-feature=tests",
"VCPKG_TARGET_TRIPLET": "x64-windows"
}
},
{
"name": "x64-osx",
"inherits": [
"unit-test"
],
"generator": "Xcode",
"binaryDir": "${sourceParentDir}/cmake_build/x64-osx",
"installDir": "${sourceParentDir}/cmake_build/out",
"cacheVariables": {
"CMAKE_OSX_ARCHITECTURES": "x86_64",
"onnxruntime_BUILD_SHARED_LIB": true,
"onnxruntime_USE_XNNPACK": false,
"onnxruntime_USE_COREML": true,
"onnxruntime_BUILD_OBJC": true,
"onnxruntime_BUILD_APPLE_FRAMEWORK": true,
"CMAKE_CONFIGURATION_TYPES": "Debug;Release"
},
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Darwin"
}
},
{
"name": "x64-osx-vcpkg",
"inherits": [
"x64-osx",
"vcpkg-manifest"
],
"cacheVariables": {
"onnxruntime_USE_VCPKG": true,
"onnxruntime_USE_XNNPACK": false,
"onnxruntime_USE_COREML": false,
"onnxruntime_BUILD_OBJC": false,
"onnxruntime_BUILD_APPLE_FRAMEWORK": false,
"VCPKG_INSTALL_OPTIONS": "--x-feature=tests",
"VCPKG_TARGET_TRIPLET": "x64-osx"
}
}
],
"buildPresets": [
{
"name": "x64-windows-debug",
"configurePreset": "x64-windows",
"configuration": "Debug"
},
{
"name": "x64-windows-vcpkg-debug",
"configurePreset": "x64-windows-vcpkg",
"configuration": "Debug"
},
{
"name": "x64-osx-debug",
"configurePreset": "x64-osx",
"configuration": "Debug"
},
{
"name": "x64-osx-vcpkg-debug",
"configurePreset": "x64-osx-vcpkg",
"configuration": "Debug"
}
],
"testPresets": [
{
"name": "x64-windows-debug",
"configurePreset": "x64-windows",
"configuration": "Debug",
"output": {
"verbosity": "default",
"outputJUnitFile": "TEST-x64-windows-debug.xml",
"outputLogFile": "TEST-x64-windows-debug.log",
"outputOnFailure": true
},
"execution": {
"noTestsAction": "error",
"stopOnFailure": false
}
},
{
"name": "x64-windows-vcpkg-debug",
"inherits": "x64-windows-debug",
"configurePreset": "x64-windows-vcpkg"
},
{
"name": "x64-osx-debug",
"configurePreset": "x64-osx",
"configuration": "Debug",
"output": {
"verbosity": "default",
"outputJUnitFile": "TEST-x64-osx-debug.xml",
"outputLogFile": "TEST-x64-osx-debug.log",
"outputOnFailure": true
},
"execution": {
"noTestsAction": "error",
"stopOnFailure": false
}
},
{
"name": "x64-osx-vcpkg-debug",
"inherits": "x64-osx-debug",
"configurePreset": "x64-osx-vcpkg"
}
]
}