-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split release vs debug into cmake presets
--- For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/zakaria1193/my_cpp_boilerplate?shareId=XXXX-XXXX-XXXX-XXXX).
- Loading branch information
1 parent
b558b91
commit b66c4a4
Showing
5 changed files
with
96 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"version": 3, | ||
"cmakeMinimumRequired": { | ||
"major": 3, | ||
"minor": 19 | ||
}, | ||
"configurePresets": [ | ||
{ | ||
"name": "default", | ||
"hidden": false, | ||
"generator": "Ninja Multi-Config", | ||
"binaryDir": "${sourceDir}/build" | ||
} | ||
], | ||
"buildPresets": [ | ||
{ | ||
"name": "default-build", | ||
"configurePreset": "default", | ||
"verbose": true | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,35 @@ | ||
BUILD_DIR :=./build | ||
GENERATOR :='Ninja Multi-Config' | ||
.PHONY: gdb run build-release build-debug | ||
|
||
configure: | ||
cmake --fresh -B ${BUILD_DIR} -G ${GENERATOR} | ||
|
||
RELEASE ?= n | ||
ifeq (${RELEASE},y) | ||
CONFIG=Release | ||
else | ||
CONFIG=Debug | ||
endif | ||
BUILD_DIR := ./build | ||
|
||
DRY_RUN ?= n | ||
ifeq (${DRY_RUN},y) | ||
DRY_RUN_FLAG=-- -n | ||
$(info Dry run) | ||
else | ||
DRY_RUN_FLAG= | ||
endif | ||
# Set flags based on variables | ||
DRY_RUN_FLAG := $(if $(filter y,$(DRY_RUN)),-- -n) | ||
VERBOSE_FLAG := $(if $(filter y,$(VERBOSE)),--verbose) | ||
|
||
VERBOSE ?= n | ||
ifeq (${VERBOSE},y) | ||
VERBOSE_FLAG=--verbose | ||
$(info Verbose) | ||
else | ||
VERBOSE_FLAG= | ||
endif | ||
# Display settings | ||
$(info Dry run = $(DRY_RUN)) | ||
$(info Verbose = $(VERBOSE)) | ||
|
||
$(info verbose = ${VERBOSE}) | ||
|
||
build_$(CONFIG): | ||
$(info Build Config = ${CONFIG}) | ||
cmake --build ${BUILD_DIR} --config ${CONFIG} ${VERBOSE_FLAG} ${DRY_RUN_FLAG} | ||
# Configure target using a single preset | ||
configure: | ||
cmake --preset default | ||
|
||
build: build_$(CONFIG) | ||
clean: | ||
rm build -rf | ||
|
||
%: | ||
cmake --build ${BUILD_DIR} -t $@ ${VERBOSE_FLAG} ${DRY_RUN_FLAG} | ||
# Separate build targets for Debug and Release | ||
build-debug: | ||
cmake --build --preset default-build --config Debug $(VERBOSE_FLAG) $(DRY_RUN_FLAG) | ||
|
||
OUTPUT_BIN := ${BUILD_DIR}/$(CONFIG)/mockbee_test_bin | ||
build-release: | ||
cmake --build --preset default-build --config Release $(VERBOSE_FLAG) $(DRY_RUN_FLAG) | ||
|
||
run: build_$(CONFIG) | ||
${OUTPUT_BIN} | ||
# Run target in Debug configuration by default | ||
OUTPUT_BIN := $(BUILD_DIR)/Debug/my_template_binary | ||
|
||
gdb: build_$(CONFIG) | ||
gdb-multiarch ${OUTPUT_BIN} -ex "run" | ||
run: build-debug | ||
$(OUTPUT_BIN) | ||
|
||
.PHONY: build build_$(CONFIG) configure run | ||
# Debug with GDB in Debug configuration | ||
gdb: build-debug | ||
gdb-multiarch $(OUTPUT_BIN) -ex "run" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,35 @@ | ||
|
||
[ Describe your project here ] | ||
|
||
### Prerequisites | ||
|
||
- CMake 3.10 or later | ||
- C++ compiler with C++23 support (Recommended clang-17, CI is running clang-20) | ||
### Dependencies | ||
|
||
### Code quality checks | ||
#### Build system | ||
- CMake 3.19 or later (to be able to use CMakePresets) | ||
- C++ compiler with C++23 support (Recommended clang-17+, The CI uses clang-20) | ||
- ninja-build | ||
|
||
#### Static analyzes | ||
- libsanitizer | ||
- clang-tidy | ||
- cppcheck | ||
|
||
#### Formatter | ||
- clang-format | ||
|
||
### CI Test | ||
|
||
[![CMake](https://github.com/zakaria1193/my_cpp_boilerplate/actions/workflows/cmake.yml/badge.svg)](https://github.com/zakaria1193/my_cpp_boilerplatmy_cpp_boilerplate/actions/workflows/cmake.yml) | ||
[![Build & Check](https://github.com/zakaria1193/my_cpp_boilerplate/actions/workflows/build.yml/badge.svg)](https://github.com/zakaria1193/my_cpp_boilerplate/actions/workflows/build.yml) | ||
|
||
### Documentation | ||
|
||
[ Add your documentation here ] | ||
|
||
|
||
### CMake usage of Presets | ||
|
||
- This boilerplate uses the presets feature (CMake 3.19), but we still keep the presets to minimal (KISS principle), How? | ||
- Only one config preset | ||
- Multiple build presets (release, debug...) | ||
|
||
This means we require a *multi-configuration* build system to support both Debug and Release builds in a *single* configuration step. It is designed to work with generators like _Ninja Multi-Config_ (Available on all Linux systems) or _Visual Studio_, _XCode_... Which allow specifying build configurations (Debug, Release, etc.) at build time. | ||
*Single-configuration* generators, such as *Makefiles*, are not supported, as they require separate build directories for each configuration. If you really need that, edit the configurePresets section of the CMakePresets.json file. Copy paste this to Chatgpt if it's not clear. | ||
|