Skip to content

Commit 2139ee2

Browse files
committed
initial commit
0 parents  commit 2139ee2

32 files changed

Lines changed: 9802 additions & 0 deletions

.clang-format

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Language: Cpp
2+
BasedOnStyle: Google
3+
AccessModifierOffset: -4
4+
Standard: c++20
5+
IndentWidth: 4
6+
TabWidth: 4
7+
UseTab: Never
8+
ColumnLimit: 120
9+
AlignAfterOpenBracket: Align
10+
BinPackParameters: false
11+
AlignEscapedNewlines: Left
12+
AlwaysBreakTemplateDeclarations: Yes
13+
PackConstructorInitializers: Never
14+
BreakConstructorInitializersBeforeComma: false
15+
IndentPPDirectives: BeforeHash
16+
SortIncludes: Never

.clangd

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
CompileFlags:
2+
CompilationDatabase: build
3+
Add:
4+
- -Wno-unknown-warning-option
5+
- -std=gnu++23
6+
- -Iinclude
7+
Remove: [-m*, -f*]
8+
Compiler: /usr/bin/gcc-14
9+
10+
Index:
11+
Background: Build
12+
StandardLibrary: true
13+
14+
Hover:
15+
ShowAKA: false
16+
17+
Completion:
18+
AllScopes: Yes
19+
20+
InlayHints:
21+
BlockEnd: false
22+
Designators: false
23+
Enabled: true
24+
ParameterNames: false
25+
DeducedTypes: false
26+
TypeNameLimit: 24
27+
28+
Diagnostics:
29+
UnusedIncludes: Strict
30+
ClangTidy:
31+
FastCheckFilter: Strict
32+
Add:
33+
- modernize-*
34+
- performance-*
35+
- bugprone-use-after-move
36+
Remove:
37+
- modernize-use-nodiscard
38+
- modernize-avoid-c-arrays

.github/linux.yaml

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
name: linux
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
linux:
7+
strategy:
8+
fail-fast: false
9+
matrix:
10+
include:
11+
- compiler: llvm
12+
compiler-version: 16
13+
cxx: 20
14+
- compiler: llvm
15+
compiler-version: 17
16+
cxx: 20
17+
- compiler: llvm
18+
compiler-version: 18
19+
cxx: 23
20+
- compiler: gcc
21+
compiler-version: 13
22+
cxx: 20
23+
- compiler: gcc
24+
compiler-version: 14
25+
cxx: 23
26+
name: "${{ github.job }} (C++${{ matrix.cxx }}-${{ matrix.compiler }}-${{ matrix.compiler-version }})"
27+
runs-on: ubuntu-latest
28+
steps:
29+
- name: Checkout
30+
uses: actions/checkout@v4
31+
with:
32+
submodules: recursive
33+
fetch-depth: 0
34+
- name: Export GitHub Actions cache environment variables
35+
uses: actions/github-script@v7
36+
with:
37+
script: |
38+
core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || '');
39+
core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || '');
40+
- name: Setup ccache
41+
uses: hendrikmuhs/ccache-action@v1
42+
with:
43+
key: "${{ github.job }}-${{ matrix.compiler }}-${{ matrix.compiler-version }}"
44+
max-size: "2G"
45+
- name: Compile
46+
run: |
47+
if [[ "${{ matrix.compiler }}" == "llvm" ]]; then
48+
export CC=clang-${{ matrix.compiler-version }}
49+
export CXX=clang++-${{ matrix.compiler-version }}
50+
elif [[ "${{ matrix.compiler }}" == "gcc" ]]; then
51+
export CC=gcc-${{ matrix.compiler-version }}
52+
export CXX=g++-${{ matrix.compiler-version }}
53+
fi
54+
sudo ln -s $(which ccache) /usr/local/bin/$CC
55+
sudo ln -s $(which ccache) /usr/local/bin/$CXX
56+
$CXX --version
57+
cmake -B build -G Ninja -DCMAKE_CXX_STANDARD=${{ matrix.cxx }} -DORYX_CRT_BUILD_TESTS=ON -DCMAKE_BUILD_TYPE=Release
58+
cmake --build build
59+
- name: Run tests
60+
run: |
61+
./build/chron-cpp_tests --success
62+
linux-valgrind:
63+
name: "Valgrind leak checks"
64+
runs-on: ubuntu-latest
65+
steps:
66+
- name: Setup
67+
run: |
68+
sudo apt-get update
69+
sudo apt-get install -y valgrind
70+
71+
- name: Checkout
72+
uses: actions/checkout@v4
73+
with:
74+
submodules: recursive
75+
fetch-depth: 0
76+
- name: Export GitHub Actions cache environment variables
77+
uses: actions/github-script@v7
78+
with:
79+
script: |
80+
core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || '');
81+
core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || '');
82+
- name: Setup ccache
83+
uses: hendrikmuhs/ccache-action@v1
84+
with:
85+
key: "${{ github.job }}-valgrind-checks"
86+
max-size: "2G"
87+
- name: Compile
88+
run: |
89+
cmake -B build -G Ninja -DORYX_CRT_BUILD_TESTS=ON -DCMAKE_BUILD_TYPE=Release
90+
cmake --build build
91+
- name: Run tests
92+
run: |
93+
valgrind --leak-check=full --error-exitcode=1 ./build/chron-cpp_tests

