Skip to content

Commit 0cff2e3

Browse files
committed
Rework project structure
1 parent eb8c7f6 commit 0cff2e3

11 files changed

Lines changed: 512 additions & 55 deletions

File tree

.clang-format

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# Copyright Agustin K-ballo Berge, Fusion Fenix 2026
2+
#
3+
# Distributed under the Boost Software License, Version 1.0. (See accompanying
4+
# file LICENSE.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5+
---
6+
Language: Cpp
7+
Standard: Latest
8+
9+
# ── Indentation ──────────────────────────────────────────────────────────────
10+
IndentWidth: 4
11+
TabWidth: 4
12+
UseTab: Never
13+
ContinuationIndentWidth: 4
14+
IndentCaseLabels: true
15+
IndentPPDirectives: AfterHash # `# if`, `# define` inside nested ifdefs
16+
NamespaceIndentation: None # namespace bodies are NOT indented
17+
18+
# ── Column limit ─────────────────────────────────────────────────────────────
19+
ColumnLimit: 80 # classic; fits terminal & paper
20+
21+
# ── Brace style ──────────────────────────────────────────────────────────────
22+
BreakBeforeBraces: Mozilla # wraps after functions and classes/structs
23+
24+
# ── Spaces ───────────────────────────────────────────────────────────────────
25+
SpaceBeforeParens: ControlStatements
26+
SpaceInEmptyParentheses: false
27+
SpacesInParentheses: false
28+
SpacesInSquareBrackets: false
29+
SpacesInAngles: false # `vector<int>` not `vector< int >`
30+
SpaceAfterTemplateKeyword: true # `template <typename T>` (space after kw)
31+
SpaceBeforeAssignmentOperators: true
32+
SpaceBeforeCpp11BracedList: false
33+
34+
# ── Pointer / reference alignment ────────────────────────────────────────────
35+
# East-const style: `T const&`, `T*` → pointer/ref binds to the type, not name
36+
PointerAlignment: Left # `T* p` / `T& r` — type-side binding
37+
ReferenceAlignment: Left
38+
39+
# ── Template / requires ──────────────────────────────────────────────────────
40+
AlwaysBreakTemplateDeclarations: Yes # `template <…>` always on its own line
41+
# before the declaration
42+
43+
# ── Function / call formatting ───────────────────────────────────────────────
44+
AllowShortFunctionsOnASingleLine: Inline # only genuinely trivial accessors inline
45+
AllowShortIfStatementsOnASingleLine: true
46+
AllowShortLoopsOnASingleLine: true
47+
AllowShortLambdasOnASingleLine: Inline
48+
AlignAfterOpenBracket: BlockIndent # always breaks, places closing
49+
# brackets on new lines
50+
51+
BinPackArguments: true # all args same line
52+
BinPackParameters: true # same for parameters
53+
54+
# ── Return type ──────────────────────────────────────────────────────────────
55+
AlwaysBreakAfterReturnType: None # return type stays on same line as name
56+
# unless forced by column limit
57+
58+
# ── Constructor initialiser lists ────────────────────────────────────────────
59+
BreakConstructorInitializers: BeforeColon # `: base(x)\n, member_(y)` style
60+
ConstructorInitializerIndentWidth: 4
61+
PackConstructorInitializers: Never
62+
63+
# ── Inheritance ──────────────────────────────────────────────────────────────
64+
BreakInheritanceList: BeforeColon
65+
66+
# ── Include sorting ──────────────────────────────────────────────────────────
67+
SortIncludes: CaseSensitive
68+
IncludeBlocks: Regroup
69+
IncludeCategories:
70+
# 1. The library's own headers <eggs/…>
71+
- Regex: '^<eggs/'
72+
Priority: 1
73+
# 2. Standard library
74+
- Regex: '^<[a-z_]+>$'
75+
Priority: 2
76+
# 3. Everything else (config, platform)
77+
- Regex: '.*'
78+
Priority: 3
79+
80+
# ── Comments ─────────────────────────────────────────────────────────────────
81+
ReflowComments: false # do NOT reflow // section banners
82+
# (e.g. `// namespace detail`)
83+
SpacesBeforeTrailingComments: 1
84+
85+
# ── Alignment ────────────────────────────────────────────────────────────────
86+
AlignConsecutiveAssignments: false # no forced vertical alignment of `=`
87+
AlignConsecutiveDeclarations: false
88+
AlignTrailingComments: true # trailing `//` comments align in a block
89+
AlignEscapedNewlines: Left
90+
91+
# ── Misc ─────────────────────────────────────────────────────────────────────
92+
Cpp11BracedListStyle: true
93+
FixNamespaceComments: true # auto-add `// namespace foo` at closing }
94+
CompactNamespaces: false
95+
MaxEmptyLinesToKeep: 1
96+
KeepEmptyLinesAtTheStartOfBlocks: false
97+
DerivePointerAlignment: false
98+
SeparateDefinitionBlocks: Always # blank line between top-level definitions

