Skip to content

Commit

Permalink
Add Clang-Tidy to the Project (#54)
Browse files Browse the repository at this point in the history
This PR enables `clang-tidy` in the main CMake file [5]. Clang-tidy will help to enable developer guidelines such as [1,2]. The C++ Core Guidelines checkers are more a MSVC tool, which is not usable in a multi-platform development framework. A documentation for `clang-tidy` can be found in [4].

References:
[1] https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines
[2] https://developers.google.com/style/
[3] https://github.com/MicrosoftDocs/cpp-docs/blob/main/docs/code-quality/using-the-cpp-core-guidelines-checkers.md
[4] https://clang.llvm.org/extra/clang-tidy/
[5] https://cmake.org/cmake/help/latest/variable/CMAKE_LANG_CLANG_TIDY.html

* Add Clang-Tidy to the project
* Install LLVM for Clang-Tidy on MacOS
   Why?
   * The CXX compiler identification is AppleClang 14.0.0.14000029
   * ls -la /Library/Developer/CommandLineTools/usr/bin/c*
   * For more information, see https://stackoverflow.com/questions/53111082/how-to-install-clang-tidy-on-macos
* Add GitHub's `homebrew` path hint to `find_program`
  • Loading branch information
franziska-wegner authored Dec 27, 2023
1 parent fe424e7 commit 6a26946
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/cmake-multi-platform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ jobs:
cache-key-prefix: ${{ runner.os }}-Qt-Cache-${{ env.QT_VERSION }}
dir: ${{ github.workspace }}/Qt

- name: Install LLVM for Clang-Tidy (MacOS)
if: startsWith(matrix.os,'macos-')
run: |
brew install llvm
# - name: Install correct version of mingw
# uses: crazy-max/ghaction-chocolatey@v1
# with:
Expand Down
10 changes: 10 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ if ( EGOA_ENABLE_BOOST )
include ( Boost )
endif ( EGOA_ENABLE_BOOST )

# Search for clang-tidy
find_package ( ClangTidy )

# Google tests
if ( EGOA_ENABLE_TESTS )
include ( CTest )
Expand Down Expand Up @@ -227,6 +230,13 @@ if ( Qt6_FOUND )
target_compile_definitions ( EGOA PUBLIC QT6_AVAILABLE )
endif ( Qt6_FOUND )

# clang-tidy found
if ( CLANG_TIDY_PROG )
message ( STATUS "${MY_SPACE}clang-tidy:\t\t\t\tis enabled" )
# set CXX_CLANG_TIDY property after defining the target
# set_target_properties(EGOA PROPERTIES CXX_CLANG_TIDY "${CMAKE_CXX_CLANG_TIDY}")
endif ( CLANG_TIDY_PROG )

# OpenMP found
if ( OPENMP_FOUND )
message ( STATUS "${MY_SPACE}OpenMP:\t\t\t\tadd libraries of OpenMP" )
Expand Down
29 changes: 29 additions & 0 deletions cmake/FindClangTidy.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# FindClangTidy.cmake
#
# Created on: Dec 27, 2023
# Author: Franziska Wegner
#
# This file enables clang tidy for the project.
#


# Search for clang-tidy
find_program(CLANG_TIDY_PROG
HINTS "/opt/homebrew/opt/llvm/bin/"
"/usr/local/opt/llvm/bin/"
NAMES "clang-tidy"
REQUIRED
)
# Setup clang-tidy command with executable and options, see https://cmake.org/cmake/help/latest/variable/CMAKE_LANG_CLANG_TIDY.html.
# Disable all default checks (-*) and only enable checks that advocate the use of modern C++ language constructs with (modernize-*).
set(CMAKE_CXX_CLANG_TIDY
"${CLANG_TIDY_PROG}"
"-checks=-*,modernize-*"
# -format-style='file';
# -header-filter=${CMAKE_CURRENT_SOURCE_DIR};
# -header-filter=.;
# -warnings-as-errors=*;
)

# set CXX_CLANG_TIDY property after defining the target
# set_target_properties(EGOA PROPERTIES CXX_CLANG_TIDY "${CMAKE_CXX_CLANG_TIDY}")

0 comments on commit 6a26946

Please sign in to comment.