Skip to content

Commit fa5acc5

Browse files
31chtumaisch
authored andcommitted
Add initial example project
1 parent 221d2e5 commit fa5acc5

29 files changed

+3972
-20
lines changed

.clang-format

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

.clang-tidy

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
Checks: 'clang-analyzer-*,cppcoreguidelines-*,modernize-*,performance-*,portability-*,readability-*'

.devcontainer/Dockerfile

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
# https://github.com/devcontainers/images/tree/main/src/cpp
22
FROM mcr.microsoft.com/devcontainers/cpp:1-debian-12
33

4-
# [Optional] Uncomment this section to install additional packages.
5-
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
6-
# && apt-get -y install --no-install-recommends \
7-
# <your-package-list-here> \
8-
# && apt-get autoremove -y && apt-get clean -y && rm -rf /var/lib/apt/lists/*
4+
# Install additional packages
5+
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
6+
&& apt-get -y install --no-install-recommends \
7+
clang-format \
8+
clang-tidy \
9+
doxygen \
10+
gcovr \
11+
graphviz \
12+
iwyu \
13+
&& apt-get autoremove -y && apt-get clean -y && rm -rf /var/lib/apt/lists/*
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Build and publish Docker image
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- ".devcontainer/Dockerfile"
9+
pull_request:
10+
branches:
11+
- main
12+
paths:
13+
- ".devcontainer/Dockerfile"
14+
workflow_dispatch:
15+
16+
jobs:
17+
build-and-publish:
18+
runs-on: ubuntu-latest
19+
20+
steps:
21+
- name: Checkout
22+
uses: actions/checkout@v4
23+
24+
- name: Set up QEMU
25+
uses: docker/setup-qemu-action@v3
26+
27+
- name: Set up Docker Buildx
28+
uses: docker/setup-buildx-action@v3
29+
30+
- name: Log in to GitHub Container Registry
31+
uses: docker/login-action@v3
32+
with:
33+
registry: ghcr.io
34+
username: ${{ github.actor }}
35+
password: ${{ secrets.GITHUB_TOKEN }}
36+
37+
- name: Build and push Docker image
38+
uses: docker/build-push-action@v6
39+
with:
40+
context: .
41+
file: .devcontainer/Dockerfile
42+
push: true
43+
tags: ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}:latest
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
name: Build and test the project
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths-ignore:
8+
- ".devcontainer/Dockerfile"
9+
pull_request:
10+
branches:
11+
- main
12+
paths-ignore:
13+
- ".devcontainer/Dockerfile"
14+
workflow_dispatch:
15+
16+
# IMPORTANT: make sure to use the 'runner user'when running jobs in a container!
17+
# Otherwise there will be 'dubious ownership' issues reported by Git.
18+
# Therefore, make sure to use the '--user 1001' option for the container.
19+
jobs:
20+
build-doc:
21+
runs-on: ubuntu-latest
22+
container:
23+
image: ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}:latest
24+
options: --user 1001
25+
steps:
26+
- name: Checkout code
27+
uses: actions/checkout@v4
28+
- name: Build documentation
29+
run: ./tools/build-docs.sh
30+
- name: Upload documentation
31+
uses: actions/upload-artifact@v4
32+
with:
33+
name: documentation
34+
path: "build/html"
35+
retention-days: 1
36+
37+
build-app:
38+
runs-on: ubuntu-latest
39+
container:
40+
image: ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}:latest
41+
options: --user 1001
42+
strategy:
43+
matrix:
44+
compiler: [gcc, clang]
45+
steps:
46+
- name: Checkout code
47+
uses: actions/checkout@v4
48+
with:
49+
submodules: "true"
50+
- name: Run clang-format
51+
run: ./tools/clang-format.sh
52+
- name: Build application
53+
run: |
54+
export ENABLE_IWYU=1
55+
export ENABLE_LWYU=1
56+
export ENABLE_CLANG_TIDY=1
57+
export ENABLE_CPPCHECK=1
58+
./tools/build-cmake-target.sh ${{ matrix.compiler }}-release cplusplus_training_project
59+
- name: Upload application
60+
uses: actions/upload-artifact@v4
61+
with:
62+
name: application-${{ matrix.compiler }}
63+
path: "build/${{ matrix.compiler }}-release/bin/cplusplus_training_project"
64+
retention-days: 1
65+
66+
test-app:
67+
runs-on: ubuntu-latest
68+
container:
69+
image: ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}:latest
70+
options: --user 1001
71+
strategy:
72+
matrix:
73+
compiler: [gcc, clang]
74+
steps:
75+
- name: Checkout code
76+
uses: actions/checkout@v4
77+
with:
78+
submodules: "true"
79+
- name: Build tests
80+
run: ./tools/build-cmake-target.sh ${{ matrix.compiler }}-coverage calculate_test
81+
- name: Run tests
82+
run: ./tools/run-test.sh build/${{ matrix.compiler }}-coverage/bin/calculate_test build/${{ matrix.compiler }}
83+
- name: Upload test results
84+
uses: actions/upload-artifact@v4
85+
with:
86+
name: test-results-${{ matrix.compiler }}
87+
path: "build/${{ matrix.compiler }}/*.xml"
88+
retention-days: 1

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.vscode/
2+
build/

.gitlab-ci.yml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
---
2+
default:
3+
image: mcr.microsoft.com/devcontainers/cpp:1-debian-12
4+
5+
stages:
6+
- build
7+
- test
8+
- deploy
9+
10+
include:
11+
- template: Jobs/Code-Quality.gitlab-ci.yml
12+
- component: $CI_SERVER_FQDN/devminds-ch/gitlab-component-clang-format/gitlab-component-clang-format@main
13+
14+
build-project:
15+
stage: build
16+
before_script:
17+
- git submodule update --init --recursive
18+
script:
19+
- ./tools/build-cmake-target.sh gcc-release cplusplus_training_project
20+
artifacts:
21+
paths:
22+
- build/bin
23+
expire_in: 1 week
24+
25+
build-unit-tests:
26+
stage: build
27+
before_script:
28+
- git submodule update --init --recursive
29+
script:
30+
- ./tools/build-cmake-target.sh gcc-coverage calculate_test
31+
artifacts:
32+
paths:
33+
- build/
34+
expire_in: 1 week
35+
36+
build-documentation:
37+
stage: build
38+
before_script:
39+
- git submodule update --init --recursive
40+
- apt update && apt install -y doxygen
41+
script:
42+
- ./tools/build-docs.sh
43+
artifacts:
44+
paths:
45+
- build/html/
46+
expire_in: 1 week
47+
48+
code_quality:
49+
when: manual
50+
51+
run-unit-tests:
52+
stage: test
53+
before_script:
54+
- apt update && apt install -y gcovr
55+
script:
56+
- ./tools/run-test.sh build/gcc-coverage/bin/calculate_test build/gcc
57+
coverage: /^\s*lines:\s*\d+.\d+\%/
58+
artifacts:
59+
expire_in: 1 week
60+
reports:
61+
junit: build/gcc/test-report.xml
62+
coverage_report:
63+
coverage_format: cobertura
64+
path: build/gcc/test-coverage.xml
65+
66+
pages:
67+
stage: deploy
68+
script:
69+
- mv build/html/ public/
70+
environment:
71+
name: "Pages production"
72+
url: "${CI_PAGES_URL}"
73+
artifacts:
74+
paths:
75+
- public/

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "external/CLI11"]
2+
path = external/CLI11
3+
url = https://github.com/CLIUtils/CLI11.git

CMakeLists.txt

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
cmake_minimum_required(VERSION 3.14)
2+
3+
# Add custom CMake files
4+
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake)
5+
include(GitProjectVersion)
6+
7+
project(cplusplus_training_project)
8+
9+
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
10+
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
11+
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
12+
13+
# GoogleTest requires at least C++14
14+
set(CMAKE_CXX_STANDARD 14)
15+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
16+
17+
# Enable include-what-you-use (IWYU) if available
18+
find_program(IWYU_PATH NAMES include-what-you-use)
19+
if (IWYU_PATH AND DEFINED ENV{ENABLE_IWYU})
20+
message(STATUS "Enabling: include-what-you-use")
21+
set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE "${IWYU_PATH}")
22+
endif()
23+
24+
if(DEFINED ENV{ENABLE_LWYU})
25+
# Enable link-what-you-use (LWYU)
26+
message(STATUS "Enabling: link-what-you-use")
27+
set(CMAKE_LINK_WHAT_YOU_USE TRUE)
28+
endif()
29+
30+
# Enable cppcheck if available
31+
find_program(CPPCHECK_PATH NAMES cppcheck)
32+
if (CPPCHECK_PATH AND DEFINED ENV{ENABLE_CPPCHECK})
33+
message(STATUS "Enabling: cppcheck")
34+
set(CMAKE_CXX_CPPCHECK "${CPPCHECK_PATH}")
35+
endif()
36+
37+
# Enable clang-tidy if available
38+
find_program(CLANG_TIDY_PATH NAMES clang-tidy)
39+
if (CLANG_TIDY_PATH AND DEFINED ENV{ENABLE_CLANG_TIDY})
40+
message(STATUS "Enabling: clang-tidy")
41+
set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY_PATH}")
42+
endif()
43+
44+
# Enable code coverage for GCC and Clang if PROFILE build type is selected
45+
if(CMAKE_BUILD_TYPE STREQUAL "PROFILE")
46+
if((CMAKE_CXX_COMPILER_ID STREQUAL "GNU") OR (CMAKE_CXX_COMPILER_ID STREQUAL "Clang"))
47+
message(STATUS "Enabling code coverage")
48+
set(CMAKE_CXX_FLAGS_PROFILE --coverage)
49+
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
50+
set(GCOV_LINK gcov)
51+
endif()
52+
endif()
53+
endif()
54+
55+
add_subdirectory(external/CLI11)
56+
add_subdirectory(src)
57+
58+
# Enable testing
59+
enable_testing()
60+
add_subdirectory(tests)

0 commit comments

Comments
 (0)