CMake preset and VsDevCmd.bat / yocto environment

There is the environment element in CMakePresets.json to specify environment variables.

However, the usual way to get the build tools into PATH and other variables is to run a script before executing cmake.

Can this be done via presets? Or do I still need to to this manually before?

I don’t think presets changed that behavior. @kyle.edwards?

No, there are currently no plans to make CMakePresets.json read from or interact with vcvarsall.bat. At most, in the future we may add functionality to verify that vcvarsall.bat has been run correctly, but not actually run it from CMake.

Ok :sob:, but I understand why this is not in the core interest of CMake.
We really could have used this feature, since we have multiple targets with different build environments.

At most, in the future we may add functionality to verify that vcvarsall.bat has been run correctly

This is perfectly clear from the documentation, but I just noticed this a few days ago. This feature can be done today (CMake 3.21) by checking VS env vars in conditions. e.g.:

            "condition": {
                "type": "allOf",
                "conditions": [
                    {
                        "type": "equals",
                        "lhs": "$env{VSCMD_ARG_TGT_ARCH}",
                        "rhs": "x64"
                    },
                    {
                        "type": "matches",
                        "string": "$env{VSCMD_VER}",
                        "regex": "16\\.[0-9]+\\.[0-9]+"
                    }
                ]
            }