Wednesday, February 4, 2026

CMakePresets.json Version 6 Support in Visual Studio and VS Code

hi my name is Andrea isak and I am a
software engineer in the C++
crossplatform team at Microsoft I want
to present today the support that we
implemented in our vs and vs code cake
extensions for presets version six let's
start with a quick reminder about what
are the cake
presets they are Json files which allow
users to Define in a robust way a set of
command line options cache or
environment variables for various
operations like configure build and test
the fields ultimately translate into
command line arguments toward words
tools that form the cake build ecosystem
like cmake itself C test or CAC Concepts
like build type build directory
generator and many others are
recommended to be written in files like
cake presets and Cake user presets Json
instead of other Legacy mechanisms like
kits and
variants kitware is constantly defining
more formats and schemas to improve the
developer experience and we try our best
to match this support in VSS and vs code
let's look quickly over how presets V6
looks like in the official kitware
documentation two new types of presets
are introduced package presets which
produce an installation artifact via the
CAC tool and workflow presets which are
able to execute a series of different
configure build test and package presets
in a given order and following some
rules the package preset schema has many
fields that are common with the other
preset types like name inherit hidden uh
condition vendor vendor name display
name description environment variables
configure preset inherit configure
environment all of these function the
exact same way there are also fields
that are new and which introduce new
Concepts specific to CPAC like package
name package version package directory
or concepts that exist for other preset
kinds but are applied in a different way
for CPAC like generators configurations
config file or
output but the basic approach of
interpreting these fields is the same as
for the previous versions depending on
the values written in the cake presets
Json file the extension calculates the
final CPAC command line that will be run
when the package operation is
invoked and here is the workflow preset
besides few General and obvious Fields
the steps array is meant to to define a
sequence of configure build test and
package presets as part of a developer
workflow here are the rules of a
workflow it must be associated with one
configure preset which should be defined
only as step one in the array and all
the following presets must be Associated
themselves with the same configure
preset now let's see some of the most
common user scenarios for version six of
the cake presets in the cake tools VI
code extension I chose this open-source
project hdf5 which represents a high
performance library and file format
specification that implements the hdf5
data
model it had defined a complex set of
presets and we can see right away how
this new support applies to a code base
that is already already using heavily
all kinds of
presets the project defines many
configure build test package and
workflow presets I also added
temporarily some debac preset variations
to be able to Showcase particular
scenarios in My Demo I will be focusing
on the msvc tool set with debug and
release flavors and since I am on a
Windows system I will Define a zip
package generator for
CAC here are also some other fields that
are supported by the the package preset
schema they are not necessarily needed
by this project but I thought they can
be useful for us to see their impact on
the final CPAC command line that we are
going to generate so here are different
logging verbosity levels various
environment or cach
variables and the override settings icon
notifies us that we defined additional
arguments to the CPAC tool via the
settings
this project is already configured for
msvc amd64 debug and it is entirely
built to save some time we are ready to
invoke now the package command for the
debug
configuration this is also triggering a
build same as running a test preset does
it should be quick though since it is an
incremental build
and packaging is done here is where the
zip was created let's explore and see
how it looks
like and this is the structure of the
installation
package it's useful to inspect also the
CPAC command line that we generated all
these parameters are coming from the
package preset field fields that we
wrote in the presets file and these
additional arguments are coming from
settings now it would be nice to be able
with one command to run multiple
processes of configure build test and
package in any combination and Order of
course while following the rules like
one configure per workflow configure
must be first and all steps must have
the same configure preset Associated as
the configure preset of the first
workflow step the workflow presets are
pretty straightforward to read for
example the release workflow notice how
all the steps are associated with the
release configuration while my project
is currently configured for debug it is
possible I run this workflow with one
command and not lose the Deb back state
of my project let's
run the release
workflow on top of a debug configured
project under the covers we temporarily
set all the presets to the release
counterparts specified by the workflow
and at the end we restore everything to
what it was this is useful for
developers when they need to produce
retail binaries while developing in a
debu state and also to orchestrate CI
builds for cake
projects for this Repository
which is quite large uh this workflow
can last a long
time the workflow finished so now let's
inspect the logging in the output
channel to see the steps that will
run this is the configure that sets up
the whole workflow and here we are
building the
binaries then the workflow runs the test
suite and at the end
it runs CPAC to produce the final
package after producing the package
since we ran um red workflow on top of a
debug project um we restore the presets
and the configuration State back to
debug now let's explore how the presets
V6 support looks like for a brand new
project the UI entry points are exactly
the same as for the other configure
build and test presets adding a new
preset selecting one from all that
should be visible inheritance the
visibility settings in status bar or
sidebar all these work the same as for
the previous versions and the other
kinds of
presets we can add now some new package
and workflow presets by by using various
UI entry points and predefined templates
I'm going to use the command pette and
invoke the action of add package preset
let's use the custom template to define
a base package preset for all others to
inherit from
being a base preset it needs to be
hidden I needed this base preset in
order to define a common information for
all the future package presets we are
going to write soon like CAC generators
I want it to be zip because I'm working
on a Windows machine if I use another
entry point like from the left sqi panel
I can add another package
preset by inheriting from the base I
wrote
earlier let's use another entry point
and inherit again creating a new package
preset for release
these both will automatically inherit
the zip
generator something that is missing and
the schema requires it is a configure
preset
because this is the debu package
it makes sense to associate it with a
debug configure
preset and the
release package
preset to be associated with a release
configure
preset let's do the same for um workflow
presets by creating
from a configure
debug so this will be a debug
workflow and The Wizard already wrote
the first step for
us we only need to write the extra steps
I am thinking to add the build and the
package step
let's write also a release
workflow let's create from an existing
workflow preset like
debug this is a mechanism similar to
inheritance this way we end up doing
only uh a few minor
edits now let's select a package
preset and the workflow preset from the
ones that we wrote
release package we do not see the debug
package because the current
configuration of the project is released
and the hidden base preset is um
Invisible by default and the workflow
the workflows we can see both because um
the extension allows running a workflow
that is associated with a different
configure than the main state of the
project so so I can decide either of
them the V6 preset support exists in vs
as well and it looks very similar with
just some variations in the UI specific
to the visual studio overall design
let's open in vs the same basic project
that we created in vs code
earlier it should configure build and
package with the exact same presets that
we wrote out of the
box and done so now let's quickly run a
package on the
workflow let's package the debug
binaries since we are configured for
debug here is the
zip and let's see how workflows are
executed the debug workflow which
configures for
debug builds the debug binaries and then
packages them into the
zip we can also run our package and
workflow presets from another UI entry
point like in solution Explorer context
menu on cake presets Json file here are
the
menus also in the same place we we can
add new presets let's see how the
predefined templates and wizards look
like let's add a new package
preset we can add any other fields that
we are interested in or modify the text
that was
written and same for adding a new
workflow
preset well this shows that the presets
V6 support in both vs and vs code is
bringing more consistency and
compatibility for code
bases this is the end of the demo let us
know in the comments if you have any
suggestions about how we can improve
this experience or if you encounter any
problems while using this support thank
you for watching and we hope you enjoy
Also other videos prepared by our
engineers for the pure virtual
conference

No comments:

Post a Comment