.github/windows.yaml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: windows
2+
3+
on: [ push, pull_request ]
4+
5+
env:
6+
VCPKG_BINARY_SOURCES: "clear;x-gha,readwrite"
7+
8+
jobs:
9+
windows-msvc:
10+
runs-on: windows-latest
11+
steps:
12+
- name: Checkout
13+
uses: actions/checkout@v4
14+
with:
15+
submodules: recursive
16+
fetch-depth: 0
17+
- name: Export GitHub Actions cache environment variables
18+
uses: actions/github-script@v7
19+
with:
20+
script: |
21+
core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || '');
22+
core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || '');
23+
- uses: ilammy/msvc-dev-cmd@v1
24+
- name: Compile
25+
run: |
26+
cmake -B build -DORYX_CRT_BUILD_TESTS=ON -DCMAKE_CXX_STANDARD=20 -DCMAKE_BUILD_TYPE=Release
27+
cmake --build build
28+
- name: Run tests
29+
run: |
30+
.\build\Debug\chron-cpp_tests --success

.gitignore

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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

.vscode/c_cpp_properties.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"configurations": [
3+
{
4+
"name": "Linux",
5+
"includePath": [
6+
"include"
7+
],
8+
"defines": [],
9+
"cppStandard": "gnu++23",
10+
"compilerPath": "/usr/bin/g++-14",
11+
"intelliSenseMode": "${default}"
12+
}
13+
],
14+
"version": 4
15+
}

.vscode/settings.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"editor.formatOnSave": true,
3+
"cmake.configureOnOpen": false,
4+
"cmake.configureOnEdit": false,
5+
"clangd.path": "/usr/bin/clangd",
6+
"C_Cpp.clang_format_path": "/usr/bin/clang-format-18",
7+
"files.associations": {
8+
"*.hpp": "cpp",
9+
"*.cpp": "cpp",
10+
},
11+
}

