Add clang-tidy config and CMake/CI support.

This commit is contained in:
Pierre Wendling
2022-10-25 23:26:42 -04:00
committed by Sam Lantinga
parent 5fded632d6
commit fa8fba3812
6 changed files with 211 additions and 6 deletions

View File

@@ -69,6 +69,7 @@ include(${SDL3_SOURCE_DIR}/cmake/sdlfind.cmake)
include(${SDL3_SOURCE_DIR}/cmake/sdlplatform.cmake)
include(${SDL3_SOURCE_DIR}/cmake/CheckCPUArchitecture.cmake)
include(${SDL3_SOURCE_DIR}/cmake/GetGitRevisionDescription.cmake)
include(${SDL3_SOURCE_DIR}/cmake/3rdparty.cmake)
# Enable large file support on 32-bit glibc, so that we can access files
# with large inode numbers
@@ -439,6 +440,7 @@ set_option(SDL_LIBUDEV "Enable libudev support" ON)
set_option(SDL_ASAN "Use AddressSanitizer to detect memory errors" OFF)
option_string(SDL_VENDOR_INFO "Vendor name and/or version to add to SDL_REVISION" "")
set_option(SDL_CCACHE "Use Ccache to speed up build" ON)
set_option(SDL_CLANG_TIDY "Run clang-tidy static analysis" OFF)
option(SDL_WERROR "Enable -Werror" OFF)
@@ -2968,6 +2970,28 @@ else()
set(HAVE_CCACHE OFF)
endif()
if(SDL_CLANG_TIDY)
cmake_minimum_required(VERSION 3.6)
find_program(CLANG_TIDY_BINARY clang-tidy)
if(CLANG_TIDY_BINARY)
set(HAVE_CLANG_TIDY ON)
get_clang_tidy_ignored_files(CLANG_TIDY_IGNORED_FILES)
set(CLANG_TIDY_COMMAND "${CLANG_TIDY_BINARY}" "-extra-arg=-Wno-unknown-warning-option" "--line-filter=[${CLANG_TIDY_IGNORED_FILES}]")
if(SDL_WERROR)
list(APPEND CLANG_TIDY_COMMAND "--warnings-as-errors=*")
endif()
set(CMAKE_C_CLANG_TIDY ${CLANG_TIDY_COMMAND})
set(CMAKE_CXX_CLANG_TIDY ${CLANG_TIDY_COMMAND})
set(CMAKE_OBJC_CLANG_TIDY ${CLANG_TIDY_COMMAND})
set_source_files_properties(${SOURCE_FILES} PROPERTIES SKIP_PRECOMPILE_HEADERS TRUE)
file(GLOB STDLIB_SOURCES "${SDL3_SOURCE_DIR}/src/stdlib/*.c")
set_property(SOURCE ${STDLIB_SOURCES} APPEND PROPERTY COMPILE_DEFINITIONS "SDL_DISABLE_ANALYZE_MACROS")
else()
set(HAVE_CLANG_TIDY OFF)
endif()
endif()
if(SDL_TESTS)
set(HAVE_TESTS ON)
endif()