Create a check target to run clang-tidy

This help to run clang-tidy while build
Note: this only check example tree and needs
run-clang-tidy python script from llvm distro!
pull/1440/head
ClausKlein 6 years ago
parent 2d395a557f
commit e02480c301

@ -8,6 +8,7 @@ cmake_minimum_required(VERSION 3.2)
#---------------------------------------------------------------------------------------
include(cmake/utils.cmake)
include(cmake/ide.cmake)
include(cmake/clang-tidy.cmake)
spdlog_extract_version()
@ -180,8 +181,7 @@ if(SPDLOG_WCHAR_SUPPORT)
endif()
if(SPDLOG_NO_EXCEPTIONS)
target_compile_definitions(spdlog PUBLIC SPDLOG_NO_EXCEPTIONS)
target_compile_definitions(spdlog PUBLIC SPDLOG_NO_EXCEPTIONS)
target_compile_definitions(spdlog_header_only INTERFACE SPDLOG_NO_EXCEPTIONS)
if(NOT MSVC)

@ -0,0 +1,35 @@
option(ENABLE_CLANG_TIDY "Add run-clang-tidy automatically to builds" OFF)
find_program(CLANG_TIDY_EXE
NAMES run-clang-tidy.py run-clang-tidy run-clang-tidy-7
DOC "Path to clang-tidy executable")
if(CLANG_TIDY_EXE)
message(STATUS "clang-tidy found: ${CLANG_TIDY_EXE}")
set(DCMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CLANG_TIDY_CMD ${CLANG_TIDY_EXE})
message(STATUS "cmake source dir: ${CMAKE_SOURCE_DIR}")
if(ENABLE_CLANG_TIDY)
# NOTE: the project config file .clang-tidy is not found if the
# binary tree is not part of the source tree! CK
set(CMAKE_CXX_CLANG_TIDY ${CLANG_TIDY_CMD} CACHE STRING "" FORCE)
else()
set(CMAKE_CXX_CLANG_TIDY "" CACHE STRING "" FORCE) # delete it
endif()
if(NOT TARGET check)
add_custom_target(check)
message(STATUS "check target added")
set_target_properties(check PROPERTIES EXCLUDE_FROM_ALL TRUE)
endif()
add_custom_command(TARGET check PRE_BUILD
# -p BUILD_PATH Path used to read a compile command database (compile_commands.json).
# NOTE: we use defaults checks from .clang-tidy and examples only!
COMMAND ${CLANG_TIDY_EXE} -p ${CMAKE_BINARY_DIR} example
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" # location of compile_commands.json
COMMENT "Running check on targets at ${CMAKE_SOURCE_DIR} ..."
VERBATIM
)
else()
message(AUTHOR_WARNING "run-clang-tidy not found!")
endif()
Loading…
Cancel
Save