From 86f4a1c97d7bfe459027d63b8caf8240830fef30 Mon Sep 17 00:00:00 2001 From: prmoore77 Date: Mon, 4 Mar 2024 13:05:22 -0500 Subject: [PATCH] Making application version driven by the git tag --- CMakeLists.txt | 24 ++++++++++++++++++++++++ src/library/include/.gitignore | 1 + src/library/include/flight_sql_library.h | 3 ++- src/library/include/version.h.in | 8 ++++++++ 4 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 src/library/include/.gitignore create mode 100644 src/library/include/version.h.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 081abf1..16ad708 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,6 +3,30 @@ project(flight_sql) set(CMAKE_CXX_STANDARD 17) +# Function to retrieve the latest Git tag +function(get_latest_git_tag OUTPUT_VARIABLE) + execute_process( + COMMAND git describe --tags --abbrev=0 + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + OUTPUT_VARIABLE RETURN_VALUE + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + set(${OUTPUT_VARIABLE} ${RETURN_VALUE} PARENT_SCOPE) +endfunction() + +# Set the version +get_latest_git_tag(LATEST_TAG) +set(PROJECT_VERSION ${LATEST_TAG}) + +# Display variable values using message +message(STATUS "PROJECT_VERSION: ${PROJECT_VERSION}") + +# Configure a header file with the version +configure_file( + ${CMAKE_SOURCE_DIR}/src/library/include/version.h.in + ${CMAKE_SOURCE_DIR}/src/library/include/version.h +) + # --------------------- Arrow --------------------- configure_file(third_party/Arrow_CMakeLists.txt.in arrow/CMakeLists.txt) execute_process(COMMAND "${CMAKE_COMMAND}" -G "${CMAKE_GENERATOR}" . diff --git a/src/library/include/.gitignore b/src/library/include/.gitignore new file mode 100644 index 0000000..6702033 --- /dev/null +++ b/src/library/include/.gitignore @@ -0,0 +1 @@ +version.h diff --git a/src/library/include/flight_sql_library.h b/src/library/include/flight_sql_library.h index e453453..4cb7ec0 100644 --- a/src/library/include/flight_sql_library.h +++ b/src/library/include/flight_sql_library.h @@ -2,9 +2,10 @@ #pragma once #include +#include "version.h" // Constants -const std::string FLIGHT_SQL_SERVER_VERSION = "v1.2.3"; // For now - be sure to update this version with the git tag! TODO: automate this +const std::string FLIGHT_SQL_SERVER_VERSION = PROJECT_VERSION; const std::string DEFAULT_FLIGHT_HOSTNAME = "0.0.0.0"; const std::string DEFAULT_FLIGHT_USERNAME = "flight_username"; const int DEFAULT_FLIGHT_PORT = 31337; diff --git a/src/library/include/version.h.in b/src/library/include/version.h.in new file mode 100644 index 0000000..ca73219 --- /dev/null +++ b/src/library/include/version.h.in @@ -0,0 +1,8 @@ +// version.h.in +// This file is used by CMake to generate version.h +#ifndef PROJECT_VERSION_H +#define PROJECT_VERSION_H + +#define PROJECT_VERSION "@PROJECT_VERSION@" + +#endif // PROJECT_VERSION_H