From 7cf8d132c468b47f4f9b93582be9894b83828dc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Klaim=20=28Jo=C3=ABl=20Lamotte=29?= <142265+Klaim@users.noreply.github.com> Date: Tue, 13 Feb 2024 15:38:30 +0100 Subject: [PATCH 1/4] Use constexpr constants instead of defines. This is both to avoid using the preprocessor in C++ in general, and to prepare for future usage of the library as a C++ module. --- CMakeLists.txt | 4 ++-- include/sparrow/sparrow_version.hpp | 9 ++++++--- test/main.cpp | 8 ++++++++ 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 051d77a8..a502ff5c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,9 +28,9 @@ set(SPARROW_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include) # =========== file(STRINGS "${SPARROW_INCLUDE_DIR}/sparrow/sparrow_version.hpp" sparrow_version_defines - REGEX "#define SPARROW_VERSION_(MAJOR|MINOR|PATCH)") + REGEX "constexpr int SPARROW_VERSION_(MAJOR|MINOR|PATCH)") foreach(ver ${sparrow_version_defines}) - if(ver MATCHES "#define SPARROW_VERSION_(MAJOR|MINOR|PATCH) +([^ ]+)$") + if(ver MATCHES "constexpr int SPARROW_VERSION_(MAJOR|MINOR|PATCH) +([^ ]+)$") set(SPARROW_VERSION_${CMAKE_MATCH_1} "${CMAKE_MATCH_2}" CACHE INTERNAL "") endif() endforeach() diff --git a/include/sparrow/sparrow_version.hpp b/include/sparrow/sparrow_version.hpp index 77960e62..b69da666 100644 --- a/include/sparrow/sparrow_version.hpp +++ b/include/sparrow/sparrow_version.hpp @@ -14,7 +14,10 @@ #pragma once -#define SPARROW_VERSION_MAJOR 0 -#define SPARROW_VERSION_MINOR 0 -#define SPARROW_VERSION_PATCH 1 +namespace sparrow +{ + constexpr int SPARROW_VERSION_MAJOR = 0; + constexpr int SPARROW_VERSION_MINOR = 0; + constexpr int SPARROW_VERSION_PATCH = 1; +} diff --git a/test/main.cpp b/test/main.cpp index a89b6f8a..45911eb8 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -16,3 +16,11 @@ #include "doctest/doctest.h" #include + +#include + +TEST_CASE("version is readable") +{ + using namespace sparrow; + [[maybe_unused]] const std::string printable_version = std::format("sparrow version : {}.{}.{}", SPARROW_VERSION_MAJOR, SPARROW_VERSION_MINOR, SPARROW_VERSION_PATCH); +} From 3cccb6ffd8ad9aecc8c2c50269103d0fdc5e1cf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Klaim=20=28Jo=C3=ABl=20Lamotte=29?= <142265+Klaim@users.noreply.github.com> Date: Wed, 6 Mar 2024 16:24:29 +0100 Subject: [PATCH 2/4] Rewritten test to not use `` --- test/main.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/test/main.cpp b/test/main.cpp index 45911eb8..33d7893c 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -15,12 +15,15 @@ #define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN #include "doctest/doctest.h" -#include +#include #include TEST_CASE("version is readable") { + // TODO: once available on OSX, use `` facility instead. + // We only try to make sure the version valeus are printable, whatever their type. + // AKA this is not written to be fancy but to force conversion to string. using namespace sparrow; - [[maybe_unused]] const std::string printable_version = std::format("sparrow version : {}.{}.{}", SPARROW_VERSION_MAJOR, SPARROW_VERSION_MINOR, SPARROW_VERSION_PATCH); + [[maybe_unused]] const std::string printable_version = std::string("sparrow version : ") + std::to_string(SPARROW_VERSION_MAJOR) + "." + std::to_string(SPARROW_VERSION_MINOR) "." std::to_string(SPARROW_VERSION_PATCH); } From ac4b8b53e9234a447cc3c18395cddb242f7d95c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Klaim=20=28Jo=C3=ABl=20Lamotte=29?= <142265+Klaim@users.noreply.github.com> Date: Wed, 6 Mar 2024 16:31:18 +0100 Subject: [PATCH 3/4] woops --- test/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/main.cpp b/test/main.cpp index 33d7893c..2b476b15 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -25,5 +25,5 @@ TEST_CASE("version is readable") // We only try to make sure the version valeus are printable, whatever their type. // AKA this is not written to be fancy but to force conversion to string. using namespace sparrow; - [[maybe_unused]] const std::string printable_version = std::string("sparrow version : ") + std::to_string(SPARROW_VERSION_MAJOR) + "." + std::to_string(SPARROW_VERSION_MINOR) "." std::to_string(SPARROW_VERSION_PATCH); + [[maybe_unused]] const std::string printable_version = std::string("sparrow version : ") + std::to_string(SPARROW_VERSION_MAJOR) + "." + std::to_string(SPARROW_VERSION_MINOR) + "." std::to_string(SPARROW_VERSION_PATCH); } From b6c1c3999a25c6fb67b24e64701ef700a596c241 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Klaim=20=28Jo=C3=ABl=20Lamotte=29?= <142265+Klaim@users.noreply.github.com> Date: Wed, 6 Mar 2024 16:35:13 +0100 Subject: [PATCH 4/4] sorry! --- test/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/main.cpp b/test/main.cpp index 2b476b15..2d6e2e75 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -25,5 +25,5 @@ TEST_CASE("version is readable") // We only try to make sure the version valeus are printable, whatever their type. // AKA this is not written to be fancy but to force conversion to string. using namespace sparrow; - [[maybe_unused]] const std::string printable_version = std::string("sparrow version : ") + std::to_string(SPARROW_VERSION_MAJOR) + "." + std::to_string(SPARROW_VERSION_MINOR) + "." std::to_string(SPARROW_VERSION_PATCH); + [[maybe_unused]] const std::string printable_version = std::string("sparrow version : ") + std::to_string(SPARROW_VERSION_MAJOR) + "." + std::to_string(SPARROW_VERSION_MINOR) + "." + std::to_string(SPARROW_VERSION_PATCH); }