Skip to content

Commit

Permalink
Additional targets to perform clang-format/clang-tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
kennethassogba committed Nov 12, 2024
1 parent 91b91f4 commit ac8318c
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
4 changes: 2 additions & 2 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Generate this file
# clang-tidy -checks=*,-clang-analyzer-alpha.*,-llvm-include-order,-llvmlibc*,-modernize-use-trailing-return-type -dump-config examples/main.cpp -- -std=c++11 > .clang-tidy
# clang-tidy -checks=*,-clang-analyzer-alpha.*,-llvm-include-order,-llvmlibc*,-modernize-use-trailing-return-type -dump-config examples/main.cpp -- -std=c++20 > .clang-tidy
# Usage
# clang-tidy (-fix) examples/main.cpp -config='' -- -std=c++11 -I/include/path
# clang-tidy (-fix) examples/main.cpp -config='' -- -std=c++20 -I/include/path
---
Checks: 'clang-diagnostic-*,clang-analyzer-*,*,-clang-analyzer-alpha.*,-llvm-include-order,-llvmlibc*,-modernize-use-trailing-return-type'
WarningsAsErrors: ''
Expand Down
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ cmake_print_variables(CMAKE_CXX_COMPILER_RANLIB)
cmake_print_variables(OpenMP_CXX_FOUND OpenMP_CXX_FLAGS OpenMP_CXX_INCLUDE_DIRS)
cmake_print_variables(OpenMP::OpenMP_CXX OpenMP_CXX_VERSION)

# Including custom cmake rules
include(cmake/clang-cxx-dev-tools.cmake) # make clang-format and make clang-tidy

# Executables
add_executable(main examples/main.cpp) # create an executable using the specified file
target_link_libraries(main PUBLIC ${LINK_LIBS})
Expand Down
33 changes: 33 additions & 0 deletions cmake/clang-cxx-dev-tools.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Additional targets to perform clang-format/clang-tidy
# Get all project files
file(GLOB_RECURSE
ALL_CXX_SOURCE_FILES
*.[chi]pp *.[chi]xx *.cc *.hh *.ii *.[CHI]
)

# Adding clang-format target if executable is found
find_program(CLANG_FORMAT "clang-format")
if(CLANG_FORMAT)
add_custom_target(
clang-format
COMMAND /usr/bin/clang-format
-i
-style=file
${ALL_CXX_SOURCE_FILES}
)
endif()

# Adding clang-tidy target if executable is found
# find_program(CLANG_TIDY "clang-tidy")
# if(CLANG_TIDY)
# add_custom_target(
# clang-tidy
# COMMAND /usr/bin/clang-tidy
# ${ALL_CXX_SOURCE_FILES}
# -config=''
# --
# -std=c++20
# ${INCLUDE_DIRECTORIES}
# ${LIBS_DIR}
# )
# endif()

0 comments on commit ac8318c

Please sign in to comment.