clang-tidy: adjust used compile commands / pass flags possible?
-
Hello,
I have a quite complex and large project, that uses an own build system on top of cmake and uses e.g. Intel compiler.
Currently I can load the CMakeLists.txt and work on the project in QtCreator (15.0.0) just fine.
Now I wanted to use clang-tidy on one file, unfortunately this is currently not possible for me in QtCreator. I managed to get it working from the command-line, so let me first explain what I had to do to get it running:I enabled
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
to generate a
compile_commands.json
file in my build directorybuild/ninja/Debug
When first trying to run:clang-tidy source/my_file.cpp -p build/ninja/Debug
where I specified the build path (to the location where also
compile_commands.json
is) with the-p
switch.
With this I got an error like:error: 'Kokkos_Core.hpp' file not found [clang-diagnostic-error] 13 | #include "Kokkos_Core.hpp"
For any reason I could build the library just finie and it picked up this header and the corresponding library, but clang-tidy did not find it. So I manually added the path to the library with the
-I
switch:clang-tidy source/my_file.cpp -p build/ninja/Debug -- -I $TRILINOS_DIR/include/
With this I got the next error:
error: unknown argument: '-no-diag-error-limit' [clang-diagnostic-error]
This is an Intel flag, specified in the
compile_commands.json
file.
I removed this flag manually in mycompile_commands.json
and finally clang-tidy works fine from the command line.
However - it would be great to see the problems in QtCreator with the visual feedback. Unfortunately if I run clang-tidy on the same file, I get the same error as before on the command line:error: unknown argument: '-no-diag-error-limit' [clang-diagnostic-error]
Is there a way to adjust this in a similar way, as before manually or how does QtCreator invode clang-tidy (and is there a way to adjust this behavior)?
Maybe anybody can help me here.
Thanks and many greetings
matse -
A little update on this:
I just saw the QtCreator output:Creating compilation database for Clang-Tidy in "/tmp/QtCreator-GXwzFX/Clang-Tidy.XgcZGh" ...
So in
/tmp/QtCreator-GXwzFX/Clang-Tidy.XgcZGh/compilation_commands.json
I removed-no-diag-error-limit
for my source file and this helped with the first error. Now I get the other error (that I first got on the command line):error: 'Kokkos_Core.hpp' file not found [clang-diagnostic-error] 13 | #include "Kokkos_Core.hpp"
So I'm looking for a way to adjust the include path or pass parameters to clang-tidy. Of course it would be also nice if QtCreator would use a compilation_database, that is persistent or if I could find a better way to cope with the situation.
-
Try setting the environment variable
QTC_CLANG_CMD_OPTIONS_BLACKLIST=-no-diag-error-limit
before starting Qt Creator. -
@cristian-adam Thanks for the quick help! This is really great and works like a charm. I can simply pass all the arguments via the environment variable - how nice!
I will mark this as solved. Thanks again for the help and many greetings
matse -