From a08585812ddfb3dbbc65637d867ad24346396b87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20D=C3=BCrrenberger?= Date: Sat, 3 Oct 2026 12:19:42 +0200 Subject: [PATCH] Add sfGetVersion to retrieve the runtime SFML version --- include/CSFML/System.h | 1 + include/CSFML/System/Version.h | 64 +++++++++++++++++++++++++++++++++ src/CSFML/System/CMakeLists.txt | 2 ++ src/CSFML/System/Version.cpp | 41 +++++++++++++++++++++ test/CMakeLists.txt | 1 + test/System/Version.test.cpp | 15 ++++++++ 6 files changed, 124 insertions(+) create mode 100644 include/CSFML/System/Version.h create mode 100644 src/CSFML/System/Version.cpp create mode 100644 test/System/Version.test.cpp diff --git a/include/CSFML/System.h b/include/CSFML/System.h index 83a7332..7050c01 100644 --- a/include/CSFML/System.h +++ b/include/CSFML/System.h @@ -37,3 +37,4 @@ #include #include #include +#include diff --git a/include/CSFML/System/Version.h b/include/CSFML/System/Version.h new file mode 100644 index 0000000..b3302ec --- /dev/null +++ b/include/CSFML/System/Version.h @@ -0,0 +1,64 @@ +//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007-2026 Laurent Gomila (laurent@sfml-dev.org) +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +//////////////////////////////////////////////////////////// + +#pragma once + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include + +#include +#include + + +//////////////////////////////////////////////////////////// +/// \brief Version information of the SFML library +/// +//////////////////////////////////////////////////////////// +typedef struct +{ + int8_t major; ///< SFML major version + int8_t minor; ///< SFML minor version + int8_t patch; ///< SFML patch version + bool isRelease; ///< true if this is a release version, false if this is a development version + const char* string; ///< String representation of the SFML version, e.g. 3.1.0 or 3.1.0-dev +} sfVersion; + + +//////////////////////////////////////////////////////////// +/// \brief Get the version of the SFML library loaded at runtime +/// +/// This is the version of the SFML library CSFML is linked +/// against at runtime, which can differ from the version +/// CSFML was compiled with (see CSFML_VERSION_MAJOR, +/// CSFML_VERSION_MINOR and CSFML_VERSION_PATCH). +/// +/// The returned string is owned by SFML and stays valid +/// for the whole lifetime of the program. +/// +/// \return Version information of the SFML library +/// +//////////////////////////////////////////////////////////// +CSFML_SYSTEM_API sfVersion sfGetVersion(void); diff --git a/src/CSFML/System/CMakeLists.txt b/src/CSFML/System/CMakeLists.txt index a973cd1..0178d6c 100644 --- a/src/CSFML/System/CMakeLists.txt +++ b/src/CSFML/System/CMakeLists.txt @@ -23,6 +23,8 @@ set(SRC ${INCROOT}/Types.h ${INCROOT}/Vector2.h ${INCROOT}/Vector3.h + ${SRCROOT}/Version.cpp + ${INCROOT}/Version.h ) # define the csfml-system target diff --git a/src/CSFML/System/Version.cpp b/src/CSFML/System/Version.cpp new file mode 100644 index 0000000..0d80f83 --- /dev/null +++ b/src/CSFML/System/Version.cpp @@ -0,0 +1,41 @@ +//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007-2026 Laurent Gomila (laurent@sfml-dev.org) +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +//////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include + +#include + +#include + + +//////////////////////////////////////////////////////////// +sfVersion sfGetVersion() +{ + const auto& version = sf::version(); + static const std::string string(version.string); + return {version.major, version.minor, version.patch, version.isRelease, string.c_str()}; +} diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index f32f988..dd6cdaa 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -27,6 +27,7 @@ add_executable(test-csfml-system System/Time.test.cpp System/Vector2.test.cpp System/Vector3.test.cpp + System/Version.test.cpp ) target_link_libraries(test-csfml-system PRIVATE csfml-system Catch2::Catch2WithMain) set_target_warnings(test-csfml-system) diff --git a/test/System/Version.test.cpp b/test/System/Version.test.cpp new file mode 100644 index 0000000..028b8ab --- /dev/null +++ b/test/System/Version.test.cpp @@ -0,0 +1,15 @@ +#include + +#include + +#include + +TEST_CASE("[System] sfGetVersion") +{ + const sfVersion version = sfGetVersion(); + CHECK(version.major == 3); + CHECK(version.minor >= 1); + CHECK(version.patch >= 0); + REQUIRE(version.string != nullptr); + CHECK(std::string(version.string).rfind(std::to_string(version.major) + "." + std::to_string(version.minor), 0) == 0); +}