update readme and add clangformat and clang tidy

This commit is contained in:
Aaron Po
2026-04-02 17:12:22 -04:00
parent 98083ab40c
commit 2ea8aa52b4
4 changed files with 98 additions and 0 deletions

10
pipeline/.clang-format Normal file
View 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
View 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
...

View File

@@ -13,6 +13,20 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF) set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) 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) # Compiler Options & Warnings (Interface Library)
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
@@ -77,6 +91,12 @@ set(PIPELINE_SOURCES
add_executable(biergarten-pipeline ${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 target_include_directories(biergarten-pipeline
PRIVATE PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/includes ${CMAKE_CURRENT_SOURCE_DIR}/includes
@@ -94,6 +114,32 @@ target_link_libraries(biergarten-pipeline
Boost::json 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 # Post-Build Steps & Utilities
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------

View File

@@ -197,3 +197,28 @@ Run
./biergarten-pipeline ./biergarten-pipeline
Output: Logs to console; caches JSON in /tmp/countries+states+cities.json. 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 ..