myxx/MyxxCMake/lib/AnalyzeClangCheck.cmake

57 lines
1.7 KiB
CMake
Raw Normal View History

2022-10-06 04:57:47 +00:00
include_guard(GLOBAL)
if(NOT CLANG_CHECK_NAME)
set(CLANG_CHECK_NAMES clang-check)
2024-03-28 07:08:29 +00:00
foreach(V RANGE 9 19)
2022-10-06 04:57:47 +00:00
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)
2022-10-09 18:15:35 +00:00
function(myxx_analyze_clang_check TARGET_NAME)
2022-10-19 13:59:18 +00:00
if(NOT ${PROJECT_BINARY_DIR} STREQUAL ${CMAKE_BINARY_DIR})
return()
endif()
2022-10-09 18:15:35 +00:00
2022-10-06 04:57:47 +00:00
if(NOT CLANG_CHECK_EXE)
message(STATUS "MyxCMake: Clang Check analyzer is not found")
return()
endif()
2022-10-09 18:15:35 +00:00
if(TARGET ${TARGET_NAME}-analyze-clang-check)
message(STATUS "MyxxCMake: target ${TARGET_NAME}-analyze-clang-check already exists")
2022-10-06 04:57:47 +00:00
return()
endif()
set(options FIX)
set(oneValueArgs)
set(multiValueArgs EXTRA_ARGS)
cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
2022-10-09 18:15:35 +00:00
set(__cmd_args --analyze --extra-arg=-Wno-unknown-warning-option ${EXTRA_ARGS})
get_target_property(__sources ${TARGET_NAME} SOURCES)
foreach(iter ${__sources})
2022-10-06 04:57:47 +00:00
string(FIND ${iter} ${CMAKE_BINARY_DIR} pos)
if(pos EQUAL -1)
2022-10-09 18:15:35 +00:00
list(APPEND __filtered_sources ${iter})
2022-10-06 04:57:47 +00:00
endif()
endforeach()
if(ARG_FIX)
2022-10-09 18:15:35 +00:00
list(APPEND __cmd_args "--fixit")
2022-10-06 04:57:47 +00:00
endif()
if(NOT TARGET myxx-analyze-clang-check)
add_custom_target(myxx-analyze-clang-check)
endif()
2022-10-09 18:15:35 +00:00
add_custom_target(${TARGET_NAME}-analyze-clang-check
2022-10-06 04:57:47 +00:00
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
2022-10-09 18:15:35 +00:00
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)
2022-10-06 04:57:47 +00:00
endfunction()