7

I'm trying to use make use of clang-tidy integration with cmake and I'd like to pass the -check argument. I've tried adding -DCMAKE_CXX_CLANG_TIDY="/usr/local/opt/llvm38/bin/clang-tidy-3.8;-checks=*" when invoking cmake, but my makefile commands end-up looking like:

/usr/local/Cellar/cmake/3.6.2/bin/cmake -E __run_iwyu --tidy="/usr/local/opt/llvm38/bin/clang-tidy-3.8;-checks=*" --source=/Users/ellery/work/.....

in other words, it seems like the ; separated args are not being parsed apart. I've also tried setting the target property CXX_CLANG_TIDY directly on my target with the same value and I get the same behavior.

Has anyone succesfully invoked clang-tidy with additional args through cmake?

valiano
  • 16,433
  • 7
  • 64
  • 79
Mike Ellery
  • 2,054
  • 3
  • 21
  • 30

2 Answers2

7

It works as expected with cmake 3.7.2 and clang-tidy 4.0.

E.g. directly specifying on the command line:

cmake -DCMAKE_CXX_CLANG_TIDY="clang-tidy;-style=file;-checks=*"

or in the CMakeLists.txt:

set(CMAKE_CXX_CLANG_TIDY "clang-tidy;-style=file;-checks=*")

You have to make sure that the clang-tidy arguments are correct, otherwise it seems to fail silently.

misev
  • 349
  • 3
  • 11
  • 1
    clang-tidy Unknown command line argument '-style=file', but ok when cut off '-style=file'. – kgbook Sep 29 '18 at 11:38
1

Everything is correct. CMake does not parse those arguments when generating the makefile, but when the makefile is executed. When a file was successful compiled, then clang-tidy will be executed automatically.

You could try setting CMAKE_CXX_CLANG_TIDY directly in your CMakeLists.txt:
set(CMAKE_CXX_CLANG_TIDY "clang-tidy" "-checks=*")

Kevsoft
  • 11
  • 2
  • 2
  • hmmm - that's interesting. When I set this in my cmake file, I fail almost immediately with: `Error running '/usr/local/opt/llvm38/bin/clang-tidy-3.8`. There are no more details about the failure, however. If I leave off the "-checks=*" argument, the build seems to succeed, but I get the (presumably) default behavior of clang-tidy. – Mike Ellery Nov 07 '16 at 21:32