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

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”

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$ 

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.

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 .