Created
July 17, 2025 12:57
-
-
Save Bktero/0abecf3470ed25e4865847069ee04535 to your computer and use it in GitHub Desktop.
CMake and Git to run clang-tidy easily
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Get the C++ files tracked by Git | |
find_program(GIT "git" REQUIRED) | |
execute_process( | |
COMMAND ${GIT} ls-file "*.cpp" "*.hpp" ":!*magic_enum*" | |
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} | |
OUTPUT_VARIABLE GIT_TRACKED_CPP_FILES | |
OUTPUT_STRIP_TRAILING_WHITESPACE | |
COMMAND_ERROR_IS_FATAL ANY | |
) | |
# Convert the output to a list (split by newlines) | |
string(REPLACE "\n" ";" GIT_TRACKED_CPP_FILES ${GIT_TRACKED_CPP_FILES}) | |
# Add a target to run clang-tidy on this list | |
find_program(CLANG_TIDY "clang-tidy" REQUIRED) | |
add_custom_target(clang-tidy | |
COMMAND ${CLANG_TIDY} -p ${CMAKE_CURRENT_BINARY_DIR} ${GIT_TRACKED_CPP_FILES} | |
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} | |
COMMENT "Running clang-tidy..." | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment