Skip to content

Commit ff35afd

Browse files
committed
Add appropriate project version evaluation
Signed-off-by: Cristian Le <[email protected]>
1 parent 60603f6 commit ff35afd

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

src/CMakeLists.txt

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@ target_sources(nlohmann_json_schema_validator PRIVATE
88
)
99
target_sources(nlohmann_json_schema_validator_cli PRIVATE
1010
cli.cpp)
11+
configure_file(nlohmann/json-schema.hpp.in nlohmann/json-schema.hpp)
1112

1213
target_include_directories(nlohmann_json_schema_validator PUBLIC
1314
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
1415
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
16+
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
1517
)
1618
set_target_properties(nlohmann_json_schema_validator PROPERTIES
17-
PUBLIC_HEADER nlohmann/json-schema.hpp)
19+
PUBLIC_HEADER ${CMAKE_CURRENT_BINARY_DIR}/nlohmann/json-schema.hpp)
1820
target_link_libraries(nlohmann_json_schema_validator_cli PRIVATE
1921
nlohmann_json_schema_validator CLI11::CLI11)
2022

src/cli.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ using namespace nlohmann::json_schema;
1010

1111
class main_cli : public CLI::App
1212
{
13+
std::string version;
1314
std::ifstream schema_input;
1415
std::filesystem::path object_path;
1516
// TODO: Export this as a built-in loader
@@ -34,10 +35,10 @@ class main_cli : public CLI::App
3435
: CLI::App{"Json schema validator", "json-validator"},
3536
validator{
3637
[this](const json_uri &u, json &s) { this->loader(u, s); },
37-
default_string_format_check}
38+
default_string_format_check},
39+
version{nlohmann::json_schema::version}
3840
{
39-
// TODO: Move to a generated header file
40-
set_version_flag("--version", "2.2.0");
41+
set_version_flag("--version", version);
4142
add_option("schema", schema_input, "JSON schema of the object")
4243
->check(CLI::ExistingFile);
4344
add_option("object", object_path, "JSON object to validate")

src/nlohmann/json-schema.hpp renamed to src/nlohmann/json-schema.hpp.in

+2
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ class JSON_SCHEMA_VALIDATOR_API json_uri
128128
namespace json_schema
129129
{
130130

131+
constexpr std::string_view version = "@PROJECT_VERSION@";
132+
131133
extern json draft7_schema_builtin;
132134

133135
typedef std::function<void(const json_uri & /*id*/, json & /*value*/)> schema_loader;

0 commit comments

Comments
 (0)