Skip to content

Commit

Permalink
Add ApiVersion structure to let users access api version components (…
Browse files Browse the repository at this point in the history
…major, minor ...)
  • Loading branch information
Madour committed Mar 16, 2024
1 parent e7cd9f3 commit 56a34f5
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
cmake_minimum_required(VERSION 3.10)

project(LDtkLoader VERSION 1.5.3)
if (NOT PROJECT_VERSION_TWEAK)
set(PROJECT_VERSION_TWEAK 0)
endif()

# build options
option(LDTK_NO_THROW "Replace all throws by an error print and exit" OFF)
Expand Down
2 changes: 1 addition & 1 deletion cmake/LDtkLoaderConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
include("${CMAKE_CURRENT_LIST_DIR}/LDtkLoaderTargets.cmake")

message(STATUS "Found LDtkLoader @PROJECT_VERSION_MAJOR@.@PROJECT_VERSION_MINOR@.@PROJECT_VERSION_PATCH@ in ${CMAKE_CURRENT_LIST_DIR}")
message(STATUS "Found LDtkLoader @PROJECT_VERSION@ in ${CMAKE_CURRENT_LIST_DIR}")
4 changes: 2 additions & 2 deletions src/Project.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,12 @@ void Project::load(const nlohmann::json& j, const FileLoader& file_loader, bool

// compare loaded json version with the library API version and issue a warning if mismatching
{
auto api_version = std::string(API_VERSION);
auto api_version = std::string(API_VERSION_STRING);
auto json_major_minor = m_json_version.substr(0, m_json_version.find('.', 3));
auto api_major_minor = api_version.substr(0, api_version.find('.', 3));

if (json_major_minor != api_major_minor) {
std::cout << "LDtkLoader Warning: Version mismatch. LDtkLoader v" << api_major_minor
std::cout << "LDtkLoader Warning: Version mismatch. LDtkLoader v" << API_VERSION_STRING
<< " may fail to load the project \"" << getFilePath().c_str()<< "\" created"
<< " with LDtk v" << json_major_minor << ". Please make sure your software is"
<< " up to date." << std::endl;
Expand Down
9 changes: 8 additions & 1 deletion src/Version.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,12 @@
#pragma once

namespace ldtk {
constexpr const char* const API_VERSION = "@PROJECT_VERSION@";
struct ApiVersion {
static constexpr unsigned Major = @PROJECT_VERSION_MAJOR@;
static constexpr unsigned Minor = @PROJECT_VERSION_MINOR@;
static constexpr unsigned Patch = @PROJECT_VERSION_PATCH@;
static constexpr unsigned Tweak = @PROJECT_VERSION_TWEAK@;
};

constexpr const char* const API_VERSION_STRING = "@PROJECT_VERSION@";
}

0 comments on commit 56a34f5

Please sign in to comment.