Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added --version switch to pull both github and CMake version information as well as log the Version info into the log file #688

Merged
merged 3 commits into from
May 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,20 @@
########################################################################

cmake_minimum_required(VERSION 3.2)
project(Trunk-Recorder CXX C)
project(Trunk-Recorder LANGUAGES CXX C VERSION "4.3.2")

configure_file(cmake.h.in "${PROJECT_SOURCE_DIR}/cmake.h" @ONLY)

# Define the two required variables before including
# the source code for watching a git repository.
set(PRE_CONFIGURE_FILE "git.cc.in")
set(POST_CONFIGURE_FILE "${CMAKE_CURRENT_BINARY_DIR}/git.cc")
include(git_watcher.cmake)

# Create a library out of the compiled post-configure file.
add_library(git ${POST_CONFIGURE_FILE})
target_include_directories(git PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
add_dependencies(git check_git)

# Select the release build type by default to get optimization flags
if(NOT CMAKE_BUILD_TYPE)
Expand Down Expand Up @@ -324,7 +337,7 @@ add_subdirectory(plugins/simplestream)

add_executable(trunk-recorder trunk-recorder/main.cc ${trunk_recorder_sources})

target_link_libraries(trunk-recorder trunk_recorder_library gnuradio-op25_repeater ${CMAKE_DL_LIBS} ssl crypto ${CURL_LIBRARIES} ${Boost_LIBRARIES} ${GNURADIO_PMT_LIBRARIES} ${GNURADIO_RUNTIME_LIBRARIES} ${GNURADIO_FILTER_LIBRARIES} ${GNURADIO_DIGITAL_LIBRARIES} ${GNURADIO_ANALOG_LIBRARIES} ${GNURADIO_AUDIO_LIBRARIES} ${GNURADIO_UHD_LIBRARIES} ${UHD_LIBRARIES} ${GNURADIO_BLOCKS_LIBRARIES} ${GNURADIO_OSMOSDR_LIBRARIES} ) # gRPC::grpc++_reflection protobuf::libprotobuf)
target_link_libraries(trunk-recorder git trunk_recorder_library gnuradio-op25_repeater ${CMAKE_DL_LIBS} ssl crypto ${CURL_LIBRARIES} ${Boost_LIBRARIES} ${GNURADIO_PMT_LIBRARIES} ${GNURADIO_RUNTIME_LIBRARIES} ${GNURADIO_FILTER_LIBRARIES} ${GNURADIO_DIGITAL_LIBRARIES} ${GNURADIO_ANALOG_LIBRARIES} ${GNURADIO_AUDIO_LIBRARIES} ${GNURADIO_UHD_LIBRARIES} ${UHD_LIBRARIES} ${GNURADIO_BLOCKS_LIBRARIES} ${GNURADIO_OSMOSDR_LIBRARIES} ) # gRPC::grpc++_reflection protobuf::libprotobuf)

message(STATUS "All libraries:" ${GNURADIO_ALL_LIBRARIES})
if(NOT Gnuradio_VERSION VERSION_LESS "3.8")
Expand Down
10 changes: 10 additions & 0 deletions cmake.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifndef INCLUDE_GUARD
#define INCLUDE_GUARD

#define PROJECT_NAME "Trunk-Recorder"
#define PROJECT_VER "4.3.2"
#define PROJECT_VER_MAJOR "4"
#define PROJECT_VER_MINOR "3"
#define PTOJECT_VER_PATCH "2"

#endif // INCLUDE_GUARD
10 changes: 10 additions & 0 deletions cmake.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifndef INCLUDE_GUARD
#define INCLUDE_GUARD

#define PROJECT_NAME "@PROJECT_NAME@"
#define PROJECT_VER "@PROJECT_VERSION@"
#define PROJECT_VER_MAJOR "@PROJECT_VERSION_MAJOR@"
#define PROJECT_VER_MINOR "@PROJECT_VERSION_MINOR@"
#define PTOJECT_VER_PATCH "@PROJECT_VERSION_PATCH@"

#endif // INCLUDE_GUARD
56 changes: 56 additions & 0 deletions git.cc.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#include <cstdlib>
#include <iostream>

#include "git.h"
#include "cmake.h"

const char *version = "version info:\n";

bool GitMetadata::Populated() {
return @GIT_RETRIEVED_STATE@;
}
bool GitMetadata::AnyUncommittedChanges() {
return @GIT_IS_DIRTY@;
}
std::string GitMetadata::AuthorName() {
return "@GIT_AUTHOR_NAME@";
}
std::string GitMetadata::AuthorEmail() {
return "@GIT_AUTHOR_EMAIL@";
}
std::string GitMetadata::CommitSHA1() {
return "@GIT_HEAD_SHA1@";
}
std::string GitMetadata::CommitDate() {
return "@GIT_COMMIT_DATE_ISO8601@";
}
std::string GitMetadata::CommitSubject() {
return "@GIT_COMMIT_SUBJECT@";
}
std::string GitMetadata::CommitBody() {
return "@GIT_COMMIT_BODY@";
}
std::string GitMetadata::Describe() {
return "@GIT_DESCRIBE@";
}
std::string GitMetadata::Branch() {
return "@GIT_BRANCH@";
}
void GitMetadata::VersionInfo() {
std::cout << PROJECT_NAME << ": " << PROJECT_VER << std::endl;

if(GitMetadata::Populated()) {
if(GitMetadata::AnyUncommittedChanges()) {
std::cerr << "\t" << "WARN: there were uncommitted changes at build-time." << std::endl;
}
std::cout << "\t" << "commit " << GitMetadata::CommitSHA1() << " (" << GitMetadata::Branch() << ")\n"
<< "\t" << "describe " << GitMetadata::Describe() << "\n"
<< "\t" << "Author: " << GitMetadata::AuthorName() << " <" << GitMetadata::AuthorEmail() << ">\n"
<< "\t" << "Date: " << GitMetadata::CommitDate() << "\n\n"
<< "\t" << GitMetadata::CommitSubject() << "\n" << GitMetadata::CommitBody() << std::endl;
}
else {
std::cerr << "WARN: failed to get the current git state. Is this a git repo?" << std::endl;
}
}

33 changes: 33 additions & 0 deletions git.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#pragma once
#include <string>

class GitMetadata {
public:
// Is the metadata populated? We may not have metadata if
// there wasn't a .git directory (e.g. downloaded source
// code without revision history).
static bool Populated();

// Were there any uncommitted changes that won't be reflected
// in the CommitID?
static bool AnyUncommittedChanges();

// The commit author's name.
static std::string AuthorName();
// The commit author's email.
static std::string AuthorEmail();
// The commit SHA1.
static std::string CommitSHA1();
// The ISO8601 commit date.
static std::string CommitDate();
// The commit subject.
static std::string CommitSubject();
// The commit body.
static std::string CommitBody();
// The commit describe.
static std::string Describe();
// The symbolic reference tied to HEAD.
static std::string Branch();
// dump
static void VersionInfo();
};
Loading