Skip to content

Commit 29f7312

Browse files
committed
making it a generic template
1 parent 44b80d2 commit 29f7312

9 files changed

Lines changed: 137 additions & 91 deletions

File tree

.github/workflows/ci-cd.yml

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
on:
2+
push:
3+
4+
env:
5+
CLANG_VERSION: "20.1.8"
6+
MSVC_VERSION: "19.44.35214"
7+
VERBOSE: 1
8+
9+
jobs:
10+
CI:
11+
runs-on: ${{ matrix.os }}
12+
13+
strategy:
14+
# Set fail-fast to false to ensure that feedback is delivered for all matrix combinations. Consider changing this to true when your workflow is stable.
15+
fail-fast: false
16+
matrix:
17+
os:
18+
- ubuntu-latest
19+
- windows-latest
20+
build_type:
21+
- Release
22+
compiler:
23+
- clang
24+
- msvc
25+
generator:
26+
- "Ninja"
27+
exclude:
28+
- os: ubuntu-latest
29+
compiler: msvc
30+
31+
steps:
32+
- name: Setup Cpp
33+
uses: aminya/setup-cpp@v1
34+
with:
35+
compiler: ${{matrix.compiler}}
36+
conan: true
37+
cmake: true
38+
ninja: true
39+
vcvarsall: false
40+
clangtidy: true
41+
cppcheck: true
42+
ccache: false
43+
44+
- name: Download linux system dependencies
45+
if: matrix.os == 'ubuntu-latest'
46+
run: sudo apt-get update && sudo apt-get install -y libgl-dev libgl1-mesa-dev libglu1-mesa-dev
47+
48+
- name: Checkout
49+
uses: actions/checkout@v3
50+
51+
- name: Set env profile
52+
shell: bash
53+
run: |
54+
os="${{ matrix.os}}"
55+
system="${os%%-*}"
56+
[[ "$system" == "ubuntu" ]] && system="linux"
57+
echo "PROFILE=profiles/${system}-${{ matrix.compiler }}" >> "$GITHUB_ENV"
58+
59+
- name: Install
60+
run: conan install . -pr:a=${{env.PROFILE}} -s build_type=${{ matrix.build_type }} --build=missing
61+
62+
- name: Build
63+
run: conan build . -pr:a=${{env.PROFILE}} -s build_type=${{ matrix.build_type }} --build=missing
64+
65+
- name: Set env preset and build folder
66+
shell: bash
67+
run: echo "PRESET=$(cmake --list-presets | tail -n 1 | awk '{print $1}' | tr -d '"')" >> "$GITHUB_ENV"
68+
69+
- name: Test
70+
run: ctest --preset ${{env.PRESET}}
71+
72+
- name: Package
73+
run: cpack --preset ${{env.PRESET}} -B ${{ github.workspace }}/packages
74+
75+
- name: Upload Artifact
76+
uses: actions/upload-artifact@v4.6.2
77+
with:
78+
name: ${{matrix.os}}-${{matrix.compiler}}
79+
path: ./packages/*.*
80+
if-no-files-found: error
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
- name: Configure Git
2+
run: |
3+
git config user.name "github-actions"
4+
git config user.email "github-actions@github.com"
5+
6+
- name: Replace project name placeholder
7+
run: |
8+
# This command finds all files in the repository and uses 'sed' to replace
9+
# the placeholder '{{PROJECT_NAME}}' with the name provided in the workflow input.
10+
# The sed delimiter is changed from '/' to '|' to safely handle path names.
11+
find . -type f -not -path './.git/*' -exec sed -i "s|{{PROJECT_NAME}}|${{ github.event.inputs.new_project_name }}|g" {} +
12+
13+
- name: Create a pull request with the new name
14+
uses: peter-evans/create-pull-request@v6
15+
with:
16+
title: 'Update project name to "${{ github.event.inputs.new_project_name }}"'
17+
commit-message: 'feat: Update project name to ${{ github.event.inputs.new_project_name }}'
18+
body: |
19+
This pull request automatically updates all instances of the project name
20+
placeholder (`{{PROJECT_NAME}}`) with the new name you specified.
21+
branch: update-project-name-${{ github.run_number }}
22+
token: ${{ secrets.GITHUB_TOKEN }}

BUILDING.md

Lines changed: 14 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Building and Running the Project (Conan 2.x with CMake Presets)
22

3-
This document provides instructions for building and running the project using **Conan 2.x** and **CMake Presets**. This approach simplifies the build process by defining all build configurations in a single `CMakePresets.json` file.
3+
This document provides instructions for building and running the project using **Conan 2.x** and **CMake Presets**. This approach simplifies the build process.
44

55
### Prerequisites
66

@@ -19,81 +19,47 @@ choco install conan cmake ninja llvm
1919

2020
* **Linux**:
2121
```bash
22-
sudo apt install conan cmake ninja-build clang clang-format clang-tidy libglu1-mesa-dev freeglut3-dev
22+
sudo apt install conan cmake ninja-build clang clang-format clang-tidy
2323
```
2424

2525
### Step-by-Step Instructions
26-
TODO: There are also scripts that run generation phase accordingly for Windows system `configure.cmd` script and for Linux `configure.sh`.
26+
There are also scripts that run generation phase accordingly for Windows system `configure.cmd` and for Linux `configure.sh`.
2727

2828
#### 1. Generate the Conan Toolchain and Dependencies
29-
This step uses Conan to download all project dependencies and generate the conan_toolchain.cmake file that CMake needs.
29+
This step uses Conan to download all project dependencies and generate the conan_toolchain.cmake file that CMake needs. This is an example, parameters like profile used or build type can be changed.
3030

3131
* **Windows**:
3232
```batch
33-
conan install . --output-folder=build/windows-clang-release --build=missing -pr:h=profiles/windows-clang -pr:b=profiles/windows-clang
33+
conan install . -pr:a=profiles/windows-clang -s build_type=Release --build=missing
3434
```
3535

3636
* **Linux**:
3737
```bash
38-
conan install . --output-folder=build/linux-clang-release --build=missing -pr:h=profiles/linux-clang -pr:b=profiles/linux-clang
38+
conan install . -pr:a=profiles/linux-clang -s build_type=Release --build=missing
3939
```
4040

41-
This command will create the build directory and populate it with Conan's toolchain file and other necessary configuration.
41+
This command will create the build directory and populate it with Conan's toolchain file and other necessary configuration. Also `CMakeUserPresets.json` and `compile_commands.json` files will be generated.
4242

43-
#### 2. Configure the Project
43+
#### 2. Build the Project
4444

45-
The `cmake --preset` command will automatically resolve and install all project dependencies using Conan. It will create a build directory and generate the necessary files for building.
45+
Once the project is configured, you can build it using the same profile. This is an example, parameters like profile used or build type can be changed.
4646

4747
* **Windows**:
48-
```batch
49-
cmake --preset windows-clang-release
5048
```
51-
52-
* **Linux**:
53-
```bash
54-
cmake --preset linux-clang-release
49+
conan build . -pr:a=%PROFILE% -s build_type=Release --build=missing
5550
```
5651

57-
After this command, a new directory, `build/linux-clang-release` or `build/windows-clang-release`, will be created containing the build configuration.
58-
59-
#### 2. Build the Project
60-
61-
Once the project is configured, you can build it using the same preset name.
62-
6352
* **Linux**:
6453
```
65-
cmake --build --preset linux-clang-release
66-
```
67-
68-
* **Windows**:
69-
```
70-
cmake --build --preset windows-clang-release
54+
conan build . -pr:a=%PROFILE% -s build_type=Release --build=missing
7155
```
7256

7357
This will compile your source code and produce the final executable.
7458

7559
#### 3. Run the Executable
7660

77-
The executable is located inside the build directory. The exact name of the executable will depend on your `CMakeLists.txt` configuration.
61+
The executable is located inside the build directory. The exact path to the executable will depend on choosen profile and build type.
7862

79-
* **Linux**:
80-
```
81-
./build/linux-clang-release/your_executable_name
82-
```
83-
84-
* **Windows**:
85-
```
86-
`./build/windows-clang-release/your_executable_name.exe
8763
```
88-
89-
### How It Works
90-
91-
The `cmake --preset` command is the key to this workflow. It tells CMake to:
92-
93-
1. Read the configuration specified in the `CMakePresets.json` file.
94-
95-
2. Automatically invoke Conan to download all the dependencies defined in your `conanfile.py`.
96-
97-
3. Set up the build environment with Conan's toolchain file, ensuring that the compiler, C++ standard, and other settings are correctly configured for your chosen preset.
98-
99-
This eliminates the need to run manual `conan install` and `cmake -DCMAKE_TOOLCHAIN_FILE=...` commands separately, creating a single, consistent entry point for building your project.
64+
./build/{compiler-compiler_version-arch"}/{{PROJECT_NAME}}.exe
65+
```

CMakeLists.txt

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
cmake_minimum_required(VERSION 3.23)
22

3-
project(craftgl
3+
project({{PROJECT_NAME_LOWER}}
44
VERSION 0.1.0
5-
DESCRIPTION "A simple OpenGL game project."
6-
HOMEPAGE_URL "http://example.com"
5+
DESCRIPTION "{{PROJECT_DESCRIPTION}}"
6+
HOMEPAGE_URL "{{PROJECT_HOMEPAGE_URL}}"
77
LANGUAGES CXX)
88

99
# Enable export of compile commands for tools like clang-tidy
@@ -14,13 +14,10 @@ include(cmake/StaticAnalysis.cmake)
1414
option(ENABLE_TESTS "Enable building tests" ON)
1515

1616
# --- Find required packages ---
17-
find_package(opengl_system REQUIRED)
18-
find_package(glu REQUIRED)
19-
find_package(Microsoft.GSL REQUIRED)
20-
find_package(glm REQUIRED)
17+
# find_package(glm REQUIRED)
2118

2219
# --- Create executable ---
23-
add_executable(craftgl)
20+
add_executable({{PROJECT_NAME_LOWER}})
2421

2522
# --- Subdirectories ---
2623
add_subdirectory(src)
@@ -44,13 +41,13 @@ set(CPACK_PACKAGE_VERSION "${PROJECT_VERSION}")
4441
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "${PROJECT_DESCRIPTION}")
4542
set(CPACK_PACKAGE_HOMEPAGE_URL "${PROJECT_HOMEPAGE_URL}")
4643
set(CPACK_PACKAGE_CONTACT "norbert221198@gmail.com")
47-
set(CPACK_DEBIAN_PACKAGE_DEPENDS "libgl-dev, libgl1-mesa-dev, libglu1-mesa-dev")
44+
#set(CPACK_DEBIAN_PACKAGE_DEPENDS "libgl-dev, libgl1-mesa-dev, libglu1-mesa-dev")
4845

4946
include(CPack)
5047

5148
# clangd support
5249
add_custom_command(
53-
TARGET craftgl POST_BUILD
50+
TARGET {{PROJECT_NAME_LOWER}} POST_BUILD
5451
COMMAND ${CMAKE_COMMAND} -E copy_if_different
5552
"${CMAKE_BINARY_DIR}/compile_commands.json"
5653
"${CMAKE_SOURCE_DIR}/compile_commands.json"

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# conan-cmake-cpp
2-
[![.github/workflows/ci-cd.yml](https://github.com/LigasN/CraftGL/actions/workflows/ci-cd.yml/badge.svg)](https://github.com/LigasN/CraftGL/actions/workflows/ci-cd.yml)
1+
# {{PROJECT_NAME}}
2+
[![.github/workflows/ci-cd.yml](https://github.com/{{USERNAME}}/{{PROJECT_NAME}}/actions/workflows/ci-cd.yml/badge.svg)](https://github.com/{{USERNAME}}/{{PROJECT_NAME}}/actions/workflows/ci-cd.yml)
33

44
Repository template for a cross-platform project written in C++ with use of Conan and CMake. This template has also GitHub actions configured for CI/CD with static analysis by clang-tidy and cppcheck. It has also clang-format configuration file for code formatting.

conanfile.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ def get_version(conanfile):
1616
return None
1717

1818
class CraftGLConan(ConanFile):
19-
name = "craftgl"
20-
url = "https://github.com/LigasN/CraftGL"
21-
description = "A simple OpenGL game project."
19+
name = "{{PROJECT_NAME_LOWER}}"
20+
url = "{{PROJECT_HOMEPAGE_URL}}"
21+
description = "{{PROJECT_DESCRIPTION}}"
2222
license = ""
2323
settings = "os", "compiler", "build_type", "arch"
2424

@@ -28,13 +28,8 @@ def set_version(self):
2828
def validate(self):
2929
check_min_cppstd(self, "23")
3030

31-
def requirements(self):
32-
self.requires("opengl/system")
33-
self.requires("glu/system")
34-
self.requires("glm/1.0.1")
35-
self.requires("ms-gsl/4.0.0")
36-
#self.requires("ktx/4.3.2")
37-
#self.requires("nlohmann_json")
31+
# def requirements(self):
32+
# self.requires("glm/1.0.1")
3833

3934
def build_requirements(self):
4035
self.test_requires("gtest/1.16.0")

configure.sh

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,11 @@
22

33
# === Configuration variables ===
44
PROFILE=profiles/linux-clang
5-
BUILD_TYPE=Release
6-
PRESET=linux-clang-release
7-
OUT_DIR=build/${PRESET}
85

9-
REM === Environment variables ===
10-
set ENABLE_CLANG_TIDY=ON
11-
set ENABLE_CPPCHECK=ON
6+
# === Release ===
7+
conan install . -pr:a=$PROFILE -s build_type=Release --build=missing
8+
conan build . -pr:a=$PROFILE -s build_type=Release --build=missing
129

13-
echo "Installing dependencies and generating toolchain for Linux (${BUILD_TYPE})..."
14-
conan install . --output-folder=${OUT_DIR} --build=missing --profile:all=${PROFILE} -s build_type=${BUILD_TYPE}
15-
16-
echo "Configuring the project with CMake (${BUILD_TYPE})..."
17-
cmake --preset ${PRESET}
18-
19-
echo "Building the project (${BUILD_TYPE})..."
20-
cmake --build --preset ${PRESET}
10+
# === Debug ===
11+
# conan install . -pr:a=$PROFILE -s build_type=Debug --build=missing
12+
# conan build . -pr:a=$PROFILE -s build_type=Debug --build=missing

src/engine/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ add_library(engine STATIC)
1010
target_sources(engine PRIVATE ${ENGINE_SOURCE} ${ENGINE_HEADERS})
1111
target_compile_features(engine PUBLIC cxx_std_23)
1212
target_include_directories(engine PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/..")
13-
target_link_libraries(engine PUBLIC Microsoft.GSL::GSL)
13+
#target_link_libraries(engine PUBLIC lib::lib)
1414

1515
add_library(${PROJECT_NAME}::engine ALIAS engine)

tests/CMakeLists.txt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,6 @@ function(add_test_target test_name test_sources test_libraries)
1313
target_link_libraries(${target_name} PRIVATE GTest::gtest_main ${test_libraries})
1414

1515
add_test(NAME ${test_name} COMMAND ${target_name} WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")
16-
17-
# TODO: check if needed
18-
# Set output directory for test executables (optional, but good for organization)
19-
# set_target_properties(${TARGET_NAME} PROPERTIES
20-
# RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/tests"
21-
# )
2216
endfunction()
2317

2418
add_test_target(engine "engine/Engine.cpp" "")

0 commit comments

Comments
 (0)