104 lines
3.2 KiB
CMake
104 lines
3.2 KiB
CMake
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_NAME)
|
|
myx_skip_external_target(${TARGET_NAME})
|
|
|
|
if(NOT CLANG_TIDY_EXE)
|
|
message(STATUS "MyxxCMake: Clang Tidy analyzer is not found")
|
|
return()
|
|
endif()
|
|
|
|
if(TARGET ${TARGET_NAME}-analyze-clang-tidy)
|
|
message(STATUS "MyxxCMake: target ${TARGET_NAME}-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(__cmd_args -extra-arg="-Wno-unknown-warning-option ${ARG_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 "-fix-errors")
|
|
endif()
|
|
if(NOT TARGET myxx-analyze-clang-tidy)
|
|
add_custom_target(myxx-analyze-clang-tidy)
|
|
endif()
|
|
add_custom_target(${TARGET_NAME}-analyze-clang-tidy
|
|
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
|
|
COMMAND ${CLANG_TIDY_EXE} ${__cmd_args} -p ${CMAKE_BINARY_DIR} ${__filtered_sources})
|
|
add_dependencies(${TARGET_NAME}-analyze-clang-tidy ${TARGET_NAME})
|
|
add_dependencies(myxx-analyze-clang-tidy ${TARGET_NAME}-analyze-clang-tidy)
|
|
endfunction()
|
|
|
|
|
|
function(myxx_analyze_clang_tidy_naming TARGET_NAME)
|
|
myx_skip_external_target(${TARGET_NAME})
|
|
|
|
if(NOT CLANG_TIDY_EXE)
|
|
message(STATUS "MyxxCMake: Clang Tidy analyzer is not found")
|
|
return()
|
|
endif()
|
|
|
|
set(options FIX)
|
|
set(oneValueArgs CONFIG)
|
|
set(multiValueArgs EXTRA_ARGS)
|
|
cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
|
|
|
|
if(NOT ARG_CONFIG)
|
|
set(ARG_CONFIG ${PROJECT_SOURCE_DIR}/.clang-tidy-naming)
|
|
endif()
|
|
|
|
if(NOT EXISTS ${ARG_CONFIG})
|
|
return()
|
|
endif()
|
|
|
|
if(TARGET ${TARGET_NAME}-analyze-clang-tidy-naming)
|
|
message(STATUS "MyxxCMake: target ${TARGET_NAME}-analyze-clang-tidy-naming already exists")
|
|
return()
|
|
endif()
|
|
|
|
set(__cmd_args -extra-arg="-Wno-unknown-warning-option ${ARG_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 "-fix-errors")
|
|
endif()
|
|
if(NOT TARGET myxx-analyze-clang-tidy-naming)
|
|
add_custom_target(myxx-analyze-clang-tidy-naming)
|
|
endif()
|
|
add_custom_target(${TARGET_NAME}-analyze-clang-tidy-naming
|
|
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
|
|
COMMAND ${CLANG_TIDY_EXE} ${__cmd_args} -p ${CMAKE_BINARY_DIR} ${__filtered_sources})
|
|
add_dependencies(${TARGET_NAME}-analyze-clang-tidy-naming ${TARGET_NAME})
|
|
add_dependencies(myxx-analyze-clang-tidy-naming ${TARGET_NAME}-analyze-clang-tidy-naming)
|
|
endfunction()
|