Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .clang-format
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
BasedOnStyle: Google
IndentWidth: 2
TabWidth: 3
TabWidth: 2
ColumnLimit: 100
RequiresClausePosition: OwnLine
RequiresExpressionIndentation: OuterScope
SpacesInContainerLiterals: true
48 changes: 37 additions & 11 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -1,19 +1,45 @@
Checks: >
-*,
bugprone-*,
modernize-*,
readability-*,
cppcoreguidelines-*,
performance-*,
clang-analyzer-*,
cert-*,
misc-*,
google-*,
llvm-*,
hicpp-*
modernize-*,
performance-*,
readability-const-return-type,
readability-container-size-empty,
readability-make-member-function-const,
readability-redundant-member-init,
readability-redundant-smartptr-get,
readability-redundant-string-cstr,
readability-simplify-boolean-expr,
readability-static-accessed-through-instance,
readability-string-compare,
cppcoreguidelines-init-variables,
cppcoreguidelines-prefer-member-initializer,
cppcoreguidelines-slicing,
-bugprone-easily-swappable-parameters,
-misc-const-correctness,
-misc-include-cleaner,
-misc-no-recursion,
-misc-non-private-member-variables-in-classes,
-misc-unused-parameters,
-misc-use-anonymous-namespace,
-misc-definitions-in-headers,
-misc-use-internal-linkage,
-modernize-use-trailing-return-type

WarningsAsErrors: >
bugprone-use-after-move,
bugprone-dangling-handle

HeaderFilterRegex: 'src/.*\.(hpp|h)$'

FormatStyle: file

CheckOptions:
- key: modernize-use-nullptr.NullMacros
value: 'Google'
- key: modernize-use-override.IgnoreDestructors
value: true
value: 'NULL'
- key: performance-move-const-arg.CheckTriviallyCopyableMove
value: 'false'
- key: misc-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic
value: 'true'
46 changes: 36 additions & 10 deletions .github/workflows/cpp-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,47 @@ name: C++ CI

on:
push:
branches: [ "main" ]
branches: ["main"]
pull_request:
branches: [ "main" ]
branches: ["main"]

jobs:
build_and_test:
runs-on: ubuntu-latest
format-check:
name: Format Check
runs-on: ubuntu-24.04
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Install Dependencies
uses: actions/checkout@v6

- name: Check format
run: |
clang-format --version
find src tests \( -name "*.hpp" -o -name "*.cpp" -o -name "*.h" \) | \
xargs clang-format --dry-run --Werror

build-and-test:
name: Build and Test
runs-on: ubuntu-24.04
needs: format-check
steps:
- name: Check out repository
uses: actions/checkout@v6

- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y cmake build-essential libgtest-dev
- name: Build and run tests
sudo apt-get install -y libgtest-dev

- name: Show tool versions
run: |
chmod +x ./scripts/run_tests.sh
./scripts/run_tests.sh
cmake --version
g++ --version

- name: Configure
run: cmake --preset ci

- name: Build
run: cmake --build --preset ci

- name: Test
run: ctest --preset ci
6 changes: 5 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,9 @@
"C_Cpp.default.includePath": [
"${workspaceFolder}/src"
],
"C_Cpp.default.intelliSenseMode": "clang-x64"
"C_Cpp.default.intelliSenseMode": "clang-x64",
"files.associations": {
".clang-tidy": "yaml",
".clang-format": "yaml"
}
}
55 changes: 41 additions & 14 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
cmake_minimum_required(VERSION 3.10)
cmake_minimum_required(VERSION 3.25)

project(CLAVIS LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED True)

# Set build type (default is Debug)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug)
endif()

# Basic compiler flags
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
endif()

