1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-11-22 10:22:52 +01:00

cmake: add support clang-tidy (=C/C++ linter)

This commit is contained in:
Anonymous Maarten 2018-03-06 00:49:11 +01:00
parent 070f58809e
commit 6e33af303e
2 changed files with 26 additions and 3 deletions

View File

@ -125,17 +125,39 @@ endif()
include(CMakeParseArguments)
if(CHECK_INCLUDES)
if(CHECK_IWYU)
find_package(IncludeWhatYouUse REQUIRED)
endif()
if(CHECK_CLANGTIDY)
find_program(CLANGTIDY_PROGRAM
clang-tidy
)
if(NOT CLANGTIDY_PROGRAM)
message(FATAL_ERROR "Cannot find clang-tidy")
endif()
set(CLANGTIDY_ARGS "${CLANGTIDY_PROGRAM}")
list(APPEND CLANGTIDY_ARGS
"-style=file"
"-checks=*"
)
endif()
function(openrw_target_apply_options)
set(IWYU_MAPPING "${PROJECT_SOURCE_DIR}/openrw_iwyu.imp")
cmake_parse_arguments("OPENRW_APPLY" "" "TARGET" "" ${ARGN})
if(CHECK_INCLUDES)
if(CHECK_IWYU)
iwyu_check(TARGET "${OPENRW_APPLY_TARGET}"
EXTRA_OPTS
"--mapping_file=${IWYU_MAPPING}"
)
endif()
if(CHECK_CLANGTIDY)
set_target_properties("${OPENRW_APPLY_TARGET}"
PROPERTIES
C_CLANG_TIDY "${CLANGTIDY_ARGS}"
CXX_CLANG_TIDY "${CLANGTIDY_ARGS}"
)
endif()
endfunction()

View File

@ -21,7 +21,8 @@ if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build, options are: Debug Release")
endif()
option(CHECK_INCLUDES "Analyze #includes in C and C++ source files")
option(CHECK_IWYU "Enable IncludeWhatYouUse (Analyze #includes in C and C++ source files)")
option(CHECK_CLANGTIDY "Enable clang-tidy (A clang-based C++ linter tool)")
option(TEST_COVERAGE "Enable coverage analysis (implies CMAKE_BUILD_TYPE=Debug)")
option(SEPARATE_TEST_SUITES "Add each test suite as separate test to CTest")