diff --git a/.gitignore b/.gitignore index ecd7d49..52565e1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ build/ +distribution/ profile.json *-profile.json *.log diff --git a/CMakeLists.txt b/CMakeLists.txt index b2e4044..1361c9b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,5 +17,9 @@ add_library(project_warnings INTERFACE) include(cmake/CompilerWarnings.cmake) set_project_warnings(project_warnings) +include(cmake/Packaging.cmake) + +enable_testing() + add_subdirectory(vendor) add_subdirectory(src) diff --git a/CMakePresets.json b/CMakePresets.json new file mode 100644 index 0000000..4321a5e --- /dev/null +++ b/CMakePresets.json @@ -0,0 +1,161 @@ +{ + "version": 6, + "configurePresets": [ + { + "name": "debug", + "displayName": "Debug", + "generator": "Ninja", + "binaryDir": "build/debug", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Debug" + } + }, + { + "name": "release", + "displayName": "Release", + "generator": "Ninja", + "binaryDir": "build/release", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Release" + } + }, + { + "name": "xcode-debug", + "displayName": "Debug (Xcode)", + "generator": "Xcode", + "binaryDir": "build/xcode-debug", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Debug" + }, + "condition": { + "type": "equals", + "lhs": "${hostSystemName}", + "rhs": "Darwin" + } + }, + { + "name": "xcode-release", + "displayName": "Release (Xcode)", + "generator": "Xcode", + "binaryDir": "build/xcode-release", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Release" + }, + "condition": { + "type": "equals", + "lhs": "${hostSystemName}", + "rhs": "Darwin" + } + } + ], + "buildPresets": [ + { + "name": "debug", + "displayName": "Build Debug", + "configurePreset": "debug", + "configuration": "Debug" + }, + { + "name": "release", + "displayName": "Build Release", + "configurePreset": "release", + "configuration": "Release", + "targets": [ + "App" + ] + }, + { + "name": "xcode-debug", + "displayName": "Build Debug (Xcode)", + "configurePreset": "xcode-debug", + "configuration": "Debug", + "condition": { + "type": "equals", + "lhs": "${hostSystemName}", + "rhs": "Darwin" + } + }, + { + "name": "xcode-release", + "displayName": "Build Release (Xcode)", + "configurePreset": "xcode-release", + "configuration": "Release", + "targets": [ + "App" + ], + "condition": { + "type": "equals", + "lhs": "${hostSystemName}", + "rhs": "Darwin" + } + } + ], + "packagePresets": [ + { + "name": "release", + "displayName": "Distribute Release", + "configurePreset": "release", + "configurations": [ + "Release" + ] + }, + { + "name": "xcode-release", + "displayName": "Distribute Release (Xcode)", + "configurePreset": "xcode-release", + "configurations": [ + "Release" + ], + "condition": { + "type": "equals", + "lhs": "${hostSystemName}", + "rhs": "Darwin" + } + } + ], + "testPresets": [ + { + "name": "all", + "displayName": "Test All", + "configurePreset": "debug" + } + ], + "workflowPresets": [ + { + "name": "dist", + "displayName": "Distribution Workflow", + "steps": [ + { + "type": "configure", + "name": "release" + }, + { + "type": "build", + "name": "release" + }, + { + "type": "package", + "name": "release" + } + ] + }, + { + "name": "xcode-dist", + "displayName": "Distribution Workflow (Xcode)", + "steps": [ + { + "type": "configure", + "name": "xcode-release" + }, + { + "type": "build", + "name": "xcode-release" + }, + { + "type": "package", + "name": "xcode-release" + } + ] + } + ] +} diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index 1c8e83f..20595a0 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -101,7 +101,7 @@ Violating these terms may lead to a permanent ban. ### 4. Permanent Ban **Community Impact**: Demonstrating a pattern of violation of community -standards, including sustained inappropriate behavior, harassment of an +standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals. **Consequence**: A permanent ban from any sort of public interaction within @@ -111,13 +111,21 @@ the community. This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0, available at -https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. +[https://www.contributor-covenant.org/version/2/0/code_of_conduct.html][v2.0]. -Community Impact Guidelines were inspired by [Mozilla's code of conduct -enforcement ladder](https://github.com/mozilla/diversity). +Community Impact Guidelines were inspired by +[Mozilla's code of conduct enforcement ladder][Mozilla CoC]. + +For answers to common questions about this code of conduct, see the FAQ at +[https://www.contributor-covenant.org/faq][FAQ]. Translations are available +at [https://www.contributor-covenant.org/translations][translations]. [homepage]: https://www.contributor-covenant.org -For answers to common questions about this code of conduct, see the FAQ at -https://www.contributor-covenant.org/faq. Translations are available at -https://www.contributor-covenant.org/translations. +[v2.0]: https://www.contributor-covenant.org/version/2/0/code_of_conduct.html + +[Mozilla CoC]: https://github.com/mozilla/diversity + +[FAQ]: https://www.contributor-covenant.org/faq + +[translations]: https://www.contributor-covenant.org/translations diff --git a/LICENSE b/LICENSE index b1503be..6c5430c 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2022-2023 Martin Helmut Fieber +Copyright (c) 2023 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 048eb88..15f8c55 100644 --- a/README.md +++ b/README.md @@ -6,25 +6,16 @@ C++ project template. The project uses [CMake](https://cmake.org) and [Ninja](https://ninja-build.org). -Build the application in debug mode: +Thanks to Cmake presets, a full distribution build can be created via: ```shell -cmake -GNinja -DCMAKE_BUILD_TYPE=Debug -B build/debug -ninja -C build/debug +cmake --workflow --preset dist ``` -Run the application: +Also, running tests with CPack: ```shell -cd ./build/debug/src/app && ./App -``` - -### Using Litr - -When using [Litr](https://github.com/krieselreihe/litr), the quick setup to build and run the application is: - -```shell -litr build,start +ctest --preset all ``` ## Disclaimer diff --git a/cmake/Packaging.cmake b/cmake/Packaging.cmake new file mode 100644 index 0000000..52204ba --- /dev/null +++ b/cmake/Packaging.cmake @@ -0,0 +1,13 @@ +# Base package settings +set(CPACK_PACKAGE_VENDOR ${PROJECT_COMPANY_NAME}) +set(CPACK_PACKAGE_DIRECTORY distribution) +set(CPACK_PACKAGE_INSTALL_DIRECTORY ${CPACK_PACKAGE_NAME}) +set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}-${CMAKE_PROJECT_VERSION}") +set(CPACK_PACKAGE_VERSION_MAJOR ${CMAKE_PROJECT_VERSION_MAJOR}) +set(CPACK_PACKAGE_VERSION_MINOR ${CMAKE_PROJECT_VERSION_MINOR}) +set(CPACK_PACKAGE_VERSION_PATCH ${CMAKE_PROJECT_VERSION_PATCH}) +set(CPACK_VERBATIM_VARIABLES YES) + +set(CPACK_GENERATOR TGZ) + +include(CPack) diff --git a/litr.toml b/litr.toml deleted file mode 100644 index 3c4cb3a..0000000 --- a/litr.toml +++ /dev/null @@ -1,24 +0,0 @@ -[commands.build] -script = [ - "cmake -GNinja -DCMAKE_BUILD_TYPE=%{target} -B build/%{target}", - "ninja -C build/%{target}" -] -description = "Build the application for a given target." - -[commands.start] -script = "./build/%{target}/src/app/App" -description = "Start the application." - -[commands.test] -script = "echo 'No tests defined, yet!'" -description = "Run all tests." - -[commands.format] -script = "find src -iname *.hpp -o -iname *.cpp | xargs clang-format -i" -description = "Format project sources via clang-format." - -[params.target] -shortcut = "t" -description = "Define the application build target." -type = ["debug", "release"] -default = "debug" diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5f86116..b1523c7 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,2 +1,3 @@ +add_subdirectory(tests) add_subdirectory(app) add_subdirectory(some_library) diff --git a/src/app/App/Main.cpp b/src/app/App/Main.cpp index f97ed2c..3301313 100644 --- a/src/app/App/Main.cpp +++ b/src/app/App/Main.cpp @@ -1,6 +1,4 @@ -/* - * Copyright (c) 2022 Martin Helmut Fieber - */ +#include #include "SomeLibrary/Core/Log.hpp" #include "SomeLibrary/Debug/Instrumentor.hpp" diff --git a/src/app/CMakeLists.txt b/src/app/CMakeLists.txt index 5afa4b2..6960aa7 100644 --- a/src/app/CMakeLists.txt +++ b/src/app/CMakeLists.txt @@ -4,6 +4,8 @@ include(${PROJECT_SOURCE_DIR}/cmake/StaticAnalyzers.cmake) add_executable(${NAME} App/Main.cpp) +install(TARGETS ${NAME} RUNTIME DESTINATION .) + target_include_directories(${NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) target_compile_features(${NAME} PRIVATE cxx_std_20) target_link_libraries(${NAME} PRIVATE project_warnings SomeLibrary) diff --git a/src/some_library/CMakeLists.txt b/src/some_library/CMakeLists.txt index 02ee77e..db4cc81 100644 --- a/src/some_library/CMakeLists.txt +++ b/src/some_library/CMakeLists.txt @@ -9,3 +9,5 @@ add_library(${NAME} STATIC target_include_directories(${NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) target_compile_features(${NAME} PRIVATE cxx_std_20) target_link_libraries(${NAME} PRIVATE project_warnings PUBLIC fmt spdlog) + +add_subdirectory(Tests) diff --git a/src/some_library/SomeLibrary/Core/Log.cpp b/src/some_library/SomeLibrary/Core/Log.cpp index cd601dd..5d01b9c 100644 --- a/src/some_library/SomeLibrary/Core/Log.cpp +++ b/src/some_library/SomeLibrary/Core/Log.cpp @@ -1,13 +1,13 @@ -/* - * Copyright (c) 2022 Martin Helmut Fieber - */ - #include "Log.hpp" -#include +#include +#include +#include +#include +#include -#include "spdlog/sinks/basic_file_sink.h" -#include "spdlog/sinks/stdout_color_sinks.h" +#include +#include namespace App { diff --git a/src/some_library/SomeLibrary/Core/Log.hpp b/src/some_library/SomeLibrary/Core/Log.hpp index a11120d..ffd4c7d 100644 --- a/src/some_library/SomeLibrary/Core/Log.hpp +++ b/src/some_library/SomeLibrary/Core/Log.hpp @@ -1,13 +1,9 @@ -/* - * Copyright (c) 2022 Martin Helmut Fieber - */ - #pragma once -#include +#include +#include -#include "spdlog/fmt/ostr.h" -#include "spdlog/spdlog.h" +#include namespace App { diff --git a/src/some_library/SomeLibrary/Debug/Instrumentor.hpp b/src/some_library/SomeLibrary/Debug/Instrumentor.hpp index 3c040c4..68b7138 100644 --- a/src/some_library/SomeLibrary/Debug/Instrumentor.hpp +++ b/src/some_library/SomeLibrary/Debug/Instrumentor.hpp @@ -1,7 +1,3 @@ -/* - * Copyright (c) 2022 Martin Helmut Fieber - */ - #pragma once #include @@ -27,8 +23,8 @@ struct ProfileResult { }; struct InstrumentationSession { - const std::string name; - explicit InstrumentationSession(std::string name) : name(std::move(name)) {} + std::string name; + explicit InstrumentationSession(std::string session_name) : name(std::move(session_name)) {} }; class Instrumentor { @@ -39,7 +35,7 @@ class Instrumentor { Instrumentor& operator=(Instrumentor&& other) = delete; void begin_session(const std::string& name, const std::string& filepath = "results.json") { - std::lock_guard lock(m_mutex); + const std::lock_guard lock(m_mutex); if (m_current_session != nullptr) { // If there is already a current session, then close it before beginning new one. @@ -62,7 +58,7 @@ class Instrumentor { } void end_session() { - std::lock_guard lock(m_mutex); + const std::lock_guard lock(m_mutex); internal_end_session(); } @@ -83,7 +79,7 @@ class Instrumentor { json << "\"ts\":" << result.start.count(); json << "}"; - std::lock_guard lock(m_mutex); + const std::lock_guard lock(m_mutex); if (m_current_session != nullptr) { m_output_stream << json.str(); m_output_stream.flush(); @@ -158,9 +154,9 @@ class InstrumentationTimer { } private: - const std::string m_name; + std::string m_name; bool m_stopped{false}; - const std::chrono::time_point m_start_time_point; + std::chrono::time_point m_start_time_point; }; } // namespace App::Debug diff --git a/src/some_library/Tests/CMakeLists.txt b/src/some_library/Tests/CMakeLists.txt new file mode 100644 index 0000000..71e1e7c --- /dev/null +++ b/src/some_library/Tests/CMakeLists.txt @@ -0,0 +1,5 @@ +# Test cases + +add_executable(ResourcesTest Resources.spec.cpp $) +add_test(NAME ResourcesTest COMMAND ResourcesTest) +target_link_libraries(ResourcesTest PRIVATE doctest SomeLibrary) diff --git a/src/some_library/Tests/Resources.spec.cpp b/src/some_library/Tests/Resources.spec.cpp new file mode 100644 index 0000000..535df17 --- /dev/null +++ b/src/some_library/Tests/Resources.spec.cpp @@ -0,0 +1,14 @@ +#include + +#include + +// NOLINTBEGIN(misc-use-anonymous-namespace, cppcoreguidelines-avoid-do-while, cert-err33-c) + +TEST_SUITE("Core::Resources") { + TEST_CASE("Example") { + const std::string input{"A"}; + CHECK_EQ(input, "A"); + } +} + +// NOLINTEND(misc-use-anonymous-namespace, cppcoreguidelines-avoid-do-while, cert-err33-c) diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt new file mode 100644 index 0000000..c5f818c --- /dev/null +++ b/src/tests/CMakeLists.txt @@ -0,0 +1,5 @@ +set(NAME "TestRunner") + +add_library(${NAME} OBJECT ${PROJECT_SOURCE_DIR}/src/tests/TestRunner.cpp) +target_compile_features(${NAME} PRIVATE cxx_std_20) +target_link_libraries(${NAME} PUBLIC doctest) diff --git a/src/tests/TestRunner.cpp b/src/tests/TestRunner.cpp new file mode 100644 index 0000000..0a3f254 --- /dev/null +++ b/src/tests/TestRunner.cpp @@ -0,0 +1,2 @@ +#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN +#include diff --git a/vendor/doctest/CMakeLists.txt b/vendor/doctest/CMakeLists.txt index 2afc2a6..7016f17 100644 --- a/vendor/doctest/CMakeLists.txt +++ b/vendor/doctest/CMakeLists.txt @@ -1,3 +1,5 @@ message(STATUS "Fetching Doctest ...") +set(DOCTEST_NO_INSTALL ON) + FetchContent_MakeAvailable(doctest)