CMakeLists.txt

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
cmake_minimum_required(VERSION 3.24)
2+
3+
project(chron-cpp VERSION 0.1.0 LANGUAGES CXX)
4+
5+
message(STATUS "Build ${PROJECT_NAME}: ${PROJECT_VERSION}")
6+
7+
include(cmake/utils.cmake)
8+
9+
option(ORYX_CHRON_BUILD_SHARED_LIBS "Build shared library" ${BUILD_SHARED_LIBS})
10+
option(ORYX_CHRON_BUILD_TESTS "Build tests" OFF)
11+
option(ORYX_CHRON_INSTALL "Install the project" OFF)
12+
option(ORYX_CHRON_SANITIZE_ADDRESS "Enable address sanitizer in tests" OFF)
13+
option(ORYX_CHRON_SANITIZE_THREAD "Enable thread sanitizer in tests" OFF)
14+
15+
if(ORYX_SANITIZE_ADDRESS AND ORYX_SANITIZE_THREAD)
16+
message(FATAL_ERROR "ORYX_SANITIZE_ADDRESS and ORYX_SANITIZE_THREAD are mutually exclusive")
17+
endif()
18+
19+
if (PROJECT_IS_TOP_LEVEL)
20+
set(ORYX_CHRON_INSTALL ON)
21+
endif()
22+
23+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
24+
if(NOT DEFINED CMAKE_CXX_STANDARD)
25+
set(CMAKE_CXX_STANDARD 23)
26+
endif()
27+
28+
if (ORYX_CHRON_BUILD_SHARED_LIBS)
29+
add_library(${PROJECT_NAME} SHARED)
30+
set_target_properties(${PROJECT_NAME} PROPERTIES SOVERSION ${PROJECT_VERSION})
31+
else()
32+
add_library(${PROJECT_NAME} STATIC)
33+
endif()
34+
35+
add_library("oryx::${PROJECT_NAME}" ALIAS ${PROJECT_NAME})
36+
37+
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
38+
target_compile_options(${PROJECT_NAME}
39+
PRIVATE
40+
/W4
41+
)
42+
else()
43+
target_compile_options(${PROJECT_NAME}
44+
PRIVATE
45+
-Wall
46+
-Wextra
47+
-Werror
48+
-Wuninitialized
49+
-Wno-unused-function
50+
-Wunused-variable
51+
)
52+
endif()
53+
54+
target_include_directories(${PROJECT_NAME}
55+
PUBLIC
56+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
57+
$<INSTALL_INTERFACE:include>
58+
)
59+
60+
file(GLOB_RECURSE ORYX_CHRON_HEADERS
61+
RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
62+
"${CMAKE_CURRENT_SOURCE_DIR}/include/*"
63+
)
64+
65+
target_sources(${PROJECT_NAME}
66+
PRIVATE
67+
src/cron_clock.cpp
68+
src/cron_data.cpp
69+
src/cron_randomization.cpp
70+
src/cron_schedule.cpp
71+
src/task.cpp
72+
PUBLIC
73+
FILE_SET HEADERS
74+
BASE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/include"
75+
FILES ${ORYX_CHRON_HEADERS}
76+
)
77+
78+
if(ORYX_CHRON_SANITIZE_ADDRESS)
79+
oryx_enable_addr_sanitizer(${PROJECT_NAME})
80+
elseif(ORYX_CHRON_SANITIZE_THREAD)
81+
oryx_enable_thread_sanitizer(${PROJECT_NAME})
82+
endif()
83+
84+
85+
if(ORYX_CHRON_BUILD_TESTS)
86+
file(GLOB_RECURSE TEST_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/tests/*.cpp")
87+
set(test_exe ${PROJECT_NAME}_tests)
88+
add_executable(${test_exe} ${TEST_SOURCES})
89+
target_link_libraries(${test_exe} PRIVATE ${PROJECT_NAME})
90+
91+
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
92+
target_compile_definitions(${test_exe} PUBLIC DOCTEST_CONFIG_USE_STD_HEADERS)
93+
endif()
94+
endif()
95+
96+
if (ORYX_CHRON_INSTALL)
97+
include(GNUInstallDirs)
98+
include(CMakePackageConfigHelpers)
99+
100+
configure_package_config_file(
101+
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/${PROJECT_NAME}-config.cmake.in"
102+
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake"
103+
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
104+
)
105+
106+
write_basic_package_version_file(
107+
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-version.cmake"
108+
COMPATIBILITY ExactVersion
109+
)
110+
111+
install(
112+
TARGETS ${PROJECT_NAME}
113+
EXPORT ${PROJECT_NAME}-targets
114+
FILE_SET HEADERS
115+
)
116+
117+
install(
118+
FILES
119+
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake"
120+
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-version.cmake"
121+
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
122+
COMPONENT ${PROJECT_NAME}
123+
)
124+
125+
install(
126+
EXPORT ${PROJECT_NAME}-targets
127+
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
128+
NAMESPACE oryx::
129+
FILE ${PROJECT_NAME}-targets.cmake
130+
COMPONENT ${PROJECT_NAME}
131+
)
132+
endif ()

0 commit comments

Comments
 (0)