mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-04-05 10:09:03 +00:00
update readme and add clangformat and clang tidy
This commit is contained in:
10
pipeline/.clang-format
Normal file
10
pipeline/.clang-format
Normal file
@@ -0,0 +1,10 @@
|
||||
---
|
||||
BasedOnStyle: Google
|
||||
Standard: c++23
|
||||
ColumnLimit: 100
|
||||
IndentWidth: 2
|
||||
DerivePointerAlignment: false
|
||||
PointerAlignment: Left
|
||||
SortIncludes: true
|
||||
IncludeBlocks: Preserve
|
||||
...
|
||||
17
pipeline/.clang-tidy
Normal file
17
pipeline/.clang-tidy
Normal file
@@ -0,0 +1,17 @@
|
||||
---
|
||||
Checks: >
|
||||
-*,
|
||||
bugprone-*,
|
||||
clang-analyzer-*,
|
||||
cppcoreguidelines-*,
|
||||
google-*,
|
||||
modernize-*,
|
||||
performance-*,
|
||||
readability-*,
|
||||
-cppcoreguidelines-avoid-magic-numbers,
|
||||
-cppcoreguidelines-owning-memory,
|
||||
-readability-magic-numbers,
|
||||
-google-readability-todo
|
||||
HeaderFilterRegex: "^(src|includes)/.*"
|
||||
FormatStyle: file
|
||||
...
|
||||
@@ -13,6 +13,20 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||
|
||||
option(ENABLE_CLANG_TIDY "Enable clang-tidy static analysis for project targets" ON)
|
||||
option(ENABLE_CLANG_FORMAT_TARGETS "Enable clang-format helper targets" ON)
|
||||
|
||||
if(ENABLE_CLANG_TIDY)
|
||||
find_program(CLANG_TIDY_EXE NAMES clang-tidy)
|
||||
if(CLANG_TIDY_EXE)
|
||||
set(BIERGARTEN_CLANG_TIDY_COMMAND
|
||||
"${CLANG_TIDY_EXE};--config-file=${CMAKE_CURRENT_SOURCE_DIR}/.clang-tidy")
|
||||
message(STATUS "clang-tidy enabled: ${CLANG_TIDY_EXE}")
|
||||
else()
|
||||
message(STATUS "clang-tidy not found; static analysis is disabled")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# Compiler Options & Warnings (Interface Library)
|
||||
# -----------------------------------------------------------------------------
|
||||
@@ -77,6 +91,12 @@ set(PIPELINE_SOURCES
|
||||
|
||||
add_executable(biergarten-pipeline ${PIPELINE_SOURCES})
|
||||
|
||||
if(BIERGARTEN_CLANG_TIDY_COMMAND)
|
||||
set_target_properties(biergarten-pipeline PROPERTIES
|
||||
CXX_CLANG_TIDY "${BIERGARTEN_CLANG_TIDY_COMMAND}"
|
||||
)
|
||||
endif()
|
||||
|
||||
target_include_directories(biergarten-pipeline
|
||||
PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/includes
|
||||
@@ -94,6 +114,32 @@ target_link_libraries(biergarten-pipeline
|
||||
Boost::json
|
||||
)
|
||||
|
||||
if(ENABLE_CLANG_FORMAT_TARGETS)
|
||||
find_program(CLANG_FORMAT_EXE NAMES clang-format)
|
||||
if(CLANG_FORMAT_EXE)
|
||||
file(GLOB_RECURSE FORMAT_SOURCES CONFIGURE_DEPENDS
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/*.cc
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/includes/*.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/includes/*.hpp
|
||||
)
|
||||
|
||||
add_custom_target(format
|
||||
COMMAND ${CLANG_FORMAT_EXE} -style=file -i ${FORMAT_SOURCES}
|
||||
COMMENT "Formatting source files with clang-format (Google style)"
|
||||
VERBATIM
|
||||
)
|
||||
|
||||
add_custom_target(format-check
|
||||
COMMAND ${CLANG_FORMAT_EXE} -style=file --dry-run --Werror ${FORMAT_SOURCES}
|
||||
COMMENT "Checking source formatting with clang-format (Google style)"
|
||||
VERBATIM
|
||||
)
|
||||
else()
|
||||
message(STATUS "clang-format not found; format targets are disabled")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# Post-Build Steps & Utilities
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
@@ -197,3 +197,28 @@ Run
|
||||
./biergarten-pipeline
|
||||
|
||||
Output: Logs to console; caches JSON in /tmp/countries+states+cities.json.
|
||||
|
||||
Code Style and Static Analysis
|
||||
|
||||
This project is configured to use:
|
||||
|
||||
- clang-format with the Google C++ style guide (via .clang-format)
|
||||
- clang-tidy checks focused on Google, modernize, performance, and bug-prone rules (via .clang-tidy)
|
||||
|
||||
After configuring CMake, use:
|
||||
|
||||
cmake --build . --target format
|
||||
|
||||
to apply formatting, and:
|
||||
|
||||
cmake --build . --target format-check
|
||||
|
||||
to validate formatting without modifying files.
|
||||
|
||||
clang-tidy runs automatically on the biergarten-pipeline target when available. You can disable it at configure time:
|
||||
|
||||
cmake -DENABLE_CLANG_TIDY=OFF ..
|
||||
|
||||
You can also disable format helper targets:
|
||||
|
||||
cmake -DENABLE_CLANG_FORMAT_TARGETS=OFF ..
|
||||
|
||||
Reference in New Issue
Block a user