# Cache invalidation doesn't affect compile\_commands.json?

**URL:** https://discourse.cmake.org/t/cache-invalidation-doesnt-affect-compile-commands-json/15642
**Category:** Usage
**Tags:** os:linux
**Created:** [May 5, 2026, 7:12pm UTC](https://discourse.cmake.org/t/cache-invalidation-doesnt-affect-compile-commands-json/15642 "2026-05-05T19:12:55Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![tali](https://discourse.cmake.org/user_avatar/discourse.cmake.org/tali/32/6123_2.png) [@tali](https://discourse.cmake.org/u/tali)
#### Post date: [May 5, 2026, 7:12pm UTC](https://discourse.cmake.org/t/cache-invalidation-doesnt-affect-compile-commands-json/15642/1 "2026-05-05T19:12:56Z")

</div>

Hello all - If a build directory is generated with `-DCMAKE_EXPORT_COMPILE_COMMANDS=1`, and then the CMake command is run again identically but with a (different) value for `--DCMAKE_CXX_COMPILER` or `-DCMAKE_C_COMPILER`, the `compiler_commands.json` file, if generated, is _not_ regenerated. Naively, I would expect that this file, since it depends on the modified variables, to be regenerated.

Is my expectation correct? I.e., is this a bug? Thank you!

I’m running version 4.1.2.

---

<div class="post-metadata">

### Author: ![craig.scott](https://discourse.cmake.org/user_avatar/discourse.cmake.org/craig.scott/32/20_2.png) [@craig.scott](https://discourse.cmake.org/u/craig.scott)
#### Post date: [May 5, 2026, 9:45pm UTC](https://discourse.cmake.org/t/cache-invalidation-doesnt-affect-compile-commands-json/15642/2 "2026-05-05T21:45:08Z")

</div>

You can’t normally change the compiler/toolchain for an existing build directory. I’m surprised CMake isn’t issuing a warning of some kind if you try to do that. If you want to change the value of `CMAKE_CXX_COMPILER` or `CMAKE_C_COMPILER`, you should add the `--fresh` option when running `cmake`. That will force CMake to discard its cached toolchain details and recompute them from scratch. I’d expect you would see any relevant changes in `compiler_commands.json` after that too.

---

<div class="post-metadata">

### Author: ![tali](https://discourse.cmake.org/user_avatar/discourse.cmake.org/tali/32/6123_2.png) [@tali](https://discourse.cmake.org/u/tali)
#### Post date: [May 5, 2026, 10:10pm UTC](https://discourse.cmake.org/t/cache-invalidation-doesnt-affect-compile-commands-json/15642/3 "2026-05-05T22:10:10Z")

</div>

Good to know - I had no idea that I shouldn’t expect changing the compiler to work. Thanks!
