From ebdaeca90a9023e2406d376808037a6a95cf09e6 Mon Sep 17 00:00:00 2001 From: Daljit Singh Date: Tue, 1 Oct 2024 13:31:59 +0100 Subject: [PATCH] Use std::string in C++ versioning logic --- cpp/lib/core/app.cpp | 2 +- cpp/lib/core/app.h | 4 ++-- cpp/lib/core/command.h | 2 +- cpp/lib/executable_version.cpp.in | 2 +- cpp/lib/mrtrix_version.cpp.in | 5 +++-- cpp/lib/mrtrix_version.h | 5 +++-- 6 files changed, 11 insertions(+), 9 deletions(-) diff --git a/cpp/lib/core/app.cpp b/cpp/lib/core/app.cpp index 5bcb28f108..0fcab3427b 100644 --- a/cpp/lib/core/app.cpp +++ b/cpp/lib/core/app.cpp @@ -1153,7 +1153,7 @@ void init(int cmdline_argc, const char *const *cmdline_argv) { NAME.erase(NAME.size() - 4); #endif - if (strcmp(mrtrix_version, executable_uses_mrtrix_version) != 0) { + if (mrtrix_version != executable_uses_mrtrix_version) { Exception E("executable was compiled for a different version of the MRtrix3 library!"); E.push_back(std::string(" ") + NAME + " version: " + executable_uses_mrtrix_version); E.push_back(std::string(" library version: ") + mrtrix_version); diff --git a/cpp/lib/core/app.h b/cpp/lib/core/app.h index 1af93e0e74..d678d6f0c4 100644 --- a/cpp/lib/core/app.h +++ b/cpp/lib/core/app.h @@ -34,8 +34,8 @@ extern void run(); namespace MR::App { -extern const char *mrtrix_version; -extern const char *build_date; +extern const std::string mrtrix_version; +extern const std::string build_date; extern int log_level; extern int exit_error_code; extern std::string NAME; diff --git a/cpp/lib/core/command.h b/cpp/lib/core/command.h index 5d4b9d44b6..b399bbebf3 100644 --- a/cpp/lib/core/command.h +++ b/cpp/lib/core/command.h @@ -21,7 +21,7 @@ #endif #include "app.h" -#include "cmd_version.h" +#include "executable_version.h" #include "mrtrix.h" #ifdef MRTRIX_PROJECT namespace MR { diff --git a/cpp/lib/executable_version.cpp.in b/cpp/lib/executable_version.cpp.in index 8bbac002c4..b310f2bb6f 100644 --- a/cpp/lib/executable_version.cpp.in +++ b/cpp/lib/executable_version.cpp.in @@ -1,4 +1,4 @@ -#include "cmd_version.h" +#include "executable_version.h" namespace MR { namespace App { diff --git a/cpp/lib/mrtrix_version.cpp.in b/cpp/lib/mrtrix_version.cpp.in index f7235a4b5b..87d2935f92 100644 --- a/cpp/lib/mrtrix_version.cpp.in +++ b/cpp/lib/mrtrix_version.cpp.in @@ -1,6 +1,7 @@ #include "mrtrix_version.h" +#include namespace MR::App { -const char *mrtrix_version = "@MRTRIX_VERSION@"; -const char *build_date = __DATE__; +const std::string mrtrix_version = "@MRTRIX_VERSION@"; +const std::string build_date = __DATE__; } diff --git a/cpp/lib/mrtrix_version.h b/cpp/lib/mrtrix_version.h index 00b6d8534e..c765871502 100644 --- a/cpp/lib/mrtrix_version.h +++ b/cpp/lib/mrtrix_version.h @@ -15,8 +15,9 @@ */ #pragma once +#include namespace MR::App { -extern const char *mrtrix_version; -extern const char *build_date; +extern const std::string mrtrix_version; +extern const std::string build_date; } // namespace MR::App