Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
Checks: "*,
-bugprone-chained-comparison,
-abseil-*,
-altera-*,
-android-*,
Expand All @@ -14,8 +15,9 @@ Checks: "*,
readability-avoid-const-params-in-decls,
cppcoreguidelines-non-private-member-variables-in-classes,
misc-non-private-member-variables-in-classes,
misc-include-cleaner,
-misc-include-cleaner,
-misc-use-internal-linkagecor
"
WarningsAsErrors: ''
WarningsAsErrors: '*'
HeaderFilterRegex: ''
FormatStyle: none
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
cmake_minimum_required(VERSION 3.21...3.28)
cmake_minimum_required(VERSION 3.23...4.0)

# set a default CXX standard for the tools and targets that do not specify them.
# If commented, the latest supported standard for your compiler is automatically set.
# set(CMAKE_CXX_STANDARD 20)

# This allows libraries from multiple build types to be put in the same directory without overwriting each other
set(CMAKE_RELWITHDEBINFO_POSTFIX d)

# Set to `ON` if using C++20 modules
set(CMAKE_CXX_SCAN_FOR_MODULES OFF)

Expand Down
59 changes: 39 additions & 20 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,51 @@
# Notes:
# - list all the task under PHONY
# - If getting missing separator error, try replacing spaces with tabs.
# - If using Visual Studio, either run the following commands inside the Visual Studio command prompt (vcvarsall) or remove the Ninja generator from the commands.
.PHONY: build test test_release test_install coverage docs format clean
# - If using Visual Studio, either run the following commands inside the Visual Studio command prompt (vcvarsall)
# or remove the Ninja generator from the commands.
# Standard stuff

.SUFFIXES:

MAKEFLAGS+= --no-builtin-rules
MAKEFLAGS+= --warn-undefined-variables

OS?=$(shell uname)
export PROJECT_DIR?=$(shell basename $(CURDIR))
export BUILD_DIR?=$(CURDIR)/build

.PHONY: all build test test_release test_install test_release_debug coverage docs format clean distclean

build: release

release:
cmake --workflow --preset default
all: test_release test_install test_release_debug coverage doc

debug:
cmake -S ./ -B ./build -G "Ninja Multi-Config" -DCMAKE_BUILD_TYPE:STRING=Debug -DFEATURE_TESTS:BOOL=OFF
cmake --build ./build --config Debug
release:
cmake --workflow --preset Release

debug: test
test:
cmake --workflow --preset developer

test_release_debug:
cmake -S ./ -B ./build -G "Ninja Multi-Config" -DCMAKE_BUILD_TYPE:STRING=RelWithDebInfo -DFEATURE_TESTS:BOOL=ON
cmake --build ./build --config RelWithDebInfo
cmake --workflow --preset RelWithDebInfo

(cd build/my_exe/test && ctest -C RelWithDebInfo --output-on-failure)
(cd build/my_header_lib/test && ctest -C RelWithDebInfo --output-on-failure)
(cd build/my_lib/test && ctest -C RelWithDebInfo --output-on-failure)
test_release:
cmake --workflow --preset gcc-release

test_release: release

test_install: release
test_install:
cmake --workflow --preset clang-release

coverage:
ifeq ($(OS), Windows_NT)
OpenCppCoverage.exe --export_type cobertura:coverage.xml --cover_children -- $(MAKE) test
else
$(MAKE) test
gcovr -j 1 --delete --root ./ --print-summary --xml-pretty --xml coverage.xml ./build --gcov-executable gcov
gcovr -j 1 --delete --root $(CURDIR) --print-summary --xml-pretty --xml coverage.xml $(BUILD_DIR)/developer --gcov-executable gcov
endif

docs:
cmake -S ./ -B ./build -G "Ninja Multi-Config" -DCMAKE_BUILD_TYPE:STRING=Debug -DFEATURE_DOCS:BOOL=ON -DFEATURE_TESTS:BOOL=OFF
cmake --build ./build --target doxygen-docs --config Debug
cmake --build $(BUILD_DIR)/developer --target doxygen-docs --config Coverage

