# cmake buildPresets runs without environment

**URL:** https://discourse.cmake.org/t/cmake-buildpresets-runs-without-environment/12831
**Category:** Usage
**Created:** [October 24, 2024, 9:34am UTC](https://discourse.cmake.org/t/cmake-buildpresets-runs-without-environment/12831 "2024-10-24T09:34:48Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![cmak](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/c/eb8c5e/32.png) [@cmak](https://discourse.cmake.org/u/cmak)
#### Post date: [October 24, 2024, 9:34am UTC](https://discourse.cmake.org/t/cmake-buildpresets-runs-without-environment/12831/1 "2024-10-24T09:34:48Z")

</div>

I have an issue where I see my cmake `buildPresets` runs without the environment defined in the `configurePresets`. I tried defining the environment in the `buildPresets` as well but seems cmake still does not run with correct environment. Small example to see issue

```cmake
{
  "configurePresets": [
    {
      "name": "default",
      "hidden": true,
      "environment": {
        "CCACHE_DIR": "${sourceDir}/build/.ccache",
      }
    },
 ],
  "buildPresets": [
    {
      "name": "test",
      "configurePreset": "default"
    }
]
 }   

```

If I then invoke `ccache -p` during the configure step (`cmake --preset`) then it is correctly set. But if I invoke `ccache -p` during the build (`cmake --build`) then the environment is not correct passed when `ccache` is invoked.

---

<div class="post-metadata">

### Author: ![ClausKlein](https://discourse.cmake.org/user_avatar/discourse.cmake.org/clausklein/32/352_2.png) [@ClausKlein](https://discourse.cmake.org/u/ClausKlein)
#### Post date: [October 24, 2024, 2:24pm UTC](https://discourse.cmake.org/t/cmake-buildpresets-runs-without-environment/12831/2 "2024-10-24T14:24:02Z")

</div>

Dit you use: cmake —build —preset test?
