57 lines
1.7 KiB
CMake
57 lines
1.7 KiB
CMake
include_guard(GLOBAL)
|
|
|
|
if(NOT CLANG_CHECK_NAME)
|
|
set(CLANG_CHECK_NAMES clang-check)
|
|
foreach(V RANGE 9 19)
|
|
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_NAME)
|
|
if(NOT ${PROJECT_BINARY_DIR} STREQUAL ${CMAKE_BINARY_DIR})
|
|
return()
|
|
endif()
|
|
|
|
if(NOT CLANG_CHECK_EXE)
|
|
message(STATUS "MyxCMake: Clang Check analyzer is not found")
|
|
return()
|
|
endif()
|
|
|
|
if(TARGET ${TARGET_NAME}-analyze-clang-check)
|
|
message(STATUS "MyxxCMake: target ${TARGET_NAME}-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(__cmd_args --analyze --extra-arg=-Wno-unknown-warning-option ${EXTRA_ARGS})
|
|
get_target_property(__sources ${TARGET_NAME} SOURCES)
|
|
foreach(iter ${__sources})
|
|
string(FIND ${iter} ${CMAKE_BINARY_DIR} pos)
|
|
if(pos EQUAL -1)
|
|
list(APPEND __filtered_sources ${iter})
|
|
endif()
|
|
endforeach()
|
|
|
|
if(ARG_FIX)
|
|
list(APPEND __cmd_args "--fixit")
|
|
endif()
|
|
if(NOT TARGET myxx-analyze-clang-check)
|
|
add_custom_target(myxx-analyze-clang-check)
|
|
endif()
|
|
add_custom_target(${TARGET_NAME}-analyze-clang-check
|
|
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
|
|
COMMAND ${CLANG_CHECK_EXE} ${__cmd_args} -p ${CMAKE_BINARY_DIR} ${__filtered_sources})
|
|
add_dependencies(${TARGET_NAME}-analyze-clang-check ${TARGET_NAME})
|
|
add_dependencies(myxx-analyze-clang-check ${TARGET_NAME}-analyze-clang-check)
|
|
endfunction()
|