cmlib/CMLibCodeAnalysisClangTidy.cmake

26 lines
908 B
CMake
Raw Normal View History

2020-04-22 16:14:51 +00:00
find_program(CLANG_TIDY_EXE NAMES clang-tidy-10 clang-tidy-9 clang-tidy)
if(CLANG_TIDY_EXE)
option(CMLIB_CLANG_TIDY_FIX "Perform fixes for Clang-Tidy" OFF)
endif()
function(add_clang_tidy_check target)
set(_sources ${ARGN})
set(_args -extra-arg="-Wno-unknown-warning-option")
if(CLANG_TIDY_EXE)
if(CMLIB_CLANG_TIDY_FIX)
list(APPEND _args "--fix")
endif()
if(NOT TARGET clang-tidy-check)
add_custom_target(clang-tidy-check)
endif()
2020-04-18 16:40:13 +00:00
add_custom_target(clang-tidy-check-${target} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMAND ${CLANG_TIDY_EXE} ${_args} -p ${CMAKE_BINARY_DIR} ${_sources})
add_dependencies(clang-tidy-check-${target} ${target})
add_dependencies(clang-tidy-check clang-tidy-check-${target})
else()
message(STATUS "CMLIB warning:")
message(STATUS " ClangTidy analyzer is not found")
endif()
endfunction()