From 8feb76a37f9539752d50d93c2ddc705d921aace6 Mon Sep 17 00:00:00 2001 From: Jochen Topf Date: Wed, 30 Jul 2025 15:41:40 +0200 Subject: [PATCH] Reorganize the way we are printing version numbers To unify the way we print the version number on startup and when using --version for the osm2pgsql and osm2pgsql-gen commands, respectively. Also show more libraries used with --version. --- src/command-line-parser.cpp | 18 ------------------ src/command-line-parser.hpp | 2 -- src/gen/osm2pgsql-gen.cpp | 13 ++++++++++--- src/osm2pgsql.cpp | 2 +- src/version.cpp.in | 23 +++++++++++++++++++++++ src/version.hpp | 3 +++ 6 files changed, 37 insertions(+), 24 deletions(-) diff --git a/src/command-line-parser.cpp b/src/command-line-parser.cpp index 568d9f5f5..51d728d88 100644 --- a/src/command-line-parser.cpp +++ b/src/command-line-parser.cpp @@ -10,7 +10,6 @@ #include "command-line-parser.hpp" #include "command-line-app.hpp" -#include "format.hpp" #include "logging.hpp" #include "options.hpp" #include "pgsql.hpp" @@ -20,12 +19,9 @@ #include "version.hpp" #include -#include #include -#include - #include #include #include @@ -254,20 +250,6 @@ void check_options_expire(options_t *options) { } // anonymous namespace -void print_version() -{ - fmt::print(stderr, "osm2pgsql version {}\n", get_osm2pgsql_version()); - fmt::print(stderr, "Build: {}\n", get_build_type()); - fmt::print(stderr, "Compiled using the following library versions:\n"); - fmt::print(stderr, "Libosmium {}\n", LIBOSMIUM_VERSION_STRING); - fmt::print(stderr, "Proj {}\n", get_proj_version()); -#ifdef HAVE_LUAJIT - fmt::print(stderr, "{} ({})\n", LUA_RELEASE, LUAJIT_VERSION); -#else - fmt::print(stderr, "{}\n", LUA_RELEASE); -#endif -} - // NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) options_t parse_command_line(int argc, char *argv[]) { diff --git a/src/command-line-parser.hpp b/src/command-line-parser.hpp index a3fe81891..0f481d5b2 100644 --- a/src/command-line-parser.hpp +++ b/src/command-line-parser.hpp @@ -15,6 +15,4 @@ // NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) options_t parse_command_line(int argc, char *argv[]); -void print_version(); - #endif // OSM2PGSQL_COMMAND_LINE_PARSER_HPP diff --git a/src/gen/osm2pgsql-gen.cpp b/src/gen/osm2pgsql-gen.cpp index 0be98a874..852fb66da 100644 --- a/src/gen/osm2pgsql-gen.cpp +++ b/src/gen/osm2pgsql-gen.cpp @@ -42,6 +42,10 @@ #include +#include + +#include + #include #include #include @@ -685,13 +689,16 @@ int main(int argc, char *argv[]) return 0; } - log_info("osm2pgsql-gen version {}", get_osm2pgsql_version()); - log_warn("This is an EXPERIMENTAL extension to osm2pgsql."); - if (app.want_version()) { + print_version("osm2pgsql-gen"); + fmt::print(stderr, "OpenCV {}\n", CV_VERSION); + fmt::print(stderr, "{}\n", potrace_version()); return 0; } + log_info("osm2pgsql-gen version {}", get_osm2pgsql_version()); + log_warn("This is an EXPERIMENTAL extension to osm2pgsql."); + if (dbschema.empty()) { log_error("Schema must not be empty"); return 2; diff --git a/src/osm2pgsql.cpp b/src/osm2pgsql.cpp index 10960162e..3fc355dca 100644 --- a/src/osm2pgsql.cpp +++ b/src/osm2pgsql.cpp @@ -339,7 +339,7 @@ int main(int argc, char *argv[]) } if (options.command == command_t::version) { - print_version(); + print_version("osm2pgsql"); return 0; } diff --git a/src/version.cpp.in b/src/version.cpp.in index f560d4a39..a02c364f6 100644 --- a/src/version.cpp.in +++ b/src/version.cpp.in @@ -7,8 +7,16 @@ * For a full list of authors see the git log. */ +#include "format.hpp" +#include "reprojection.hpp" #include "version.hpp" +#include + +#include + +#include + char const *get_build_type() noexcept { return "@CMAKE_BUILD_TYPE@"; @@ -34,3 +42,18 @@ uint32_t get_minimum_postgresql_server_version_num() noexcept return @MINIMUM_POSTGRESQL_SERVER_VERSION_NUM@; } +void print_version(std::string const &command) +{ + fmt::print(stderr, "{} version {}\n", command, get_osm2pgsql_version()); + fmt::print(stderr, "Build: {}\n", get_build_type()); + fmt::print(stderr, "Compiled using the following library versions:\n"); + fmt::print(stderr, "Libosmium {}\n", LIBOSMIUM_VERSION_STRING); + fmt::print(stderr, "Proj {}\n", get_proj_version()); + fmt::print(stderr, "nlohmann JSON {}.{}.{}\n", NLOHMANN_JSON_VERSION_MAJOR, + NLOHMANN_JSON_VERSION_MINOR, NLOHMANN_JSON_VERSION_PATCH); +#ifdef HAVE_LUAJIT + fmt::print(stderr, "{} ({})\n", LUA_RELEASE, LUAJIT_VERSION); +#else + fmt::print(stderr, "{}\n", LUA_RELEASE); +#endif +} diff --git a/src/version.hpp b/src/version.hpp index d545b2912..c4eeec53c 100644 --- a/src/version.hpp +++ b/src/version.hpp @@ -11,6 +11,7 @@ */ #include +#include char const *get_build_type() noexcept; char const *get_osm2pgsql_version() noexcept; @@ -18,4 +19,6 @@ char const *get_osm2pgsql_short_version() noexcept; char const *get_minimum_postgresql_server_version() noexcept; uint32_t get_minimum_postgresql_server_version_num() noexcept; +void print_version(std::string const &command); + #endif // OSM2PGSQL_VERSION_HPP