[Bf-blender-cvs] [f637b470642] master: MSVC: Enable clang-tidy analyser

Ray Molenkamp noreply at git.blender.org
Thu Dec 3 19:01:11 CET 2020


Commit: f637b47064237683343f00190a1438638058e92e
Author: Ray Molenkamp
Date:   Thu Dec 3 11:00:58 2020 -0700
Branches: master
https://developer.blender.org/rBf637b47064237683343f00190a1438638058e92e

MSVC: Enable clang-tidy analyser

This enables the use of clang-tidy in the VS IDE.

To use it:

1 - Enable WITH_CLANG_TIDY in your cmake configuration
2 - From the Analyse pull down menu select Run Code Analysis on...

The analyser is currently not enabled by default on build
given it is quite slow and there are quite a few problems
it reports that we still need to deal with.

===================================================================

M	CMakeLists.txt
M	build_files/cmake/platform/platform_win32.cmake
M	source/CMakeLists.txt

===================================================================

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 81fe4739da4..0d7cf4e325c 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -427,8 +427,8 @@ mark_as_advanced(WITH_CXX_GUARDEDALLOC)
 option(WITH_ASSERT_ABORT "Call abort() when raising an assertion through BLI_assert()" ON)
 mark_as_advanced(WITH_ASSERT_ABORT)
 
-if(UNIX AND NOT APPLE)
-  option(WITH_CLANG_TIDY "Use Clang Tidy to analyze the source code (only enable for development on Linux using Clang)" OFF)
+if((UNIX AND NOT APPLE) OR (CMAKE_GENERATOR MATCHES "^Visual Studio.+"))
+  option(WITH_CLANG_TIDY "Use Clang Tidy to analyze the source code (only enable for development on Linux using Clang, or Windows using the Visual Studio IDE)" OFF)
   mark_as_advanced(WITH_CLANG_TIDY)
 endif()
 
diff --git a/build_files/cmake/platform/platform_win32.cmake b/build_files/cmake/platform/platform_win32.cmake
index 3954a5f143c..dd8b286c689 100644
--- a/build_files/cmake/platform/platform_win32.cmake
+++ b/build_files/cmake/platform/platform_win32.cmake
@@ -239,9 +239,24 @@ if(NOT EXISTS "${LIBDIR}/")
   message(FATAL_ERROR "\n\nWindows requires pre-compiled libs at: '${LIBDIR}'. Please run `make update` in the blender source folder to obtain them.")
 endif()
 
+if(CMAKE_GENERATOR MATCHES "^Visual Studio.+" AND # Only supported in the VS IDE
+   MSVC_VERSION GREATER_EQUAL 1924            AND # Supported for 16.4+
+   WITH_CLANG_TIDY                                # And Clang Tidy needs to be on
+  )
+  set(CMAKE_VS_GLOBALS
+    "RunCodeAnalysis=false"
+    "EnableMicrosoftCodeAnalysis=false"
+    "EnableClangTidyCodeAnalysis=true"
+  )
+  set(VS_CLANG_TIDY On)
+endif()
+
 # Mark libdir as system headers with a lower warn level, to resolve some warnings
 # that we have very little control over
-if(MSVC_VERSION GREATER_EQUAL 1914 AND NOT MSVC_CLANG AND NOT WITH_WINDOWS_SCCACHE)
+if(MSVC_VERSION GREATER_EQUAL 1914 AND # Available with 15.7+
+   NOT MSVC_CLANG                  AND # But not for clang
+   NOT WITH_WINDOWS_SCCACHE        AND # And not when sccache is enabled
+   NOT VS_CLANG_TIDY)                  # Clang-tidy does not like these options
   add_compile_options(/experimental:external /external:templates- /external:I "${LIBDIR}" /external:W0)
 endif()
 
diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt
index 88c19355960..0ce2341fc2e 100644
--- a/source/CMakeLists.txt
+++ b/source/CMakeLists.txt
@@ -22,7 +22,7 @@ if(WITH_LEGACY_OPENGL)
   add_definitions(-DWITH_LEGACY_OPENGL)
 endif()
 
-if(WITH_CLANG_TIDY)
+if(WITH_CLANG_TIDY AND NOT MSVC)
   if(NOT CMAKE_C_COMPILER_ID MATCHES "Clang")
     message(WARNING "Currently Clang-Tidy might fail with GCC toolchain, switch to Clang toolchain if that happens")
   endif()



More information about the Bf-blender-cvs mailing list