Skip to content

Commit 555270e

Browse files
Intial project setup
1 parent 8a20051 commit 555270e

22 files changed

+935
-0
lines changed

.clang-format

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
BasedOnStyle: Google
3+
Language: Cpp
4+
Standard: Latest

.editorconfig

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# EditorConfig: https://EditorConfig.org
2+
3+
root = true
4+
5+
[*]
6+
charset = utf-8
7+
end_of_line = lf
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true
10+
11+
# C++ files - using 2 spaces to match Google C++ style guide
12+
# To use tabs instead, change indent_style to "tab"
13+
[*.{cpp,cc,cxx,hpp,h,c}]
14+
indent_style = space
15+
indent_size = 2
16+
17+
[CMakeLists.txt,*.cmake]
18+
indent_style = space
19+
indent_size = 2
20+
21+
[*.{yml,yaml}]
22+
indent_style = space
23+
indent_size = 2
24+
25+
[*.md]
26+
trim_trailing_whitespace = false

.github/workflows/ci.yml

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ master, main ]
6+
pull_request:
7+
branches: [ master, main ]
8+
9+
jobs:
10+
build-linux:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
matrix:
14+
compiler: [gcc, clang]
15+
build_type: [Debug, Release]
16+
17+
steps:
18+
- uses: actions/checkout@v4
19+
20+
- name: Install dependencies
21+
run: |
22+
sudo apt-get update
23+
sudo apt-get install -y cmake ninja-build
24+
25+
- name: Configure CMake
26+
run: |
27+
if [ "${{ matrix.compiler }}" = "gcc" ]; then
28+
export CC=gcc CXX=g++
29+
else
30+
export CC=clang CXX=clang++
31+
fi
32+
cmake -B build -S . -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} -G Ninja
33+
34+
- name: Build
35+
run: cmake --build build --config ${{ matrix.build_type }}
36+
37+
- name: Run tests
38+
run: cd build && ctest --output-on-failure -C ${{ matrix.build_type }}
39+
40+
- name: Run benchmarks (quick)
41+
run: ./build/benchmarks/hello_world_benchmark --benchmark_min_time=0.1s
42+
43+
build-macos:
44+
runs-on: macos-latest
45+
strategy:
46+
matrix:
47+
build_type: [Debug, Release]
48+
49+
steps:
50+
- uses: actions/checkout@v4
51+
52+
- name: Install dependencies
53+
run: |
54+
brew install cmake ninja llvm
55+
56+
- name: Configure CMake with Homebrew LLVM
57+
run: |
58+
export PATH="/opt/homebrew/opt/llvm/bin:$PATH"
59+
cmake -B build -S . \
60+
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \
61+
-DCMAKE_C_COMPILER=/opt/homebrew/opt/llvm/bin/clang \
62+
-DCMAKE_CXX_COMPILER=/opt/homebrew/opt/llvm/bin/clang++ \
63+
-G Ninja
64+
65+
- name: Build
66+
run: cmake --build build --config ${{ matrix.build_type }}
67+
68+
- name: Run tests
69+
run: cd build && ctest --output-on-failure -C ${{ matrix.build_type }}
70+
71+
- name: Run benchmarks (quick)
72+
run: ./build/benchmarks/hello_world_benchmark --benchmark_min_time=0.1s
73+
74+
coverage:
75+
runs-on: ubuntu-latest
76+
steps:
77+
- uses: actions/checkout@v4
78+
79+
- name: Install dependencies
80+
run: |
81+
sudo apt-get update
82+
sudo apt-get install -y cmake ninja-build lcov
83+
84+
- name: Run coverage with threshold check
85+
run: ./scripts/coverage-ci.sh 70
86+
87+
- name: Upload coverage to Codecov
88+
uses: codecov/codecov-action@v4
89+
with:
90+
files: ./coverage/coverage.info
91+
fail_ci_if_error: false
92+
verbose: true
93+
env:
94+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

