vcpkg offers seamless integration with CMake to make installed packages available in
your projects automatically. The mechanism in which vcpkg integrates is by providing a CMake toolchain file.
The first time CMake configures a project, it runs internal search routines to locate a viable
toolchain (compiler,
linker, etc.). This search happens within the
project() function in
your CMakeLists.txt.
To customize the toolchain selection process, CMake supports using custom CMake-language scripts,
known as toolchain files. A toolchain file is specified by setting the CMAKE_TOOLCHAIN_FILE
variable. CMake evaluates the contents of the provided toolchain script and sets variable definitions, paths to
required build tools, and other build parameters, such as cross-compilation flags, accordingly.
When you set CMAKE_TOOLCHAIN_FILE to use the vcpkg toolchain
(<vcpkg-root>/scripts/buildsystems/vcpkg.cmake), vcpkg takes advantage of the toolchain file
mechanism to inject code to integrate with built-in CMake functions transparently to you.
You can still use a toolchain file to configure your own toolsets by using the
VCPKG_CHAINLOAD_TOOLCHAIN_FILE triplet variable.
The vcpkg integration works differently depending on the operation mode you're using:
In classic mode, vcpkg sets CMake search paths
appropriately to make installed packages available via the find_package(),
find_library(), and find_path() functions.
In manifest mode, in addition to the above,
the toolchain detects manifest files (vcpkg.json files) and runs vcpkg install to automatically acquire the project's dependencies.
Because the toolchain file is evaluated during the project() call, all CMake-level variables that
modify a vcpkg setting must be set before the first call to project(). It may also be necessary to
reconfigure your CMake project if you modify any vcpkg setting that results in ABI
hash changes.
If you set CMAKE_TOOLCHAIN_FILE in your CMakeList.txt file, make sure that
the variable is set before any calls to project().
Projects configured to use the vcpkg toolchain file (via the CMake setting CMAKE_TOOLCHAIN_FILE) can find libraries from vcpkg using the standard CMake functions: find_package(), find_path(), and find_library().
We recommend using CMake Presets to specify your toolchain file. For example, if you have defined the environment variable VCPKG_ROOT, you can use the following CMakePresets.json and pass --preset debug on the configure line:
vcpkg supports CMake's native mechanisms for finding libraries: find_package(), find_library(), and find_path(). When installing libraries with specific CMake support, vcpkg will display usage information on how to consume the library:
The package zlib is compatible with built-in CMake targets:
find_package(ZLIB REQUIRED)
target_link_libraries(main PRIVATE ZLIB::ZLIB)
vcpkg does not automatically add any include or links paths into your project. To use a header-only library you can use find_path() which will correctly work on all platforms:
cmake
# To find and use catch2find_path(CATCH_INCLUDE_DIR NAMES catch.hpp PATH_SUFFIXES catch2)
target_include_directories(main PRIVATE ${CATCH_INCLUDE_DIR})
IDE Integration
Visual Studio / Visual Studio Code
We recommend using CMake Presets in both Visual Studio and Visual Studio Code.
Open the Toolchains settings (File > Settings on Windows and Linux, CLion > Preferences on macOS), and go to the CMake settings (Build, Execution, Deployment > CMake). In CMake options, add the following line:
vcpkg does not automatically apply your toolchain's settings, such as your compiler or compilation flags, while building libraries. To change vcpkg's library settings, you must make a custom triplet file (which can share your toolchain)**
Settings Reference
All vcpkg-affecting variables must be defined before the first project() directive such as in a CMakePresets.json's "cacheVariables" map, via the command line, or set() statements.
VCPKG_TARGET_TRIPLET
This setting controls the triplet vcpkg will install and consume libraries from.
If unset, vcpkg will automatically detect an appropriate default triplet given the current compiler settings. If you change this CMake variable, you must delete your cache and reconfigure.
VCPKG_HOST_TRIPLET
This variable controls which triplet host dependencies will be installed for.
If unset, vcpkg will automatically detect an appropriate native triplet (x64-windows, x64-osx, x64-linux).
This variable controls activation of default features in addition to those listed in VCPKG_MANIFEST_FEATURES. If set to ON, default features will not be automatically activated.
Defaults to OFF.
VCPKG_INSTALL_OPTIONS
This variable can be set to a list of additional command line parameters to pass to the vcpkg tool during automatic installation.
VCPKG_PREFER_SYSTEM_LIBS
Предупреждение
This feature has been deprecated. Use empty overlay ports instead.
This variable controls whether vcpkg will append instead of prepend its paths to CMAKE_PREFIX_PATH, CMAKE_LIBRARY_PATH and CMAKE_FIND_ROOT_PATH so that vcpkg libraries/packages are found after toolchain/system libraries/packages.
Defaults to OFF.
VCPKG_FEATURE_FLAGS
This variable can be set to a list of feature flags to pass to the vcpkg tool during automatic installation to opt-in to experimental behavior.
See the --feature-flags= command line option for more information.
VCPKG_TRACE_FIND_PACKAGE
When set to ON, Print every call to find_package. Nested calls (e.g. via find_dependency) are indented according to nesting depth.
Работете съвместно с нас в GitHub
Източникът за това съдържание може да бъде намерен в GitHub, където можете също да създавате и преглеждате проблеми и да изтегляте искания. За повече информация вижте нашето ръководство за сътрудник.
Обратна връзка за vcpkg
vcpkg е проект с отворен код. Изберете връзка, за да предоставите обратна връзка:
Azure HPC je účelově sestavená cloudová funkce pro úlohy HPC a AI, která využívá špičkové procesory a interfiniBand třídy HPC, aby poskytovala nejlepší výkon, škálovatelnost a hodnotu aplikací. Azure HPC umožňuje uživatelům odhalovat inovace, produktivitu a obchodní flexibilitu prostřednictvím vysoce dostupné řady technologií HPC a AI, které se dají dynamicky přidělovat při změně obchodních a technických potřeb. Tento studijní program je řada modulů, které vám pomůžou začít pracovat s prostředím Azure HPC –