6

How can one pass a clang flag, e.g. -fms-compatibility-version with the <LANG>_CLANG_TIDY CMake property? On the CLI this is easy:

clang-tidy main.cpp -- -fms-compatibility-version=19.10

But with CMake this does not work as expected:

-DCMAKE_CXX_CLANG_TIDY="clang-tidy;-checks=-*,readability-*;--;-fms-compatibility-version=19.10"

The flag is required to make clang work with modern versions of MSVC.

If this is not possible; Is there any other way to integrate CMake+MSVC+clang-tidy (besides creating a custom build target)?

Florian Wolters
  • 3,820
  • 5
  • 35
  • 55

4 Answers4

0

On Visual studio 2017 15.6.3 (make sure to update) here.

I had to put

set(CMAKE_CXX_CLANG_TIDY "clang-tidy;-format-style='file'")

# CMake is buggy. It gives the -std:c++14 instead of /std:c++14
# set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++14")

In my CMakeLists.txt. I Don't know if that is the right way to do it, but I can compile AND detect errors. Seems like a win to me.

hmaarrfk
  • 417
  • 5
  • 10
0

You can use --extra-arg and --extra-arg-before (docs).

--extra-arg=: Additional argument to append to the compiler command line. Can be used several times.

--extra-arg-before=: Additional argument to prepend to the compiler command line. Can be used several times.

This is supported in earlier versions of CMake, but I'm using it to get C++17 support with CMake 3.16 on Windows as well as linux.

if (MSVC)
  if(CLANG_TIDY_EXE)
    set(CMAKE_CXX_CLANG_TIDY "clang-tidy;--extra-arg-before=-std=c++17;${CLANG_TIDY_ARGS}")
  endif()
endif()

For me this was by far the hardest part of integrating CMake+MSVC+clang-tidy (here's the details I followed).

TooTone
  • 7,129
  • 5
  • 34
  • 60
0

CMAKE_CXX_CLANG_TIDY in MSVC In this topic, VS_GLOBAL_ClangTidyChecks properties maybe effective.

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Dec 19 '22 at 01:49
-1

In the docs you linked to actually said it. Currently (ver 3.13.3) it only works with Makefiles and Ninja. It doesn't work with msbuild.

user3667089
  • 2,996
  • 5
  • 30
  • 56