53 lines
1.5 KiB
CMake
53 lines
1.5 KiB
CMake
|
include_guard(GLOBAL)
|
||
|
|
||
|
if(NOT CLANG_CHECK_NAME)
|
||
|
set(CLANG_CHECK_NAMES clang-check)
|
||
|
foreach(V RANGE 9 18)
|
||
|
list(INSERT CLANG_CHECK_NAMES 0 "clang-check-${V}")
|
||
|
endforeach()
|
||
|
unset(V)
|
||
|
else()
|
||
|
set(CLANG_CHECK_NAMES ${CLANG_CHECK_NAME})
|
||
|
endif()
|
||
|
|
||
|
find_program(CLANG_CHECK_EXE NAMES ${CLANG_CHECK_NAMES})
|
||
|
unset(CLANG_CHECK_NAMES)
|
||
|
|
||
|
function(myxx_analyze_clang_check target)
|
||
|
if(NOT CLANG_CHECK_EXE)
|
||
|
message(STATUS "MyxCMake: Clang Check analyzer is not found")
|
||
|
return()
|
||
|
endif()
|
||
|
|
||
|
if(TARGET ${target}-analyze-clang-check)
|
||
|
message(STATUS "MyxxCMake: target ${target}-analyze-clang-check already exists")
|
||
|
return()
|
||
|
endif()
|
||
|
|
||
|
set(options FIX)
|
||
|
set(oneValueArgs)
|
||
|
set(multiValueArgs EXTRA_ARGS)
|
||
|
cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
|
||
|
|
||
|
set(args --analyze --extra-arg=-Wno-unknown-warning-option ${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 "--fixit")
|
||
|
endif()
|
||
|
if(NOT TARGET myxx-analyze-clang-check)
|
||
|
add_custom_target(myxx-analyze-clang-check)
|
||
|
endif()
|
||
|
add_custom_target(${target}-analyze-clang-check
|
||
|
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
|
||
|
COMMAND ${CLANG_CHECK_EXE} ${args} -p ${CMAKE_BINARY_DIR} ${srcs})
|
||
|
add_dependencies(${target}-analyze-clang-check ${target})
|
||
|
add_dependencies(myxx-analyze-clang-check ${target}-analyze-clang-check)
|
||
|
endfunction()
|