Add generated version info
This commit is contained in:
parent
ce8c03151f
commit
2ac810c843
@ -19,6 +19,12 @@ project(nlohmann_json_schema_validator
|
||||
|
||||
message(STATUS "Version: ${PROJECT_VERSION}")
|
||||
|
||||
set(LIB_VERSION_CPP_FILE ${CMAKE_CURRENT_BINARY_DIR}/json-schema-version.cpp)
|
||||
set(LIB_VERSION_HPP_FILE ${CMAKE_CURRENT_BINARY_DIR}/include/nlohmann/json-schema-version.hpp)
|
||||
|
||||
configure_file(src/json-schema-version.cpp.in ${LIB_VERSION_CPP_FILE})
|
||||
configure_file(src/json-schema-version.hpp.in ${LIB_VERSION_HPP_FILE})
|
||||
|
||||
cmake_minimum_required(VERSION 3.2)
|
||||
|
||||
option(BUILD_TESTS "Build tests" ON)
|
||||
@ -35,12 +41,14 @@ add_library(nlohmann_json_schema_validator
|
||||
src/json-uri.cpp
|
||||
src/json-validator.cpp
|
||||
src/json-patch.cpp
|
||||
${LIB_VERSION_CPP_FILE}
|
||||
src/string-format-check.cpp)
|
||||
|
||||
target_include_directories(nlohmann_json_schema_validator
|
||||
PUBLIC
|
||||
$<INSTALL_INTERFACE:include>
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>)
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>)
|
||||
|
||||
target_compile_features(nlohmann_json_schema_validator
|
||||
PUBLIC
|
||||
|
||||
44
src/json-schema-version.cpp.in
Normal file
44
src/json-schema-version.cpp.in
Normal file
@ -0,0 +1,44 @@
|
||||
#include <nlohmann/json-schema-version.hpp>
|
||||
|
||||
namespace nlohmann
|
||||
{
|
||||
namespace json_schema
|
||||
{
|
||||
namespace about
|
||||
{
|
||||
|
||||
const std::string &version_txt()
|
||||
{
|
||||
// clang-format off
|
||||
static std::string version{"${${PROJECT_NAME}_VERSION}"};
|
||||
// clang-format on
|
||||
return version;
|
||||
}
|
||||
|
||||
// clang-format off
|
||||
template <>
|
||||
bool check_library_version<${${PROJECT_NAME}_VERSION_MAJOR}>() noexcept
|
||||
{
|
||||
return true;
|
||||
}
|
||||
// clang-format on
|
||||
|
||||
// clang-format off
|
||||
template <>
|
||||
bool check_library_version<${${PROJECT_NAME}_VERSION_MAJOR}, ${${PROJECT_NAME}_VERSION_MINOR}>() noexcept
|
||||
{
|
||||
return true;
|
||||
}
|
||||
// clang-format on
|
||||
|
||||
// clang-format off
|
||||
template <>
|
||||
bool check_library_version<${${PROJECT_NAME}_VERSION_MAJOR}, ${${PROJECT_NAME}_VERSION_MINOR}, ${${PROJECT_NAME}_VERSION_PATCH}>() noexcept
|
||||
{
|
||||
return true;
|
||||
}
|
||||
// clang-format on
|
||||
|
||||
} // namespace about
|
||||
} // namespace json_schema
|
||||
} // namespace nlohmann
|
||||
43
src/json-schema-version.hpp.in
Normal file
43
src/json-schema-version.hpp.in
Normal file
@ -0,0 +1,43 @@
|
||||
#ifndef NLOHMANN_JSON_SCHEMA_VERSION_HPP__
|
||||
#define NLOHMANN_JSON_SCHEMA_VERSION_HPP__
|
||||
|
||||
#include <nlohmann/json-schema-decl.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace nlohmann
|
||||
{
|
||||
namespace json_schema
|
||||
{
|
||||
namespace about
|
||||
{
|
||||
// clang-format off
|
||||
constexpr int VERSION_MAJOR=${${PROJECT_NAME}_VERSION_MAJOR};
|
||||
constexpr int VERSION_MINOR=${${PROJECT_NAME}_VERSION_MINOR};
|
||||
constexpr int VERSION_PATCH=${${PROJECT_NAME}_VERSION_PATCH};
|
||||
constexpr int VERSION_ID=((VERSION_MAJOR*10000) + (VERSION_MINOR*100) + (VERSION_PATCH));
|
||||
// clang-format on
|
||||
|
||||
// Get library version as string
|
||||
JSON_SCHEMA_VALIDATOR_API const std::string &
|
||||
version_txt();
|
||||
|
||||
// Linker level library version check
|
||||
// Check for library major version only
|
||||
template <int>
|
||||
JSON_SCHEMA_VALIDATOR_API bool check_library_version() noexcept;
|
||||
|
||||
// Linker level library version check
|
||||
// Check for library major/minor version
|
||||
template <int, int>
|
||||
JSON_SCHEMA_VALIDATOR_API bool check_library_version() noexcept;
|
||||
|
||||
// Linker level library version check
|
||||
// Check for library major/minor/patch version
|
||||
template <int, int, int>
|
||||
JSON_SCHEMA_VALIDATOR_API bool check_library_version() noexcept;
|
||||
|
||||
} // namespace about
|
||||
} // namespace json_schema
|
||||
} // namespace nlohmann
|
||||
|
||||
#endif
|
||||
16
src/nlohmann/json-schema-decl.hpp
Normal file
16
src/nlohmann/json-schema-decl.hpp
Normal file
@ -0,0 +1,16 @@
|
||||
#ifndef NLOHMANN_JSON_SCHEMA_DECL_HPP__
|
||||
#define NLOHMANN_JSON_SCHEMA_DECL_HPP__
|
||||
|
||||
#ifdef _WIN32
|
||||
# if defined(JSON_SCHEMA_VALIDATOR_EXPORTS)
|
||||
# define JSON_SCHEMA_VALIDATOR_API __declspec(dllexport)
|
||||
# elif defined(JSON_SCHEMA_VALIDATOR_IMPORTS)
|
||||
# define JSON_SCHEMA_VALIDATOR_API __declspec(dllimport)
|
||||
# else
|
||||
# define JSON_SCHEMA_VALIDATOR_API
|
||||
# endif
|
||||
#else
|
||||
# define JSON_SCHEMA_VALIDATOR_API
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@ -9,17 +9,7 @@
|
||||
#ifndef NLOHMANN_JSON_SCHEMA_HPP__
|
||||
#define NLOHMANN_JSON_SCHEMA_HPP__
|
||||
|
||||
#ifdef _WIN32
|
||||
# if defined(JSON_SCHEMA_VALIDATOR_EXPORTS)
|
||||
# define JSON_SCHEMA_VALIDATOR_API __declspec(dllexport)
|
||||
# elif defined(JSON_SCHEMA_VALIDATOR_IMPORTS)
|
||||
# define JSON_SCHEMA_VALIDATOR_API __declspec(dllimport)
|
||||
# else
|
||||
# define JSON_SCHEMA_VALIDATOR_API
|
||||
# endif
|
||||
#else
|
||||
# define JSON_SCHEMA_VALIDATOR_API
|
||||
#endif
|
||||
#include "json-schema-decl.hpp"
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user