From 8b3e061943b714612f99b6f844efe682c1b2022b Mon Sep 17 00:00:00 2001 From: Florian Uhlig <f.uhlig@gsi.de> Date: Wed, 13 Sep 2023 15:21:49 +0200 Subject: [PATCH] Create the compile command database for clang-tidy Add the sytem compiler include paths needed for our static standalone clang-tidy binary to the list of include paths. The paths are only added to the compilation units in the generated file compile_commands.json which is used as input for clang-tidy. Without the paths clang-tidy can't find the standard C and C++ header files. The geometries, parameters and input data are not needed when running clang-tidy, so don't waste time downloading them. The still downloaded projects include header files which are used by CbmRoot classes. If these header files are not found by clang-tidy the check of some compilation units fail. Use VC in scalar mode, otherwise system and hardware related header files are needed which couldn't be found. Fix an issue with an missing header file in KFParticle when using the scalar VC version. --- CMakeLists.txt | 16 ++++++++++++++++ external/CMakeLists.txt | 9 ++++++--- external/InstallKFParticle.cmake | 22 ++++++++++++++++------ external/KFParticle_clang_tidy.patch | 13 +++++++++++++ 4 files changed, 51 insertions(+), 9 deletions(-) create mode 100644 external/KFParticle_clang_tidy.patch diff --git a/CMakeLists.txt b/CMakeLists.txt index ba1ed98646..72410085a9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -231,6 +231,7 @@ If(BUILD_UNITTESTS) Include(external/InstallGtest.cmake) endif() + ### Subdirectories to be compiled ##### ### Externals included and build from several sources @@ -238,6 +239,21 @@ endif() # following targets add_subdirectory (external) +option(BUILD_FOR_TIDY "Create compile commands database needed by clang-tidy" OFF) +# Add the default compiler include paths needed for our static standalone clang-tidy +# binary. The paths are only added to the compilation units in the generated file +# compile_commands.json which is used as input for clang-tidy. Without the +# paths clang-tidy can't find the standard C and C++ header files. +# Also add special compile options to use the scalar version of VC. +# Otherwise hardware and compiler dependent header files may not be found. +# Since we want to check our code and not some system headers this is +# acceptable. +if(BUILD_FOR_TIDY) + ADD_DEFINITIONS(-DVc_IMPL=Scalar) + set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES + ${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES} + ) +endif() ### Base directories add_subdirectory (core) diff --git a/external/CMakeLists.txt b/external/CMakeLists.txt index e6743c009e..5935eef5c8 100644 --- a/external/CMakeLists.txt +++ b/external/CMakeLists.txt @@ -72,14 +72,17 @@ if(DOWNLOAD_EXTERNALS) Include(InstallAnalysisTree.cmake) Include(InstallAnalysisTreeQA.cmake) - Include(InstallParameter.cmake) - Include(InstallInput.cmake) - Include(InstallGeometry.cmake) Include(InstallYamlCpp.cmake) Include(InstallBBA.cmake) + if(NOT BUILD_FOR_TIDY) + Include(InstallParameter.cmake) + Include(InstallInput.cmake) + Include(InstallGeometry.cmake) + endif() + else() # Define targets which are needed by CbmRoot but are not available # whithout the external packages diff --git a/external/InstallKFParticle.cmake b/external/InstallKFParticle.cmake index d95717419b..df7073ed30 100644 --- a/external/InstallKFParticle.cmake +++ b/external/InstallKFParticle.cmake @@ -14,12 +14,22 @@ if (CMAKE_SYSTEM_NAME MATCHES Darwin AND ${CMAKE_SYSTEM_PROCESSOR} MATCHES arm64 PATCH_COMMAND "patch -p1 < ${CMAKE_CURRENT_SOURCE_DIR}/KFParticle_applem1.patch" ) else() - download_project_if_needed(PROJECT kfparticle_source - GIT_REPOSITORY ${KFPARTICLE_SRC_URL} - GIT_TAG ${KFPARTICLE_TAG} - SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/KFParticle - TEST_FILE CMakeLists.txt - ) + if(BUILD_FOR_TIDY) + download_project_if_needed(PROJECT kfparticle_source + GIT_REPOSITORY ${KFPARTICLE_SRC_URL} + GIT_TAG ${KFPARTICLE_TAG} + SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/KFParticle + TEST_FILE CMakeLists.txt + PATCH_COMMAND "patch -p1 < ${CMAKE_CURRENT_SOURCE_DIR}/KFParticle_clang_tidy.patch" + ) + else() + download_project_if_needed(PROJECT kfparticle_source + GIT_REPOSITORY ${KFPARTICLE_SRC_URL} + GIT_TAG ${KFPARTICLE_TAG} + SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/KFParticle + TEST_FILE CMakeLists.txt + ) + endif() endif() If(ProjectUpdated) diff --git a/external/KFParticle_clang_tidy.patch b/external/KFParticle_clang_tidy.patch new file mode 100644 index 0000000000..86300f0cdb --- /dev/null +++ b/external/KFParticle_clang_tidy.patch @@ -0,0 +1,13 @@ +diff --git a/KFParticle/KFPSimdAllocator.h b/KFParticle/KFPSimdAllocator.h +index 20a13c4..704423f 100644 +--- a/KFParticle/KFPSimdAllocator.h ++++ b/KFParticle/KFPSimdAllocator.h +@@ -24,6 +24,8 @@ + + #include <Vc/Vc> + ++#include <mm_malloc.h> ++ + /** @class KFPSimdAllocator + ** @brief Allocator which is needed to allocate memory in std::vector aligned by the size of SIMD vectors. + ** @author M.Zyzak, I.Kisel -- GitLab