format:
ifeq ($(OS), Windows_NT)
Expand All @@ -51,7 +58,19 @@ endif

clean:
ifeq ($(OS), Windows_NT)
pwsh -c 'function rmrf($$path) { if (test-path $$path) { rm -r -force $$path }}; rmrf ./build;'
pwsh -c 'function rmrf($$path) { if (test-path $$path) { rm -r -force $$path }}; rmrf $(BUILD_DIR);'
else
rm -rf $(BUILD_DIR)
endif

distclean: clean
ifeq ($(OS), Windows_NT)
pwsh -c 'function rmrf($$path) { if (test-path $$path) { rm -r -force $$path }}; rmrf ./install;'
else
rm -rf ./build
rm -rf ./install
endif

# Anything we don't know how to build will use this rule.
# The command is a do-nothing command.
#
% :: ;
97 changes: 76 additions & 21 deletions cmake/presets/CMakeWorkflowPresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,26 @@
"binaryDir": "${sourceDir}/build/${presetName}",
"installDir": "${sourceDir}/install/${presetName}",
"cacheVariables": {
"CMAKE_CXX_STANDARD": "20",
"FEATURE_DOCS": true
}
},
{
"name": "default",
"name": "Release",
"inherits": "conf-common",
"displayName": "Default User Config",
"description": "Default build using Ninja generator",
"generator": "Ninja",
"binaryDir": "${sourceDir}/build/default",
"installDir": "${sourceDir}/install",
"cacheVariables": {
"CMAKE_PREFIX_PATH": {
"type": "path",
"value": "${sourceDir}/install"
},
"CMAKE_CXX_STANDARD": "20",
"CMAKE_UNITY_BUILD": true,
"CMAKE_CXX_STANDARD": "23",
"CMAKE_BUILD_TYPE": "Release",
"CMAKE_SKIP_INSTALL_RULES": false,
"BUILD_SHARED_LIBS": false,
"BUILD_SHARED_LIBS": true,
"FEATURE_TESTS": false,
"FEATURE_DOCS": false,
"WARNINGS_AS_ERRORS": false
Expand All @@ -45,34 +46,60 @@
},
{
"name": "developer",
"inherits": "default",
"inherits": "Release",
"displayName": "Ninja Multi-Config",
"description": "Default build using Ninja Multi-Config generator",
"description": "Debug build using Ninja Multi-Config generator",
"generator": "Ninja Multi-Config",
"binaryDir": "${sourceDir}/build/developer",
"cacheVariables": {
"CMAKE_UNITY_BUILD": false,
"CMAKE_BUILD_TYPE": "Debug",
"CMAKE_SKIP_INSTALL_RULES": true,
"BUILD_SHARED_LIBS": true,
"FEATURE_FUZZ_TESTS": false,
"FEATURE_FUZZ_TESTS": true,
"FEATURE_TESTS": true,
"FEATURE_DOCS": false,
"WARNINGS_AS_ERRORS": "WARNINGS_AS_ERRORS"
"WARNINGS_AS_ERRORS": true
}
},
{
"name": "RelWithDebInfo",
"inherits": "developer",
"description": "RelWithDebInfo build using Ninja Multi-Config generator",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "RelWithDebInfo",
"CMAKE_SKIP_INSTALL_RULES": false,
"BUILD_SHARED_LIBS": true,
"FEATURE_FUZZ_TESTS": false,
"FEATURE_TESTS": false,
"FEATURE_DOCS": false,
"WARNINGS_AS_ERRORS": false
}
}
],
"buildPresets": [
{
"name": "default",
"configurePreset": "default"
"name": "Release",
"configurePreset": "Release"
},
{
"name": "developer",
"configurePreset": "developer"
},
{
"name": "install",
"configurePreset": "default",
"name": "RelWithDebInfo",
"configurePreset": "RelWithDebInfo"
},
{
"name": "installRelease",
"configurePreset": "Release",
"targets": [
"install"
]
},
{
"name": "installRelWithDebInfo",
"configurePreset": "RelWithDebInfo",
"configuration": "RelWithDebInfo",
"targets": [
"install"
]
Expand All @@ -94,32 +121,39 @@
],
"packagePresets": [
{
"name": "default",
"configurePreset": "default",
"name": "Release",
"configurePreset": "Release",
"generators": [
"TGZ"
]
},
{
"name": "RelWithDebInfo",
"configurePreset": "RelWithDebInfo",
"generators": [
"TGZ"
]
}
],
"workflowPresets": [
{
"name": "default",
"name": "Release",
"steps": [
{
"type": "configure",
"name": "default"
"name": "Release"
},
{
"type": "build",
"name": "default"
"name": "Release"
},
{
"type": "build",
"name": "install"
"name": "installRelease"
},
{
"type": "package",
"name": "default"
"name": "Release"
}
]
},
Expand All @@ -139,6 +173,27 @@
"name": "developer"
}
]
},
{
"name": "RelWithDebInfo",
"steps": [
{
"type": "configure",
"name": "RelWithDebInfo"
},
{
"type": "build",
"name": "RelWithDebInfo"
},
{
"type": "build",
"name": "installRelWithDebInfo"
},
{
"type": "package",
"name": "RelWithDebInfo"
}
]
}
]
}
7 changes: 4 additions & 3 deletions fuzz_test/fuzz_tester.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#include <fmt/format.h>
#include <fmt/core.h> // for print, format_string