.gitignore

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Prerequisites
2+
*.d
3+
4+
# Compiled Object files
5+
*.slo
6+
*.lo
7+
*.o
8+
*.obj
9+
10+
# Precompiled Headers
11+
*.gch
12+
*.pch
13+
14+
# Linker files
15+
*.ilk
16+
17+
# Debugger Files
18+
*.pdb
19+
20+
# Compiled Dynamic libraries
21+
*.so
22+
*.dylib
23+
*.dll
24+
25+
# Fortran module files
26+
*.mod
27+
*.smod
28+
29+
# Compiled Static libraries
30+
*.lai
31+
*.la
32+
*.a
33+
*.lib
34+
35+
# Executables
36+
*.exe
37+
*.out
38+
*.app
39+
40+
# debug information files
41+
*.dwo
42+
43+
# Build files
44+
build/
45+
cmake-build-*/
46+
47+
# CMake
48+
CMakeCache.txt
49+
CMakeFiles/
50+
.cache/
51+
compile_commands.json
52+
53+
# Coverage
54+
*.gcda
55+
*.gcno
56+
*.gcov
57+
coverage/
58+
coverage.info
59+
60+
# IDE
61+
.vscode/*
62+
!.vscode/settings.json
63+
!.vscode/tasks.json
64+
!.vscode/launch.json
65+
!.vscode/extensions.json
66+
*.code-workspace
67+
.idea/
68+
*.swp
69+
*.swo
70+
*~
71+
.DS_Store
72+
73+
# Pre-commit
74+
.pre-commit-cache/

.pre-commit-config.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v6.0.0
4+
hooks:
5+
- id: trailing-whitespace
6+
- id: end-of-file-fixer
7+
- id: check-added-large-files
8+
args: ['--maxkb=1000']
9+
- id: check-yaml
10+
- id: check-merge-conflict
11+
12+
- repo: https://github.com/pre-commit/mirrors-clang-format
13+
rev: v19.1.5
14+
hooks:
15+
- id: clang-format
16+
types_or: [c++, c]
17+
args: [--style=file]
18+
19+
- repo: https://github.com/cheshirekow/cmake-format-precommit
20+
rev: v0.6.13
21+
hooks:
22+
- id: cmake-format
23+
types: [file]
24+
files: (CMakeLists\.txt|\.cmake)$
25+
args: [--in-place]

CMakeLists.txt

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
cmake_minimum_required(VERSION 3.25)
2+
project(
3+
hello_world
4+
VERSION 0.1.0
5+
LANGUAGES CXX)
6+
7+
# Set C++23 standard
8+
set(CMAKE_CXX_STANDARD 23)
9+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
10+
set(CMAKE_CXX_EXTENSIONS OFF)
11+
12+
# Only disable Apple-specific flags if using GCC on macOS
13+
if(APPLE AND CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
14+
message(STATUS "Using GCC on macOS - disabling Apple-specific flags")
15+
set(CMAKE_OSX_ARCHITECTURES "")
16+
set(CMAKE_OSX_SYSROOT "")
17+
set(CMAKE_OSX_DEPLOYMENT_TARGET "")
18+
# GCC on macOS doesn't support TSAN well, disable it
19+
set(ENABLE_TSAN
20+
OFF
21+
CACHE BOOL "TSAN not supported with GCC on macOS" FORCE)
22+
message(
23+
WARNING
24+
"Thread Sanitizer (TSAN) is not supported with GCC on macOS ARM64 - disabling"
25+
)
26+
endif()
27+
28+
# Configure Homebrew LLVM/Clang to use the correct libc++
29+
if(APPLE AND CMAKE_CXX_COMPILER_ID MATCHES "Clang")
30+
# Check if using Homebrew LLVM (path contains /opt/homebrew or /usr/local)
31+
if(CMAKE_CXX_COMPILER MATCHES "homebrew"
32+
OR CMAKE_CXX_COMPILER MATCHES "/opt/homebrew"
33+
OR CMAKE_CXX_COMPILER MATCHES "/usr/local")
34+
# Determine Homebrew prefix
35+
execute_process(
36+
COMMAND brew --prefix llvm
37+
OUTPUT_VARIABLE HOMEBREW_LLVM_PREFIX
38+
OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET)
39+
40+
if(HOMEBREW_LLVM_PREFIX)
41+
message(STATUS "Using Homebrew LLVM - configuring libc++ paths")
42+
add_link_options(-L${HOMEBREW_LLVM_PREFIX}/lib/c++)
43+
add_link_options(-Wl,-rpath,${HOMEBREW_LLVM_PREFIX}/lib/c++)
44+
endif()
45+
endif()
46+
endif()
47+
48+
# Export compile commands for IDEs
49+
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
50+
51+
# Add sanitizer options
52+
option(ENABLE_TSAN "Enable Thread Sanitizer" ON)
53+
54+
if(ENABLE_TSAN)
55+
add_compile_options(-fsanitize=thread)
56+
add_link_options(-fsanitize=thread)
57+
endif()
58+
59+
# Add coverage options
60+
option(ENABLE_COVERAGE "Enable code coverage" OFF)
61+
62+
if(ENABLE_COVERAGE)
63+
add_compile_options(--coverage)
64+
add_link_options(--coverage)
65+
endif()
66+
67+
# Include FetchContent for dependencies
68+
include(FetchContent)
69+
70+
# Fetch Google Test
71+
FetchContent_Declare(
72+
googletest
73+
GIT_REPOSITORY https://github.com/google/googletest.git
74+
GIT_TAG v1.15.2)
75+
# For Windows: Prevent overriding the parent project's compiler/linker settings
76+
set(gtest_force_shared_crt
77+
ON
78+
CACHE BOOL "" FORCE)
79+
FetchContent_MakeAvailable(googletest)
80+
81+
# Fetch Google Benchmark
82+
FetchContent_Declare(
83+
googlebenchmark
84+
GIT_REPOSITORY https://github.com/google/benchmark.git
85+
GIT_TAG v1.9.1)
86+
set(BENCHMARK_ENABLE_TESTING
87+
OFF
88+
CACHE BOOL "" FORCE)
89+
set(BENCHMARK_ENABLE_GTEST_TESTS
90+
OFF
91+
CACHE BOOL "" FORCE)
92+
set(HAVE_STD_REGEX
93+
ON
94+
CACHE BOOL "" FORCE)
95+
set(RUN_HAVE_STD_REGEX
96+
1
97+
CACHE STRING "" FORCE)
98+
FetchContent_MakeAvailable(googlebenchmark)
99+
100+
# Main library
101+
add_library(hello_world STATIC src/hello_world.cpp)
102+
target_include_directories(
103+
hello_world PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
104+
$<INSTALL_INTERFACE:include>)
105+
106+
# Main executable
107+
add_executable(hello_world_demo src/main.cpp)
108+
target_link_libraries(hello_world_demo PRIVATE hello_world)
109+
110+
# Enable testing
111+
enable_testing()
112+
113+
# Add subdirectories
114+
add_subdirectory(tests)
115+
add_subdirectory(benchmarks)

0 commit comments

Comments
 (0)