# CMake preset and VsDevCmd.bat / yocto environment

**URL:** https://discourse.cmake.org/t/cmake-preset-and-vsdevcmd-bat-yocto-environment/3519
**Category:** Usage
**Created:** [June 7, 2021, 12:59pm UTC](https://discourse.cmake.org/t/cmake-preset-and-vsdevcmd-bat-yocto-environment/3519 "2021-06-07T12:59:16Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![KUGA2](https://discourse.cmake.org/user_avatar/discourse.cmake.org/kuga2/32/4968_2.png) [@KUGA2](https://discourse.cmake.org/u/KUGA2)
#### Post date: [June 7, 2021, 12:59pm UTC](https://discourse.cmake.org/t/cmake-preset-and-vsdevcmd-bat-yocto-environment/3519/1 "2021-06-07T12:59:16Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [June 7, 2021, 1:00pm UTC](https://discourse.cmake.org/t/cmake-preset-and-vsdevcmd-bat-yocto-environment/3519/2 "2021-06-07T13:00:38Z")

</div>

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

---

<div class="post-metadata">

### Author: ![kyle.edwards](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/k/65b543/32.png) [@kyle.edwards](https://discourse.cmake.org/u/kyle.edwards)
#### Post date: [June 7, 2021, 1:38pm UTC](https://discourse.cmake.org/t/cmake-preset-and-vsdevcmd-bat-yocto-environment/3519/3 "2021-06-07T13:38:37Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![KUGA2](https://discourse.cmake.org/user_avatar/discourse.cmake.org/kuga2/32/4968_2.png) [@KUGA2](https://discourse.cmake.org/u/KUGA2)
#### Post date: [June 7, 2021, 2:14pm UTC](https://discourse.cmake.org/t/cmake-preset-and-vsdevcmd-bat-yocto-environment/3519/4 "2021-06-07T14:14:27Z")

</div>

Ok 😭, 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.

---

<div class="post-metadata">

### Author: ![KUGA2](https://discourse.cmake.org/user_avatar/discourse.cmake.org/kuga2/32/4968_2.png) [@KUGA2](https://discourse.cmake.org/u/KUGA2)
#### Post date: [June 30, 2021, 9:47am UTC](https://discourse.cmake.org/t/cmake-preset-and-vsdevcmd-bat-yocto-environment/3519/5 "2021-06-30T09:47:03Z")

</div>

> 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](https://cmake.org/cmake/help/latest/manual/cmake-presets.7.html#condition), 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.:

```auto
            "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]+"
                    }
                ]
            }

```
