From 6e33af303e2ff7f96ef6550a7f5c0a14440a074d Mon Sep 17 00:00:00 2001 From: Anonymous Maarten Date: Tue, 6 Mar 2018 00:49:11 +0100 Subject: [PATCH] cmake: add support clang-tidy (=C/C++ linter) --- cmake_configure.cmake | 26 ++++++++++++++++++++++++-- cmake_options.cmake | 3 ++- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/cmake_configure.cmake b/cmake_configure.cmake index 5daa2c50..053cd191 100644 --- a/cmake_configure.cmake +++ b/cmake_configure.cmake @@ -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() diff --git a/cmake_options.cmake b/cmake_options.cmake index 2db0ecd0..014664e1 100644 --- a/cmake_options.cmake +++ b/cmake_options.cmake @@ -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")