#include <iterator>
#include <utility>
#include <cstddef> // for size_t
#include <cstdint> // for uint8_t
#include <iterator> // for next

[[nodiscard]] auto sum_values(const uint8_t *Data, size_t Size) {
constexpr auto scale = 1000;
Expand Down
16 changes: 14 additions & 2 deletions my_header_lib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
set(CMAKE_VERIFY_INTERFACE_HEADER_SETS ON)

add_library(my_header_lib INTERFACE)

# cmake-format: off
target_sources(
my_header_lib INTERFACE
FILE_SET HEADERS
BASE_DIRS include
FILES include/my_header_lib/lib.hpp
)
# cmake-format: on

# link project_options/warnings
target_link_libraries(my_header_lib INTERFACE my_project_options my_project_warnings)

# Includes
target_include_interface_directories(my_header_lib include)
# Includes not needed if using FILE_SET HEADERS
#XXX target_include_interface_directories(my_header_lib include)

# Find dependencies:
target_find_dependencies(my_header_lib INTERFACE_CONFIG fmt)
Expand Down
6 changes: 3 additions & 3 deletions my_header_lib/include/my_header_lib/lib.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

#include <fmt/core.h>

inline int some_fun() {
[[nodiscard]] inline int some_fun() {
fmt::print("Hello {} !", "world");
return 0;
}

constexpr int some_constexpr_fun() {
[[nodiscard]] constexpr int some_constexpr_fun() {
return 0;
}
}
14 changes: 12 additions & 2 deletions my_lib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
add_library(my_lib "./src/my_lib/lib.cpp")

# cmake-format: off
target_sources(
my_lib PUBLIC
FILE_SET HEADERS
BASE_DIRS include
FILES include/my_lib/lib.hpp
)
# cmake-format: on

# link project_options/warnings
target_link_libraries(my_lib PRIVATE my_project_options my_project_warnings)

# Includes
target_include_interface_directories(my_lib include)
# Includes not needed if using FILE_SET HEADERS
#XXX target_include_interface_directories(my_lib include)

# Find dependencies:
target_find_dependencies(my_lib PRIVATE_CONFIG fmt)
Expand Down
6 changes: 3 additions & 3 deletions my_lib/include/my_lib/lib.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

int some_fun();
[[nodiscard]] int some_fun();

constexpr int some_constexpr_fun() {
[[nodiscard]] constexpr int some_constexpr_fun() {
return 0;
}
}
2 changes: 2 additions & 0 deletions my_lib/src/my_lib/lib.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include "my_lib/lib.hpp"

#include <fmt/base.h>

int some_fun() {
Expand Down