cmlib/CMLibCodeAnalysisClangTidy.cmake

32 lines
986 B
CMake
Raw Normal View History

function(add_clang_tidy_check)
list(GET ARGN 0 _target)
set(_sources ${ARGN})
list(REMOVE_AT _sources 0)
option(CLANG_TIDY_FIX "Perform fixes for Clang-Tidy" OFF)
find_program(CLANG_TIDY_EXE
2019-10-02 07:48:16 +00:00
NAMES clang-tidy-10
clang-tidy-9
clang-tidy-8
clang-tidy-7
clang-tidy-6.0
clang-tidy)
if(CLANG_TIDY_EXE)
if(CLANG_TIDY_FIX)
list(APPEND _args "-fix")
endif()
if(NOT TARGET clang-tidy-check)
add_custom_target(clang-tidy-check)
endif()
add_custom_target(clang-tidy-check-${_target}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMAND ${CLANG_TIDY_EXE} -extra-arg="-Wno-unknown-warning-option" -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()