# Collect source files
# NOTE: file(GLOB) is not recommended by CMake official docs.
# Consider listing source files explicitly for reliable rebuilds.
# See: https://cmake.org/cmake/help/latest/command/file.html#glob
file(GLOB CORE_SOURCES
src/*.cpp
src/graph/*.hpp
Expand All @@ -38,6 +33,14 @@ set(SOURCES ${CORE_SOURCES})
# Create library
add_library(clavis_algorithm ${SOURCES})

# Set C++ standard (modern target-based approach)
target_compile_features(clavis_algorithm PUBLIC cxx_std_20)

# Set compiler warnings (target-based, not global CMAKE_CXX_FLAGS)
target_compile_options(clavis_algorithm PRIVATE
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wall -Wextra>
)

# Set include directories
target_include_directories(clavis_algorithm PUBLIC
${CMAKE_SOURCE_DIR}/src
Expand All @@ -57,26 +60,41 @@ target_include_directories(clavis_algorithm_test PRIVATE

target_link_libraries(clavis_algorithm_test clavis_algorithm GTest::GTest GTest::Main)

# Register test
add_test(NAME AlgorithmTest COMMAND clavis_algorithm_test)
# Set compiler warnings for tests
target_compile_options(clavis_algorithm_test PRIVATE
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wall -Wextra>
)

# Discover and register tests
include(GoogleTest)
gtest_discover_tests(clavis_algorithm_test)

# =============================================================================
# Code Quality Tools
# =============================================================================

# Collect all C++ files for formatting/linting
# Collect all C++ files for formatting
file(GLOB_RECURSE ALL_CXX_FILES
${CMAKE_SOURCE_DIR}/src/*.hpp
${CMAKE_SOURCE_DIR}/src/*.cpp
${CMAKE_SOURCE_DIR}/src/*.h
${CMAKE_SOURCE_DIR}/tests/*.cpp
)

# Collect source files only for linting (exclude tests)
file(GLOB_RECURSE SRC_CXX_FILES
${CMAKE_SOURCE_DIR}/src/*.hpp
${CMAKE_SOURCE_DIR}/src/*.cpp
${CMAKE_SOURCE_DIR}/src/*.h
)

# clang-format targets
find_program(CLANG_FORMAT clang-format
HINTS
$ENV{LLVM_DIR}/bin
/opt/homebrew/opt/llvm/bin
/usr/local/opt/llvm/bin
/usr/bin
)
if(CLANG_FORMAT)
add_custom_target(format
Expand All @@ -97,13 +115,22 @@ endif()
# clang-tidy target
find_program(CLANG_TIDY clang-tidy
HINTS
$ENV{LLVM_DIR}/bin
/opt/homebrew/opt/llvm/bin
/usr/local/opt/llvm/bin
/usr/bin
)
if(CLANG_TIDY)
add_custom_target(lint
COMMAND ${CLANG_TIDY} -p ${CMAKE_BINARY_DIR} ${ALL_CXX_FILES}
COMMENT "Running clang-tidy"
COMMAND ${CLANG_TIDY}
-p ${CMAKE_BINARY_DIR}
-header-filter=${CMAKE_SOURCE_DIR}/src/.*
${SRC_CXX_FILES}
--
-x c++
-std=c++20
-I${CMAKE_SOURCE_DIR}/src
COMMENT "Running clang-tidy on source files"
VERBATIM
)
else()
Expand Down
107 changes: 107 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
{
"$schema": "https://cmake.org/cmake/help/latest/_downloads/3e2d73bff478d88a7de0de736ba5e361/schema.json",
"version": 8,
"cmakeMinimumRequired": {
"major": 3,
"minor": 25,
"patch": 0
},
"configurePresets": [
{
"name": "base",
"hidden": true,
"generator": "Ninja",
"binaryDir": "${sourceDir}/build/${presetName}",
"cacheVariables": {
"CMAKE_CXX_STANDARD": "20",
"CMAKE_CXX_STANDARD_REQUIRED": "ON",
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON"
}
},
{
"name": "debug",
"displayName": "Debug",
"inherits": "base",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug"
}
},
{
"name": "release",
"displayName": "Release",
"inherits": "base",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release"
}
},
{
"name": "ci",
"displayName": "CI",
"inherits": "base",
"generator": "Unix Makefiles",
"binaryDir": "${sourceDir}/build",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug"
}
}
],
"buildPresets": [
{
"name": "debug",
"configurePreset": "debug"
},
{
"name": "release",
"configurePreset": "release"
},
{
"name": "ci",
"configurePreset": "ci",
"jobs": 4
}
],
"testPresets": [
{
"name": "base",
"hidden": true,
"output": {
"outputOnFailure": true,
"verbosity": "default"
},
"execution": {
"noTestsAction": "error",
"stopOnFailure": false
}
},
{
"name": "debug",
"configurePreset": "debug",
"inherits": "base"
},
{
"name": "release",
"configurePreset": "release",
"inherits": "base"
},
{
"name": "ci",
"configurePreset": "ci",
"inherits": "base",
"output": {
"outputOnFailure": true,
"verbosity": "verbose"
}
}
],
"workflowPresets": [
{
"name": "ci",
"displayName": "CI Workflow",
"steps": [
{ "type": "configure", "name": "ci" },
{ "type": "build", "name": "ci" },
{ "type": "test", "name": "ci" }
]
}
]
}
Loading