0

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
  • Not sure what do you ask for, since your question post already contains the code which creates a target for run clang-tidy. Or do you wonder why your analysis fails? – Tsyvarev Jan 13 '23 at 10:22
  • I wonder why your command in `add_custom_target` executes a separate cmake script instead of executing clang-tidy directly. Is there a reason? – Wutz Jan 13 '23 at 10:27
  • @Tsyvarev Yep, why analysis fails? Somebody run clang-tidy with Cmake in Visual studio, I really need help why it's doesn't work. On Linux all works – Nikita Tabakaev Jan 13 '23 at 18:24
  • @Wutz because I need run clang-tidy as separate target – Nikita Tabakaev Jan 13 '23 at 18:26

0 Answers0