Running clang tidy for a qmake project from the command line
-
Context: my project (Qt 5.12, qmake-based) is developed on Windows with Qt Creator and automatically tested on an Ubuntu 20.04 build server. I'd like to use
clang-tidy
to get additional static analysis checks in my CI system (e.g, fail the build ifclang-tidy
reports something.)I've tried to use bear to generate a
compile_commands.json
file when my project is compiled in CI:#!/bin/bash # Compile mkdir build && cd build qmake -spec linux-clang ../main.pro make qmake_all bear make # generates compile_commands.json # Lint run-clang-tidy
This almost works (
clang-tidy
will run with the settings defined in my.clang-tidy
file), but the generatedcompile_commands.json
is written in terms ofmoc_*.cpp
files, which meansclang-tidy
is reporting warnings on the code thatmoc
generated -- not my actual code. For example, I see stuff like this:/home/user/Code/MyProject/build/src/core/moc_mysourcefile.cpp:97:9: warning: function-like macro 'QT_MOC_LITERAL' used; consider a 'constexpr' template function [cppcoreguidelines-macro-usage] #define QT_MOC_LITERAL(idx, ofs, len) \ ^
/home/user/Code/MyProject/build/src/core/moc_mysourcefile.cpp:99:93: warning: macro argument should be enclosed in parentheses [bugprone-macro-parentheses] qptrdiff(offsetof(qt_meta_stringdata_NotificationFullDateTimeDelegate_t, stringdata0) + ofs \ ^ ( )
What I really want is the kind of warnings I get when I do
Analyze > Clang-Tidy
in Qt Creator on Windows. In Qt Creator,clang-tidy
is able to provide static analysis on my actual source code.Is there a way to get good
clang-tidy
checks in my headless Linux CI system?Things I've looked at:
-
If you still have the same problem I published a bash solution which uses compiledb which allows to generate the file compile_commands.json with qmake on macOS: https://github.com/MiroYld/QtBuildTool