.github/workflows/format.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Copyright Agustin K-ballo Berge, Fusion Fenix 2026
2+
#
3+
# Distributed under the Boost Software License, Version 1.0. (See accompanying
4+
# file LICENSE.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5+
6+
name: format
7+
8+
on:
9+
push:
10+
branches: [ main, feature/** ]
11+
pull_request:
12+
types: [opened, synchronize, reopened]
13+
14+
jobs:
15+
format:
16+
runs-on: ubuntu-latest
17+
18+
steps:
19+
- name: Checkout repository
20+
uses: actions/checkout@v5
21+
22+
# clang-format
23+
- name: Run clang-format check
24+
uses: jidicula/clang-format-action@v4.16.0
25+
with:
26+
clang-format-version: "22"
27+
check-path: "."
28+
exclude-regex: 'test/catch2/'
29+
30+
# gersemi
31+
- name: Set up Python
32+
uses: actions/setup-python@v6
33+
with:
34+
python-version: '3.11'
35+
36+
- name: Install Gersemi
37+
run: |
38+
python -m pip install --upgrade pip
39+
pip install gersemi[color]
40+
41+
- name: Run Gersemi check
42+
run: gersemi --check --diff --color .

.github/workflows/test.yml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# Copyright Agustin K-ballo Berge, Fusion Fenix 2026
2+
#
3+
# Distributed under the Boost Software License, Version 1.0. (See accompanying
4+
# file LICENSE.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5+
6+
name: test
7+
8+
on:
9+
push:
10+
branches: [ main, feature/** ]
11+
pull_request:
12+
types: [opened, synchronize, reopened]
13+
14+
jobs:
15+
build:
16+
name: ${{ matrix.os }} / ${{ matrix.compiler }}
17+
runs-on: ${{ matrix.os }}
18+
19+
strategy:
20+
fail-fast: false
21+
matrix:
22+
include:
23+
# ── Linux / GCC 14 ──
24+
- os: ubuntu-24.04
25+
compiler: gcc-14
26+
preset: dev-gcc
27+
28+
# ── Linux / Clang 18 ──
29+
- os: ubuntu-24.04
30+
compiler: clang-18+libc++
31+
preset: dev-clang-libcxx
32+
33+
# ── macOS 15 / AppleClang 16 ──
34+
- os: macos-15
35+
compiler: apple-clang-16
36+
preset: dev-clang
37+
38+
# ── Windows 2022 / MSVC ──
39+
- os: windows-2022
40+
compiler: msvc
41+
preset: dev-msvc
42+
43+
steps:
44+
- uses: actions/checkout@v5
45+
46+
- name: Set up MSVC environment
47+
if: matrix.compiler == 'msvc'
48+
shell: pwsh
49+
run: |
50+
$vcvars = "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvars64.bat"
51+
cmd /c "`"$vcvars`" && set" | ForEach-Object {
52+
if ($_ -match '^([^=]+)=(.*)$') {
53+
"$($Matches[1])=$($Matches[2])" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
54+
}
55+
}
56+
57+
- name: Install libc++
58+
if: matrix.compiler == 'clang-18+libc++'
59+
run: sudo apt-get install -y libc++-18-dev libc++abi-18-dev
60+
61+
- name: Install Ninja
62+
if: runner.os == 'Linux'
63+
run: sudo apt-get install -y ninja-build
64+
65+
- name: Check CMake Version
66+
run: cmake --version
67+
68+
- name: Configure
69+
run: cmake --preset ${{ matrix.preset }} -B build/${{ matrix.preset }}
70+
71+
- name: Build (Debug)
72+
run: cmake --build build/${{ matrix.preset }} --config Debug
73+
74+
- name: Build (Release)
75+
run: cmake --build build/${{ matrix.preset }} --config Release

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ build/
66
CMakeUserPresets.json
77

88
# Editors
9-
.vs/
109
.vscode/
1110
.idea/
1211
*.user

CMakeLists.txt

Lines changed: 67 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -5,61 +5,93 @@
55
# Distributed under the Boost Software License, Version 1.0. (See accompanying
66
# file LICENSE.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
77

8-
cmake_minimum_required(VERSION 3.23)
8+
cmake_minimum_required(VERSION 3.24)
9+
project(
10+
Eggs.Assert
11+
DESCRIPTION "A C++23 assert library with stacktrace"
12+
LANGUAGES C CXX
13+
)
914

10-
project(Eggs.Assert C CXX)
15+
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
1116

17+
include(GNUInstallDirs)
18+
19+
# Options (two spellings: short when top-level, prefixed when a subdirectory)
1220
if(PROJECT_IS_TOP_LEVEL)
13-
option(BUILD_EXAMPLE "Build the example" ON)
14-
option(ENABLE_INSTALL "Enable installing the library" ON)
21+
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
22+
set(CMAKE_CXX_SCAN_FOR_MODULES OFF)
1523

16-
set(CMAKE_CXX_STANDARD 23)
17-
set(CMAKE_CXX_STANDARD_REQUIRED ON)
18-
set(CMAKE_CXX_EXTENSIONS OFF)
24+
option(BUILD_EXAMPLE "Build the example" ON)
25+
option(ENABLE_INSTALL "Generate install rules" ON)
1926
else()
2027
option(EGGS_ASSERT_BUILD_EXAMPLE "Build the example" OFF)
21-
option(EGGS_ASSERT_ENABLE_INSTALL "Enable installing the library" OFF)
28+
option(EGGS_ASSERT_ENABLE_INSTALL "Generate install rules" OFF)
2229

30+
# Map prefixed options back to the canonical names used below
2331
set(BUILD_EXAMPLE ${EGGS_ASSERT_BUILD_EXAMPLE})
2432
set(ENABLE_INSTALL ${EGGS_ASSERT_ENABLE_INSTALL})
2533
endif()
2634

27-
# Build
28-
29-
add_library(_eggs_assert STATIC
30-
src/assert.cpp)
31-
32-
# <stacktrace> requires linking against stdc++exp on GCC
33-
target_link_libraries(_eggs_assert PUBLIC
34-
$<$<CXX_COMPILER_ID:GNU>:stdc++exp>)
35-
36-
target_sources(_eggs_assert PUBLIC
37-
FILE_SET HEADERS
38-
BASE_DIRS include
39-
FILES include/eggs/assert.h)
35+
#
36+
# Library target — static library.
37+
# Internal name _eggs_assert; downstream CMake code uses the alias Eggs::Assert.
38+
#
39+
add_library(_eggs_assert STATIC src/assert.cpp)
40+
target_sources(
41+
_eggs_assert
42+
PUBLIC FILE_SET HEADERS BASE_DIRS include FILES include/eggs/assert.h
43+
)
44+
set_target_properties(_eggs_assert PROPERTIES EXPORT_NAME Assert)
45+
target_compile_features(_eggs_assert PUBLIC cxx_std_23)
4046

41-
set_target_properties(_eggs_assert
42-
PROPERTIES
43-
CXX_SCAN_FOR_MODULES OFF
44-
EXPORT_NAME Eggs::Assert)
47+
include(Cxx23Stacktrace)
48+
target_link_libraries(_eggs_assert PUBLIC ${EGGS_CXX23_STACKTRACE_LIB})
4549

4650
add_library(Eggs::Assert ALIAS _eggs_assert)
4751

52+
#
4853
# Example
49-
54+
#
5055
if(BUILD_EXAMPLE)
5156
add_subdirectory(example)
5257
endif()
5358

54-
# Install
55-
56-
include(GNUInstallDirs)
57-
59+
#
60+
# Install rules
61+
#
5862
if(ENABLE_INSTALL)
59-
install(TARGETS _eggs_assert EXPORT _targets
60-
FILE_SET HEADERS)
61-
62-
install(EXPORT _targets
63+
include(CMakePackageConfigHelpers)
64+
65+
install(
66+
TARGETS _eggs_assert
67+
EXPORT EggsAssertTargets
68+
FILE_SET HEADERS DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
69+
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
70+
)
71+
72+
install(
73+
EXPORT EggsAssertTargets
74+
NAMESPACE Eggs::
75+
FILE eggs.assert-targets.cmake
76+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/eggs.assert
77+
)
78+
79+
configure_package_config_file(
80+
cmake/eggs.assert-config.cmake.in
81+
${CMAKE_CURRENT_BINARY_DIR}/eggs.assert-config.cmake
82+
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/eggs.assert
83+
)
84+
85+
write_basic_package_version_file(
86+
${CMAKE_CURRENT_BINARY_DIR}/eggs.assert-config-version.cmake
87+
VERSION 1.0.0
88+
COMPATIBILITY SameMajorVersion
89+
)
90+
91+
install(
92+
FILES
93+
${CMAKE_CURRENT_BINARY_DIR}/eggs.assert-config.cmake
94+
${CMAKE_CURRENT_BINARY_DIR}/eggs.assert-config-version.cmake
6395
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/eggs.assert
64-
FILE eggs.assert-config.cmake)
96+
)
6597
endif()

0 commit comments

Comments
 (0)