[CMake] Can CXX_CLANG_TIDY use .clang-tidy file?
Mateusz Loskot
mateusz at loskot.net
Wed Dec 12 06:19:49 EST 2018
On Mon, 10 Dec 2018 at 18:31, Bill Hoffman via CMake <cmake at cmake.org> wrote:
> On 12/8/2018 7:47 PM, Mateusz Loskot wrote:
> >
> > Am I correct clang-tidy run via CXX_CLANG_TIDY
> > ignores .clang-tidy configuration file?
> >
> > I've tried number of ways to help it find the file,
> > i.e. copied the file to binary directories from where it seems run via
> > usr/local/bin/cmake -E __run_co_compile --tidy=/usr/bin/clang-tidy-7
>
> I don't think anything was done to turn that off on purpose. Can you
> run the command from the command line and get it to work? If so, you
> should be able to get the same arguments to the clang tidy that CMake is
> running.
Bill,
Thank you for the hint. It helped to discover it turns out to be a silly issue.
My .clang-tidy listed checks that would issue no warnings for the
target source files :)
Since, apparently, clang-tidy via
/usr/local/bin/cmake -E __run_co_compile --tidy=/usr/bin/clang-tidy-7
runs in quiet mode, while when run directly /usr/bin/clang-tidy-7,
it outputs a brief summary even if no analysis warnings are issued.
That left me with impression, .clang-tidy is not used.
To summary, for records and others looking for similar answers, here
is what works for me:
1. .clang-tidy is in source root directory
2. Top-level CMakeLists.txt
```
find_program(CLANG_TIDY
NAMES clang-tidy-7 clang-tidy-6.0 clang-tidy-5.0 clang-tidy-4.0 clang-tidy
```
and
```
set_target_properties(test_headers_all_in_one
PROPERTIES
CXX_CLANG_TIDY ${CLANG_TIDY})
```
Notice, since checks are specified in .clang-tidy configuration file,
no arguments need to be specified to clang-tidy.
3. Build analysed target
```
$ cd project
$ cmake -S . -B _build -DBoost_ARCHITECTURE=-x64 ..
$ VERBOSE=1 cmake --build _build --target test_headers_all_in_one
# alternative to the last command may be
$ cd _build
$ VERBOSE=1 make test_headers_all_in_one
```
Both, will run clang-tidy with checks read from .clang-tidy config,
and output of any warnings.
Best regards,
--
Mateusz Loskot, http://mateusz.loskot.net
More information about the CMake
mailing list