diff --git a/.gitignore b/.gitignore index f76fdb680..2e247ec75 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,4 @@ gens .vscode __pycache__/ .venv +/generated/version.h diff --git a/CMakeLists.txt b/CMakeLists.txt index fac1027ee..c0934dd63 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -425,6 +425,13 @@ if(WIN32) ) endif() +execute_process( + COMMAND git rev-parse --abbrev-ref HEAD + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + OUTPUT_VARIABLE GIT_BRANCH + OUTPUT_STRIP_TRAILING_WHITESPACE +) + # Generate version header file # This file requires product name and version info that mako does not know, but CMake does configure_file( diff --git a/generated/version.h b/generated/version.h deleted file mode 100644 index cf2b266ab..000000000 --- a/generated/version.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef NIDEVICE_GRPC_VERSION_H -#define NIDEVICE_GRPC_VERSION_H - -namespace nidevice_grpc { - -static constexpr const char* kNiDeviceGrpcFileVersion = "2.5.0.0"; -static constexpr const char* kNiDeviceGrpcOriginalFileName = "ni_grpc_device_server.exe"; - -} - -#endif // NIDEVICE_GRPC_VERSION_H diff --git a/source/server/core_server.cpp b/source/server/core_server.cpp index 8d5b4dd84..3c97a1451 100644 --- a/source/server/core_server.cpp +++ b/source/server/core_server.cpp @@ -17,6 +17,8 @@ #include "windows/console_ctrl_handler.h" #endif +#include "version.h" + using FeatureState = nidevice_grpc::FeatureToggles::FeatureState; struct ServerConfiguration { @@ -185,6 +187,17 @@ Options parse_options(int argc, char** argv) nidevice_grpc::logging::log(nidevice_grpc::logging::Level_Info, usage); exit(EXIT_SUCCESS); } + else if (strcmp("--version", argv[i]) == 0) { + std::string string_kNiDeviceGrpcBranchName(nidevice_grpc::kNiDeviceGrpcBranchName); + if (string_kNiDeviceGrpcBranchName.rfind("releases", 0) == 0) { + nidevice_grpc::logging::log(nidevice_grpc::logging::Level_Info, nidevice_grpc::kNiDeviceGrpcFileVersion); + } + else { + nidevice_grpc::logging::log(nidevice_grpc::logging::Level_Info, nidevice_grpc::kNiDeviceGrpcFileVersion); + nidevice_grpc::logging::log(nidevice_grpc::logging::Level_Info, "dev"); + } + exit(EXIT_SUCCESS); + } else if (i == argc - 1) { options.config_file_path = argv[i]; } diff --git a/source/server/version.h.in b/source/server/version.h.in index d50bb4d9a..82eae2d85 100644 --- a/source/server/version.h.in +++ b/source/server/version.h.in @@ -5,6 +5,7 @@ namespace nidevice_grpc { static constexpr const char* kNiDeviceGrpcFileVersion = "@PROJECT_VERSION_MAJOR@.@PROJECT_VERSION_MINOR@.@PROJECT_VERSION_PATCH@.0"; static constexpr const char* kNiDeviceGrpcOriginalFileName = "ni_grpc_device_server.exe"; +static constexpr const char* kNiDeviceGrpcBranchName = "@GIT_BRANCH@"; }