A CMake toolchain file describes the set of tools and utilities for compiling code in CMake. This repo provides toolchains that describes how to compile using MSVC and Clang in CMake, with the goal of making Windows CMake builds more canonical to reduce the 'barrier-to-entry' to build code for Windows.
Yes, but you're probably either:
-
using a "Visual Studio Generator". In which case, CMake will emit - and then build - a Visual Studio Solution file that knows how to find the build tools and utilities.
-
running from a Visual Studio "Command Prompt". In which case, the command prompt is hard-coded to use a set of tools and utilities, which means that you always need to initialize your command prompt before getting started.
By using a Toolchain file to describe the tools and utilities to build in CMake-terms, you can use other generators (e.g. Ninja) and don't have to initialize an environment to run a build.
No, no. This uses the tools and utilities from installed Visual Studio but from a CMake build.
No. This is an early attempt at making Visual Studio tooling easier to use from CMake. There's definitely gaps - there's no support for "Windows Universal" builds, for example. But it gets enough of a stake-in-the-ground to start a conversation.
Specify the 'Windows.MSVC.toolchain.cmake' or 'Windows.Clang.toolchain.cmake' file as a toolchain file to your CMake builds. See the documentation for CMake toolchains for more details on Toolchain files and how to consume them.
The 'Windows.MSVC.toolchain.cmake' and 'Windows.Clang.toolchain.cmake' file has details on the various CMake variables that can be used to configure the build. And the example folder provides a CMake project that builds a variety of Windows projects.