Using clang-tidy with C++14 and C++17 produces an unknown argument error
If CMAKE_CXX_CLANG_TIDY
is set when using C++14/17, I get an error when I try to compile that reads
error: unknown argument: '-std:c++17' [clang-diagnostic-error]
My clang-tidy setup: set(CMAKE_CXX_CLANG_TIDY clang-tidy -checks=-*,readability-*)
The issue is present when using the following:
target_compile_features(my_target PUBLIC cxx_std_14)
target_compile_features(my_target PRIVATE cxx_std_14)
target_compile_features(my_target PUBLIC cxx_std_17)
target_compile_features(my_target PRIVATE cxx_std_17)
The issue is not present when using the following:
target_compile_features(my_target PUBLIC cxx_std_11)
target_compile_features(my_target PRIVATE cxx_std_11)
target_compile_features(my_target INTERFACE cxx_std_11)
target_compile_features(my_target INTERFACE cxx_std_14)
target_compile_features(my_target INTERFACE cxx_std_17)
Full Ninja output using MSVC to compile, running from a Visual Studio command prompt. Similar output is seen using clang-cl:
[1/2] Building CXX object CMakeFiles\test.dir\main.cpp.obj
FAILED: CMakeFiles/test.dir/main.cpp.obj
C:\Users\username\scoop\apps\cmake\3.13.2\bin\cmake.exe -E __run_co_compile --tidy=clang-tidy;-checks=-,readability- --source=..\main.cpp -- C:\PROGRA
2\MICROS1\2017\COMMUN1\VC\Tools\MSVC\14161.270\bin\Hostx64\x64\cl.exe /nologo /TP /DWIN32 /D_WINDOWS /W3 /GR /EHsc /MDd /Zi /Ob0 /Od /RTC1 -std:c++17 /showIncludes /FoCMakeFiles\test.dir\main.cpp.obj /FdCMakeFiles\test.dir\ /FS -c ..\main.cpperror: unknown argument: '-std:c++17' [clang-diagnostic-error]
392 warnings and 1 error generated.
Error while processing C:\Users\username\Code\testing\test\build..\main.cpp.
Suppressed 392 warnings (392 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
Found compiler error(s).
ninja: build stopped: subcommand failed.
Software:
- OS: Windows 10
- CMake: 3.12+
- LLVM: 7.0.1
- Ninja: 1.8.2
- Compiler: MSVC or clang-cl
- Visual Studio Community 2017