diff --git a/.clang-tidy b/.clang-tidy index 5b98248..4b6edb3 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -1,5 +1,6 @@ --- Checks: "*, + -bugprone-chained-comparison, -abseil-*, -altera-*, -android-*, @@ -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 diff --git a/CMakeLists.txt b/CMakeLists.txt index 11783ec..131ee69 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/Makefile b/Makefile index 1f9ca0e..7931b5e 100644 --- a/Makefile +++ b/Makefile @@ -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) @@ -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. +# +% :: ; diff --git a/cmake/presets/CMakeWorkflowPresets.json b/cmake/presets/CMakeWorkflowPresets.json index 3ceb511..4e5bf8d 100644 --- a/cmake/presets/CMakeWorkflowPresets.json +++ b/cmake/presets/CMakeWorkflowPresets.json @@ -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 @@ -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" ] @@ -94,8 +121,15 @@ ], "packagePresets": [ { - "name": "default", - "configurePreset": "default", + "name": "Release", + "configurePreset": "Release", + "generators": [ + "TGZ" + ] + }, + { + "name": "RelWithDebInfo", + "configurePreset": "RelWithDebInfo", "generators": [ "TGZ" ] @@ -103,23 +137,23 @@ ], "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" } ] }, @@ -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" + } + ] } ] } diff --git a/fuzz_test/fuzz_tester.cpp b/fuzz_test/fuzz_tester.cpp index 7c1eb82..289c5da 100644 --- a/fuzz_test/fuzz_tester.cpp +++ b/fuzz_test/fuzz_tester.cpp @@ -1,7 +1,8 @@ -#include +#include // for print, format_string -#include -#include +#include // for size_t +#include // for uint8_t +#include // for next [[nodiscard]] auto sum_values(const uint8_t *Data, size_t Size) { constexpr auto scale = 1000; diff --git a/my_header_lib/CMakeLists.txt b/my_header_lib/CMakeLists.txt index 24bb0f7..c9e4cff 100644 --- a/my_header_lib/CMakeLists.txt +++ b/my_header_lib/CMakeLists.txt @@ -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) diff --git a/my_header_lib/include/my_header_lib/lib.hpp b/my_header_lib/include/my_header_lib/lib.hpp index 74170c7..6f5152e 100644 --- a/my_header_lib/include/my_header_lib/lib.hpp +++ b/my_header_lib/include/my_header_lib/lib.hpp @@ -2,11 +2,11 @@ #include -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; -} \ No newline at end of file +} diff --git a/my_lib/CMakeLists.txt b/my_lib/CMakeLists.txt index a0d6447..05bb9e4 100644 --- a/my_lib/CMakeLists.txt +++ b/my_lib/CMakeLists.txt @@ -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) diff --git a/my_lib/include/my_lib/lib.hpp b/my_lib/include/my_lib/lib.hpp index 4d766c1..43cc0f6 100644 --- a/my_lib/include/my_lib/lib.hpp +++ b/my_lib/include/my_lib/lib.hpp @@ -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; -} \ No newline at end of file +} diff --git a/my_lib/src/my_lib/lib.cpp b/my_lib/src/my_lib/lib.cpp index 84794f2..a0dfc51 100644 --- a/my_lib/src/my_lib/lib.cpp +++ b/my_lib/src/my_lib/lib.cpp @@ -1,3 +1,5 @@ +#include "my_lib/lib.hpp" + #include int some_fun() {