CMake Presets Best Practices -- Toolchains vs Cache Variables

Hey,

I’ve googled and search this site, but can’t find much on this.
What is the preferred method for setting compilers and other settings?

We don’t do any cross compilation, but have been using toolchains to make certain tasks simpler and less error prone. I just learned about presets, so we’re immediately adding support for presets.

But, within the preset, I can either specify a path to the toolchain file that sets the properties. Or, I can manually specify the cache variables and values.

Is there a preferred approach or best practice? Right now, our toolchain files are incredibly simple.
They only consist of setting one internal variable and set the CXX compiler type. So, complexity is not an issue in the present moment.

“Whatever works for you”. :slight_smile: I usually just set CC and CXX (Linux), set up DEVELOPER_DIR (Xcode), or load the required env (vcvarsall / MSVC). Cross-compiles usually are more complicated and a toolchain file is better.

Cool.

There’s only two “issues” I’ve encountered with presets.
The different configuration add up quickly. Unless I’m doing something wrong.

There’s a clang and gcc config preset that are the bases.
Then, a clang-debug, gcc-debug, clang-release, gcc-release, clang-docker-debug, etc…
I am using inheritance, but I also don’t see a good way to get rid of all of these presets. And to be fair, it’s still much more orderly than handling these without presets.

The other issue is with build configs. I got around the issue I’m about to describe by using a custom target and adding DEPENDS on executables we want grouped. But, I’d like to be able to use a build preset without having to specify a configuration. Let’s say there’s a build config release_apps. It would be great to be able to simple use whatever build directory has been made and just be able to specify the name of the build config and the targets it uses.

See issue 22538 for discussion of the problem with combinatorial explosion of build presets.

1 Like