Начало
This commit is contained in:
52
MyxxCMake/lib/CodeAnalyzeClangTidy.cmake
Normal file
52
MyxxCMake/lib/CodeAnalyzeClangTidy.cmake
Normal file
@ -0,0 +1,52 @@
|
||||
include_guard(GLOBAL)
|
||||
|
||||
if(NOT CLANG_TIDY_NAME)
|
||||
set(CLANG_TIDY_NAMES clang-tidy)
|
||||
foreach(V RANGE 9 18)
|
||||
list(INSERT CLANG_TIDY_NAMES 0 "clang-tidy-${V}")
|
||||
endforeach()
|
||||
unset(V)
|
||||
else()
|
||||
set(CLANG_TIDY_NAMES ${CLANG_TIDY_NAME})
|
||||
endif()
|
||||
|
||||
find_program(CLANG_TIDY_EXE NAMES ${CLANG_TIDY_NAMES})
|
||||
unset(CLANG_TIDY_NAMES)
|
||||
|
||||
function(myxx_analyze_clang_tidy target)
|
||||
if(NOT CLANG_TIDY_EXE)
|
||||
message(STATUS "MyxxCMake: Clang Tidy analyzer is not found")
|
||||
return()
|
||||
endif()
|
||||
|
||||
if(TARGET ${target}-analyze-clang-tidy)
|
||||
message(STATUS "MyxxCMake: target ${target}-analyze-clang-tidy already exists")
|
||||
return()
|
||||
endif()
|
||||
|
||||
set(options FIX)
|
||||
set(oneValueArgs)
|
||||
set(multiValueArgs EXTRA_ARGS)
|
||||
cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
|
||||
|
||||
set(args -extra-arg="-Wno-unknown-warning-option ${ARG_EXTRA_ARGS}")
|
||||
get_target_property(sources ${target} SOURCES)
|
||||
foreach(iter ${sources})
|
||||
string(FIND ${iter} ${CMAKE_BINARY_DIR} pos)
|
||||
if(pos EQUAL -1)
|
||||
list(APPEND srcs ${iter})
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
if(ARG_FIX)
|
||||
list(APPEND args "-fix-errors")
|
||||
endif()
|
||||
if(NOT TARGET myxx-analyze-clang-tidy)
|
||||
add_custom_target(myxx-analyze-clang-tidy)
|
||||
endif()
|
||||
add_custom_target(${target}-analyze-clang-tidy
|
||||
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
|
||||
COMMAND ${CLANG_TIDY_EXE} ${args} -p ${CMAKE_BINARY_DIR} ${srcs})
|
||||
add_dependencies(${target}-analyze-clang-tidy ${target})
|
||||
add_dependencies(myxx-analyze-clang-tidy ${target}-analyze-clang-tidy)
|
||||
endfunction()
|
Reference in New Issue
Block a user