# run-clang-tidy checks each source file N times on Multi-Config generator projects?

**URL:** https://discourse.cmake.org/t/run-clang-tidy-checks-each-source-file-n-times-on-multi-config-generator-projects/13046
**Category:** Usage
**Tags:** gen:ninja
**Created:** [November 23, 2024, 9:29pm UTC](https://discourse.cmake.org/t/run-clang-tidy-checks-each-source-file-n-times-on-multi-config-generator-projects/13046 "2024-11-23T21:29:13Z")
**Posts on this page:** 5
**Page:** 1

<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: [November 23, 2024, 9:29pm UTC](https://discourse.cmake.org/t/run-clang-tidy-checks-each-source-file-n-times-on-multi-config-generator-projects/13046/1 "2024-11-23T21:29:13Z")

</div>

### How to check the source files only 1 times with run-clang-tidy?

I have an header only library with one example and one test source.  
I create a “Ninja Multi-Config” generator with this types:

**CMAKE\_CONFIGURATION\_TYPES=“Debug;RelWithDebInfo;Coverage;Asan;Lsan;Usan”**

```cmake
bash-5.2$ find . -name compile_commands.json 
./compile_commands.json
bash-5.2$ grep -w file compile_commands.json 
  "file": "/Users/clausklein/Workspace/cpp/beman-project/inplace_vector/build/beman_inplace_vector_verify_interface_header_sets/beman/inplace_vector/inplace_vector.hpp.cxx",
  "file": "/Users/clausklein/Workspace/cpp/beman-project/inplace_vector/build/beman_inplace_vector_verify_interface_header_sets/beman/inplace_vector/inplace_vector.hpp.cxx",
  "file": "/Users/clausklein/Workspace/cpp/beman-project/inplace_vector/build/beman_inplace_vector_verify_interface_header_sets/beman/inplace_vector/inplace_vector.hpp.cxx",
  "file": "/Users/clausklein/Workspace/cpp/beman-project/inplace_vector/build/beman_inplace_vector_verify_interface_header_sets/beman/inplace_vector/inplace_vector.hpp.cxx",
  "file": "/Users/clausklein/Workspace/cpp/beman-project/inplace_vector/build/beman_inplace_vector_verify_interface_header_sets/beman/inplace_vector/inplace_vector.hpp.cxx",
  "file": "/Users/clausklein/Workspace/cpp/beman-project/inplace_vector/build/beman_inplace_vector_verify_interface_header_sets/beman/inplace_vector/inplace_vector.hpp.cxx",
  "file": "/Users/clausklein/Workspace/cpp/beman-project/inplace_vector/tests/beman/inplace_vector/inplace_vector.test.cpp",
  "file": "/Users/clausklein/Workspace/cpp/beman-project/inplace_vector/tests/beman/inplace_vector/inplace_vector.test.cpp",
  "file": "/Users/clausklein/Workspace/cpp/beman-project/inplace_vector/tests/beman/inplace_vector/inplace_vector.test.cpp",
  "file": "/Users/clausklein/Workspace/cpp/beman-project/inplace_vector/tests/beman/inplace_vector/inplace_vector.test.cpp",
  "file": "/Users/clausklein/Workspace/cpp/beman-project/inplace_vector/tests/beman/inplace_vector/inplace_vector.test.cpp",
  "file": "/Users/clausklein/Workspace/cpp/beman-project/inplace_vector/tests/beman/inplace_vector/inplace_vector.test.cpp",
  "file": "/Users/clausklein/Workspace/cpp/beman-project/inplace_vector/examples/fibonacci.cpp",
  "file": "/Users/clausklein/Workspace/cpp/beman-project/inplace_vector/examples/fibonacci.cpp",
  "file": "/Users/clausklein/Workspace/cpp/beman-project/inplace_vector/examples/fibonacci.cpp",
  "file": "/Users/clausklein/Workspace/cpp/beman-project/inplace_vector/examples/fibonacci.cpp",
  "file": "/Users/clausklein/Workspace/cpp/beman-project/inplace_vector/examples/fibonacci.cpp",
  "file": "/Users/clausklein/Workspace/cpp/beman-project/inplace_vector/examples/fibonacci.cpp",
bash-5.2$ cd ..
bash-5.2$ cmake --list-presets
Available configure presets:

  "debug" - Debug Build
  "release" - Release Build
  "gcov" - Coverage Build
  "asan" - AddressSanitizer Build
  "lsan" - LeakSanitizer Build
  "usan" - UndefinedSanitizer Build
bash-5.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: [November 24, 2024, 9:32pm UTC](https://discourse.cmake.org/t/run-clang-tidy-checks-each-source-file-n-times-on-multi-config-generator-projects/13046/2 "2024-11-24T21:32:46Z")

</div>

CMake uses a co-compile approach for its `clang-tidy` support. It isn’t a distinct, separate operation, it is tied to compiling the file. Since you have six different configurations, that’s six different ways to compile the file and six different ways to run `clang-tidy`. You can argue that all the `clang-tidy` invocations on the same source file will be the same, but that might not always be the case if there are any compile flags that change how the source is interpreted.

I don’t know how the `run-clang-tidy` tool from LLVM handles `compile_commands.json` files created by CMake for a multi-config generator. If it doesn’t recognise the separate configurations as related in some way, then yes I’d expect it will just run everything six times in your case. Probably both CMake and LLVM contribute to that problem, but ultimately the `run-clang-tidy` tool is responsible for how it interprets the data it encounters in the `compile_commands.json`.

---

<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: [November 24, 2024, 9:56pm UTC](https://discourse.cmake.org/t/run-clang-tidy-checks-each-source-file-n-times-on-multi-config-generator-projects/13046/3 "2024-11-24T21:56:45Z")

</div>

OK I will add a `lint` `CMAKE_BUILD_TYPE` with co-compile `clang-tidy`.

But I expect to check than the files only while build this `lint` type?

While daily development, I have no time to run alway this clang-tidy, which takes to long time!

### My usual workflow is: `code` a little, `test`, `run-clang-tidy`, `spellcheck`, `clang-format`, and `commit` .

---

<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: [November 27, 2024, 7:49pm UTC](https://discourse.cmake.org/t/run-clang-tidy-checks-each-source-file-n-times-on-multi-config-generator-projects/13046/4 "2024-11-27T19:49:41Z")

</div>

If you were not enabling CMake’s `clang-tidy` support before, enabling it now will not change your situation. I just assumed you had it enabled before, but it shouldn’t really make a difference for the problem you raised.

---

<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: [November 27, 2024, 8:05pm UTC](https://discourse.cmake.org/t/run-clang-tidy-checks-each-source-file-n-times-on-multi-config-generator-projects/13046/5 "2024-11-27T20:05:07Z")

</div>

This is the first time I use the `Ninja Multi-Config` generator.

I need a complex, but generic workflow setting and I was thinking this may be faster for local builds.

see [inplace\_vector/cmake/CMakeDarwinPresets.json at feature/export\_cmake\_config\_package · ClausKlein/inplace\_vector · GitHub](https://github.com/ClausKlein/inplace_vector/blob/feature/export_cmake_config_package/cmake/CMakeDarwinPresets.json)

I will got back to `Ninja` generator.
