macOS: Add support for clang-tidy checks during compilation

This commit adds support for clang-tidy checks during compilation on
macOS, which can now be enabled using the optional `WITH_CLANG_TIDY`
CMake variable.

The clang-tidy executable doesn't need to be separately installed since
CMake will pick up the executable from the LLVM pre-compiled library.
This commit also expands the coverage of clang-tidy checks to
Objective-C/C++, for which checks were enabled in PR #128334.

Pull Request: https://projects.blender.org/blender/blender/pulls/129761
This commit is contained in:
Jonas Holzman
2024-11-13 16:14:01 +01:00
committed by Jonas Holzman
parent 365f58ca0c
commit 527a08ac42
2 changed files with 9 additions and 6 deletions

View File

@@ -289,10 +289,10 @@ Use pre-compiled headers to speed up compilation."
) )
mark_as_advanced(WITH_COMPILER_PRECOMPILED_HEADERS) mark_as_advanced(WITH_COMPILER_PRECOMPILED_HEADERS)
if(WITH_CLANG_TIDY AND CMAKE_COMPILER_IS_GNUCC) if(WITH_CLANG_TIDY AND (CMAKE_COMPILER_IS_GNUCC OR APPLE))
if(WITH_COMPILER_PRECOMPILED_HEADERS) if(WITH_COMPILER_PRECOMPILED_HEADERS)
message(STATUS message(STATUS
"Clang-Tidy and GCC precompiled headers are incompatible, disabling precompiled headers" "Clang-Tidy and the current compiler's precompiled headers are incompatible, disabling precompiled headers."
) )
set(WITH_COMPILER_PRECOMPILED_HEADERS OFF) set(WITH_COMPILER_PRECOMPILED_HEADERS OFF)
endif() endif()
@@ -783,7 +783,7 @@ mark_as_advanced(WITH_ASSERT_ABORT)
option(WITH_ASSERT_RELEASE "Build with asserts enabled even for non-debug configurations" OFF) option(WITH_ASSERT_RELEASE "Build with asserts enabled even for non-debug configurations" OFF)
mark_as_advanced(WITH_ASSERT_RELEASE) mark_as_advanced(WITH_ASSERT_RELEASE)
if((UNIX AND NOT APPLE) OR (CMAKE_GENERATOR MATCHES "^Visual Studio.+")) if(UNIX OR (CMAKE_GENERATOR MATCHES "^Visual Studio.+"))
option(WITH_CLANG_TIDY "\ option(WITH_CLANG_TIDY "\
Use Clang Tidy to analyze the source code \ Use Clang Tidy to analyze the source code \
(only enable for development on Linux using Clang, or Windows using the Visual Studio IDE)" (only enable for development on Linux using Clang, or Windows using the Visual Studio IDE)"

View File

@@ -8,9 +8,12 @@ endif()
if(WITH_CLANG_TIDY AND NOT MSVC) if(WITH_CLANG_TIDY AND NOT MSVC)
find_package(ClangTidy REQUIRED) find_package(ClangTidy REQUIRED)
set(CMAKE_C_CLANG_TIDY set(CLANG_TIDY_EXTRA_ARGS --extra-arg=-Wno-error=unknown-warning-option)
${CLANG_TIDY_EXECUTABLE};--extra-arg=-Wno-error=unknown-warning-option)
set(CMAKE_CXX_CLANG_TIDY ${CLANG_TIDY_EXECUTABLE};--extra-arg=-Wno-error=unknown-warning-option) set(CMAKE_C_CLANG_TIDY ${CLANG_TIDY_EXECUTABLE};${CLANG_TIDY_EXTRA_ARGS})
set(CMAKE_CXX_CLANG_TIDY ${CLANG_TIDY_EXECUTABLE};${CLANG_TIDY_EXTRA_ARGS})
set(CMAKE_OBJC_CLANG_TIDY ${CLANG_TIDY_EXECUTABLE};${CLANG_TIDY_EXTRA_ARGS})
set(CMAKE_OBJCXX_CLANG_TIDY ${CLANG_TIDY_EXECUTABLE};${CLANG_TIDY_EXTRA_ARGS})
endif() endif()
add_subdirectory(blender) add_subdirectory(blender)