aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMauro Sardara <msardara@cisco.com>2019-10-22 12:01:54 +0200
committerMauro Sardara <msardara@cisco.com>2019-10-22 12:01:54 +0200
commit7429211aee3daa4227e10d2541920c0dea785191 (patch)
tree21dc0f5a1075d33dc42e34d880f086589253aff4
parent49b9891dc32ea1fbd0af4711a200b425c7482da0 (diff)
[HICN-346] Add version of the transport library in the config.h header file.
Change-Id: I1ce0b705db98f4042470a7b80b422720ba03c0f6 Signed-off-by: Mauro Sardara <msardara@cisco.com>
-rw-r--r--cmake/Modules/Packager.cmake49
-rw-r--r--libtransport/src/hicn/transport/CMakeLists.txt2
-rw-r--r--libtransport/src/hicn/transport/config.h.in4
3 files changed, 40 insertions, 15 deletions
diff --git a/cmake/Modules/Packager.cmake b/cmake/Modules/Packager.cmake
index 898e40bcb..6f77fd3a8 100644
--- a/cmake/Modules/Packager.cmake
+++ b/cmake/Modules/Packager.cmake
@@ -33,10 +33,35 @@ function(get_next_version VERSION NEXT_VERSION)
math(EXPR major "${major} + 1")
endif()
- set(minor "0${minor}")
+ if (minor LESS 10)
+ set(minor "0${minor}")
+ endif()
+
set(${NEXT_VERSION} "${major}.${minor}" PARENT_SCOPE)
endfunction()
+macro(extract_version)
+ # Extract version from git
+ execute_process(
+ COMMAND git describe --long --match v*
+ WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
+ OUTPUT_VARIABLE VER
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ )
+
+ if (NOT VER)
+ set(VER "v1.0-0-gcafe")
+ endif()
+
+ message(STATUS "Git describe output: ${VER}")
+
+ string(REGEX REPLACE "v([0-9]+).([0-9]+)-([0-9]+)-(g[0-9a-f]+)" "\\1;\\2;\\3;\\4" VER ${VER})
+ list(GET VER 0 VERSION_MAJOR)
+ list(GET VER 1 VERSION_MINOR)
+ list(GET VER 2 VERSION_REVISION)
+ list(GET VER 3 COMMIT_NAME)
+endmacro(extract_version)
+
macro(make_packages)
if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
# parse /etc/os-release
@@ -49,23 +74,17 @@ macro(make_packages)
set(OS_${_name} ${_value})
endforeach()
- # extract version from git
- execute_process(
- COMMAND git describe --long --match v*
- WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
- OUTPUT_VARIABLE VER
- OUTPUT_STRIP_TRAILING_WHITESPACE
- )
+ extract_version()
- if (NOT VER)
- set(VER "v1.0-1-gcafe")
- endif()
+ message(STATUS "Version major: ${VERSION_MAJOR}")
+ message(STATUS "Version minor: ${VERSION_MINOR}")
+ message(STATUS "Revision: ${VERSION_REVISION}")
+ message(STATUS "Commit hash: ${COMMIT_NAME}")
- string(REGEX REPLACE "v(.*)-([0-9]+)-(g[0-9a-f]+)" "\\1;\\2;\\3" VER ${VER})
- list(GET VER 0 tag)
+ set(tag "${VERSION_MAJOR}.${VERSION_MINOR}")
string(REPLACE "-" "~" tag ${tag})
- list(GET VER 1 commit_num)
- list(GET VER 2 commit_name)
+ set(commit_num ${VERSION_REVISION})
+ set(commit_name ${COMMIT_NAME})
if (NOT DEFINED ENV{BUILD_NUMBER})
set(bld "b1")
diff --git a/libtransport/src/hicn/transport/CMakeLists.txt b/libtransport/src/hicn/transport/CMakeLists.txt
index 6e0ae5b88..22acdcb7f 100644
--- a/libtransport/src/hicn/transport/CMakeLists.txt
+++ b/libtransport/src/hicn/transport/CMakeLists.txt
@@ -25,6 +25,8 @@ add_subdirectory(portability)
add_subdirectory(protocols)
add_subdirectory(utils)
+include(Packager)
+extract_version()
configure_file("config.h.in" "config.h" @ONLY)
install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/config.h
diff --git a/libtransport/src/hicn/transport/config.h.in b/libtransport/src/hicn/transport/config.h.in
index 7d47c2b3f..ef47affda 100644
--- a/libtransport/src/hicn/transport/config.h.in
+++ b/libtransport/src/hicn/transport/config.h.in
@@ -17,6 +17,10 @@
#cmakedefine TRANSPORT_HAVE_PTHREAD 1
+#define HICNTRANSPORT_VERSION_MAJOR "@VERSION_MAJOR@"
+#define HICNTRANSPORT_VERSION_MINOR "@VERSION_MINOR@"
+#define HICNTRANSPORT_VERSION_REVISION "@VERSION_REVISION@"
+
#ifndef ASIO_STANDALONE
#cmakedefine ASIO_STANDALONE
#endif