How to execute clang-tidy with CMake in Visual studio just as single target? 1.OS: Windows 2.IDE: Visual Studio 2022 3.LLVM: Installed 4.Clang-Tidy: 15.0.6 5.Ninja: Installed (and added to path)
CMakeLists.txt
add_custom_target(tidy
COMMAND ${CMAKE_COMMAND} -DCLANG_TIDY_EXECUTABLE=${CLANG_TIDY_EXECUTABLE} -DPROJECT_BINARY_DIR=${PROJECT_BINARY_DIR} -P ./cmake/Tidy.cmake
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} VERBATIM)
cmake/Tidy.cmake
find_program(CLANG_TIDY_EXECUTABLE "clang-tidy")
execute_process(COMMAND run-clang-tidy -clang-tidy-binary ${CLANG_TIDY_EXECUTABLE} -p ${PROJECT_BINARY_DIR} RESULTS_VARIABLE EXIT_CODE)
if(NOT EXIT_CODE STREQUAL 0)
message(FATAL_ERROR "Analysis failed")
endif()
Output:
Analysis failed