1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-10-06 09:07:19 +02: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) include(CMakeParseArguments)
if(CHECK_INCLUDES) if(CHECK_IWYU)
find_package(IncludeWhatYouUse REQUIRED) find_package(IncludeWhatYouUse REQUIRED)
endif() 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) function(openrw_target_apply_options)
set(IWYU_MAPPING "${PROJECT_SOURCE_DIR}/openrw_iwyu.imp") set(IWYU_MAPPING "${PROJECT_SOURCE_DIR}/openrw_iwyu.imp")
cmake_parse_arguments("OPENRW_APPLY" "" "TARGET" "" ${ARGN}) cmake_parse_arguments("OPENRW_APPLY" "" "TARGET" "" ${ARGN})
if(CHECK_INCLUDES) if(CHECK_IWYU)
iwyu_check(TARGET "${OPENRW_APPLY_TARGET}" iwyu_check(TARGET "${OPENRW_APPLY_TARGET}"
EXTRA_OPTS EXTRA_OPTS
"--mapping_file=${IWYU_MAPPING}" "--mapping_file=${IWYU_MAPPING}"
) )
endif() endif()
if(CHECK_CLANGTIDY)
set_target_properties("${OPENRW_APPLY_TARGET}"
PROPERTIES
C_CLANG_TIDY "${CLANGTIDY_ARGS}"
CXX_CLANG_TIDY "${CLANGTIDY_ARGS}"
)
endif()
endfunction() 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") set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build, options are: Debug Release")
endif() 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(TEST_COVERAGE "Enable coverage analysis (implies CMAKE_BUILD_TYPE=Debug)")
option(SEPARATE_TEST_SUITES "Add each test suite as separate test to CTest") option(SEPARATE_TEST_SUITES "Add each test suite as separate test to CTest")