Skip to content
Snippets Groups Projects

Add new CMake target to run clang-tidy

Merged Florian Uhlig requested to merge f.uhlig/cbmroot:add_clang_tidy_to_CI into master
6 files
+ 263
4
Compare changes
  • Side-by-side
  • Inline
Files
6
@@ -26,7 +26,7 @@ macro(define_additional_targets)
# Create a list C, C++ and header files which have been changed in the
# current commit
execute_process(COMMAND ${CMAKE_SOURCE_DIR}/cmake/scripts/find_files.sh
execute_process(COMMAND ${CMAKE_SOURCE_DIR}/cmake/scripts/find_files.sh ${BASE_COMMIT}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE FileList
OUTPUT_STRIP_TRAILING_WHITESPACE
@@ -58,6 +58,50 @@ macro(define_additional_targets)
endif()
find_package2(PRIVATE ClangTidy)
if(ClangTidy_FOUND AND EXISTS ${CMAKE_SOURCE_DIR}/.git)
if (FAIRROOT_TIDY_BASE)
set(BASE_COMMIT ${FAIRROOT_TIDY_BASE})
else()
set(BASE_COMMIT upstream/master)
endif()
# Create a list C, C++ and header files which have been changed in the
# current commit
execute_process(COMMAND ${CMAKE_SOURCE_DIR}/cmake/scripts/find_files.sh ${BASE_COMMIT}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE FileList
OUTPUT_STRIP_TRAILING_WHITESPACE
)
string(REGEX REPLACE " " ";" FileList "${FileList}")
# Loop over the files and create the code whch is executed when running
# "make FormatCheck".
# The produced code will run clang-format on one of the files. If
# clang-format finds code which are not satisfying our code rules a
# detailed error message is created. This error message can be checked on
# our CDash web page.
foreach(file ${FileList})
set(file1 ${CMAKE_BINARY_DIR}/${file}.ct_out)
list(APPEND myfilelist1 ${file1})
add_custom_command(OUTPUT ${file1}
COMMAND ${CMAKE_SOURCE_DIR}/cmake/scripts/check-tidy.sh ${file} ${file1} ${CMAKE_BINARY_DIR}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
endforeach()
# Create the target FormatCheck which only depends on the files creted in
# previous step. When running "make FormatCheck" clang-format is executed
# for all C, C++ and header files which have changed in the commit.
add_custom_target(TidyCheck
DEPENDS ${myfilelist1}
)
endif()
# TODO: check if still needed
# if(RULE_CHECKER_FOUND)
# ADD_CUSTOM_TARGET(RULES
Loading