7

I have linked clang for my cpp project with CMakeLists.txt with

set(CMAKE_CXX_CLANG_TIDY "clang-tidy;-checks=google-*,cppcoreguidelines-*")

Since, I would like to move all the clang config to a file, I googled little bit and found that there is .clang-tidy file for this usage.

However, I wasn't able to configure CMakeList.txt to actually use this file.

Can anyone tell me how I should change that line in CMakeList.txt to link it with .clang-tidy file?

Brandon Lee
  • 391
  • 1
  • 3
  • 6
  • Not sure how to include .clang-tidy file. But you can put `set(CMAKE_CXX_CLANG_TIDY "clang-tidy;-checks=google-*,cppcoreguidelines-*")` in a separate cmake file(for example clang-tidy.cmake) and include it in main `CMakeLists.txt`. – MaxPlankton Apr 02 '20 at 19:08
  • @JohnKoch Do you know if there is any way of adding filter externally? or in a more organized way than putting them all into a single line? – Brandon Lee Apr 02 '20 at 19:15
  • cmake does support multi line string since version 3.0. https://stackoverflow.com/a/27983206/5360439 – MaxPlankton Apr 02 '20 at 19:20
  • @JohnKoch seems like you know clang-tidy well, would you be able to take a look at this one as well? https://stackoverflow.com/q/61001314/13200816 – Brandon Lee Apr 02 '20 at 21:37

1 Answers1

5

If you have .clang-tidy in project root, all you need to do is specify clang-tidy executable, e.g.

set(CMAKE_CXX_CLANG_TIDY "clang-tidy")

and clang-tidy will implicitly use .clang-tidy.

Ave Milia
  • 599
  • 4
  • 12