Skip to content

Commit 94bb7e4

Browse files
authored
Merge pull request #508 from scratchcpp/version_api
Add version API
2 parents e8a3468 + 36dccb8 commit 94bb7e4

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cmake_minimum_required(VERSION 3.14)
22

3-
project(libscratchcpp LANGUAGES C CXX)
3+
project(libscratchcpp VERSION 0.9.0 LANGUAGES C CXX)
44

55
set(CMAKE_INCLUDE_CURRENT_DIR ON)
66
set(CMAKE_CXX_STANDARD 17)
@@ -92,6 +92,10 @@ if (LIBSCRATCHCPP_NETWORK_SUPPORT)
9292
endif()
9393

9494
target_compile_definitions(scratchcpp PRIVATE LIBSCRATCHCPP_LIBRARY)
95+
target_compile_definitions(scratchcpp PRIVATE LIBSCRATCHCPP_VERSION="${PROJECT_VERSION}")
96+
target_compile_definitions(scratchcpp PRIVATE LIBSCRATCHCPP_VERSION_MAJOR=${PROJECT_VERSION_MAJOR})
97+
target_compile_definitions(scratchcpp PRIVATE LIBSCRATCHCPP_VERSION_MINOR=${PROJECT_VERSION_MINOR})
98+
target_compile_definitions(scratchcpp PRIVATE LIBSCRATCHCPP_VERSION_PATCH=${PROJECT_VERSION_PATCH})
9599

96100
if (LIBSCRATCHCPP_BUILD_UNIT_TESTS)
97101
enable_testing()

include/scratchcpp/scratchconfiguration.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ class LIBSCRATCHCPP_EXPORT ScratchConfiguration
4040
static void removeGraphicsEffect(const std::string &name);
4141
static IGraphicsEffect *getGraphicsEffect(const std::string &name);
4242

43+
static const std::string &version();
44+
static int majorVersion();
45+
static int minorVersion();
46+
static int patchVersion();
47+
4348
private:
4449
static const std::vector<std::shared_ptr<IExtension>> getExtensions();
4550

src/scratchconfiguration.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,31 @@ IGraphicsEffect *ScratchConfiguration::getGraphicsEffect(const std::string &name
4949
return it->second.get();
5050
}
5151

52+
/*! Returns the version string of the library. */
53+
const std::string &ScratchConfiguration::version()
54+
{
55+
static const std::string ret = LIBSCRATCHCPP_VERSION;
56+
return ret;
57+
}
58+
59+
/*! Returns the major version of the library. */
60+
int ScratchConfiguration::majorVersion()
61+
{
62+
return LIBSCRATCHCPP_VERSION_MAJOR;
63+
}
64+
65+
/*! Returns the minor version of the library. */
66+
int ScratchConfiguration::minorVersion()
67+
{
68+
return LIBSCRATCHCPP_VERSION_MINOR;
69+
}
70+
71+
/*! Returns the patch version of the library. */
72+
int ScratchConfiguration::patchVersion()
73+
{
74+
return LIBSCRATCHCPP_VERSION_PATCH;
75+
}
76+
5277
const std::vector<std::shared_ptr<IExtension>> ScratchConfiguration::getExtensions()
5378
{
5479
return impl->extensions;

0 commit comments

Comments
 (0)