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

Don't require git for version.h, autoformat, use project version from CMakeLists.txt #38

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
28 changes: 8 additions & 20 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.14)
project(novatel-edie)
project(novatel-edie VERSION 3.3.7)

enable_testing()

Expand Down Expand Up @@ -69,25 +69,13 @@ set(CMAKE_INSTALL_PREFIX "${CMAKE_CURRENT_SOURCE_DIR}")
FetchContent_Declare(googletest URL https://github.com/google/googletest/archive/refs/tags/v1.14.0.zip)
FetchContent_MakeAvailable(googletest)

# Find Git package, if not need to install manually or through .yml file
find_package(Git)
if(NOT Git_FOUND)
message(FATAL_ERROR "Git was not found. Install Git and make sure it is in your PATH.")
endif()

if(NOT DEFINED GIT_BRANCH)
set(GIT_BRANCH "main")
endif()

# Build version of EDIE through cmake
if(GIT_EXECUTABLE)
execute_process(COMMAND ${CMAKE_COMMAND}
-D SRC=${CMAKE_CURRENT_SOURCE_DIR}/src/version.h.in
-D DST=${CMAKE_CURRENT_SOURCE_DIR}/src/version.h
-D GIT_EXECUTABLE=${GIT_EXECUTABLE}
-D GIT_BRANCH=${GIT_BRANCH}
-P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/GenerateVersionHeader.cmake)
endif()
# Create src/version.h based on CMake project and git versions
execute_process(COMMAND ${CMAKE_COMMAND}
-D SRC=${CMAKE_CURRENT_SOURCE_DIR}/src/version.h.in
-D DST=${CMAKE_CURRENT_SOURCE_DIR}/src/version.h
-D PROJECT_VERSION=${PROJECT_VERSION}
-P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/GenerateVersionHeader.cmake
)

include_directories(
${CMAKE_CURRENT_SOURCE_DIR}
Expand Down
4 changes: 2 additions & 2 deletions cmake/GenerateVersionHeader.cmake
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
get_filename_component(SRC_DIR ${SRC} DIRECTORY)

# Generate a git-describe version string from Git repository tags

find_package(Git)
if(GIT_EXECUTABLE AND NOT DEFINED VERSION)

execute_process(
Expand Down Expand Up @@ -97,7 +97,7 @@ if(NOT DEFINED GIT_BRANCH)
endif()

if(NOT DEFINED GIT_IS_DIRTY)
set(GIT_IS_DIRTY FALSE)
set(GIT_IS_DIRTY "false")
message(WARNING "Failed to determine GIT_IS_DIRTY from repository tags. Using default version \"${GIT_IS_DIRTY}\".")
endif()

Expand Down
45 changes: 12 additions & 33 deletions src/version.h.in
Original file line number Diff line number Diff line change
@@ -1,45 +1,24 @@
#include <string>
#include <string.h>

#define RELEASE_VERSION "3.3.7"
#define RELEASE_VERSION "@PROJECT_VERSION@"
#define GIT_SHA "@GIT_SHA@"
#define GIT_BRANCH "@GIT_BRANCH@"
#define GIT_IS_DIRTY @GIT_IS_DIRTY@
#define BUILD_TIMESTAMP "@BUILD_TIMESTAMP@"

constexpr const char* get_version()
{
return RELEASE_VERSION;
}
constexpr const char* get_version() { return RELEASE_VERSION; }

constexpr const char* get_git_sha()
{
return GIT_SHA;
}
constexpr const char* get_git_sha() { return GIT_SHA; }

constexpr const char* get_git_branch()
{
return GIT_BRANCH;
}
constexpr const char* get_git_branch() { return GIT_BRANCH; }

constexpr bool get_git_is_dirty()
{
return GIT_IS_DIRTY;
}
constexpr bool get_git_is_dirty() { return GIT_IS_DIRTY; }

constexpr const char* get_build_timestamp()
{
return BUILD_TIMESTAMP;
}
constexpr const char* get_build_timestamp() { return BUILD_TIMESTAMP; }

constexpr const char* caPrettyPrint = []
{
return GIT_IS_DIRTY
? "Version: " RELEASE_VERSION "-Dirty\nBranch: " GIT_BRANCH "\nSHA: " GIT_SHA
: "Version: " RELEASE_VERSION "\nBranch: " GIT_BRANCH "\nSHA: " GIT_SHA;
constexpr const char* caPrettyPrint = [] {
bool git_is_available = get_git_branch()[0] != '\0';
return git_is_available ? "Version: " RELEASE_VERSION
: GIT_IS_DIRTY ? "Version: " RELEASE_VERSION "-Dirty\nBranch: " GIT_BRANCH "\nSHA: " GIT_SHA
: "Version: " RELEASE_VERSION "\nBranch: " GIT_BRANCH "\nSHA: " GIT_SHA;
}();

constexpr const char* get_pretty_version()
{
return caPrettyPrint;
}
constexpr const char* get_pretty_version() { return caPrettyPrint; }