Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generate version.h with git branch and commit hash (#2793)
* Generate version.h on every build and include git hash and branch/tag name * Don't generate "alpha" postfix on buildfarm * Show git version via moveit_version * Change version postfix: alpha -> devel Co-authored-by: Robert Haschke <rhaschke@techfak.uni-bielefeld.de>
- Loading branch information
1 parent
0a0fc56
commit 9225971
Showing
5 changed files
with
80 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,30 @@ | ||
# Generate and install version.h | ||
|
||
if(NOT "$ENV{USER}" STREQUAL "buildfarm") # Don't define version postfix on buildfarm | ||
set(MOVEIT_VERSION_EXTRA "devel" CACHE STRING "version string postfix") | ||
endif() | ||
|
||
message(STATUS " *** Building MoveIt ${${PROJECT_NAME}_VERSION} ${MOVEIT_VERSION_EXTRA} ***") | ||
|
||
# https://stackoverflow.com/questions/13920072/how-to-always-run-command-when-building-regardless-of-any-dependency | ||
add_custom_command( | ||
OUTPUT ${VERSION_FILE_PATH}/moveit/version.h always_rebuild | ||
COMMAND ${CMAKE_COMMAND} | ||
-DVERSION_FILE_PATH="${VERSION_FILE_PATH}" | ||
-DMOVEIT_VERSION="${${PROJECT_NAME}_VERSION}" | ||
-DMOVEIT_VERSION_EXTRA="${MOVEIT_VERSION_EXTRA}" | ||
-P ${CMAKE_CURRENT_SOURCE_DIR}/version.cmake | ||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} | ||
) | ||
|
||
add_custom_target(version_h | ||
DEPENDS always_rebuild | ||
COMMENT "Generating version.h" | ||
) | ||
|
||
add_executable(moveit_version version.cpp) | ||
add_dependencies(moveit_version version_h) | ||
|
||
# catkin_lint: ignore_once external_file | ||
install(FILES "${VERSION_FILE_PATH}/moveit/version.h" DESTINATION ${CATKIN_GLOBAL_INCLUDE_DESTINATION}/moveit) | ||
install(TARGETS moveit_version RUNTIME DESTINATION ${CATKIN_GLOBAL_BIN_DESTINATION}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Retrieve (active) branch name | ||
execute_process( | ||
COMMAND git rev-parse --abbrev-ref HEAD | ||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} | ||
OUTPUT_VARIABLE MOVEIT_GIT_NAME | ||
OUTPUT_STRIP_TRAILING_WHITESPACE | ||
ERROR_QUIET | ||
) | ||
|
||
if("${MOVEIT_GIT_NAME}" STREQUAL "HEAD") | ||
# Retrieve any associated name (tag or branch) | ||
execute_process( | ||
COMMAND git describe --contains --all HEAD | ||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} | ||
OUTPUT_VARIABLE MOVEIT_GIT_NAME | ||
OUTPUT_STRIP_TRAILING_WHITESPACE | ||
ERROR_QUIET | ||
) | ||
endif() | ||
|
||
# Retrieve (short) commit hash | ||
execute_process( | ||
COMMAND git rev-parse --short HEAD | ||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} | ||
OUTPUT_VARIABLE MOVEIT_GIT_COMMIT_HASH | ||
OUTPUT_STRIP_TRAILING_WHITESPACE | ||
ERROR_QUIET | ||
) | ||
|
||
string(REGEX REPLACE "^([0-9]+)\\..*" "\\1" MOVEIT_VERSION_MAJOR "${MOVEIT_VERSION}") | ||
string(REGEX REPLACE "^[0-9]+\\.([0-9]+).*" "\\1" MOVEIT_VERSION_MINOR "${MOVEIT_VERSION}") | ||
string(REGEX REPLACE "^[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" MOVEIT_VERSION_PATCH "${MOVEIT_VERSION}") | ||
set(MOVEIT_VERSION "${MOVEIT_VERSION_MAJOR}.${MOVEIT_VERSION_MINOR}.${MOVEIT_VERSION_PATCH}") | ||
|
||
if(NOT "${MOVEIT_VERSION_EXTRA}" STREQUAL "") | ||
string(APPEND MOVEIT_VERSION "-${MOVEIT_VERSION_EXTRA}") | ||
endif() | ||
|
||
configure_file("version.h.in" "${VERSION_FILE_PATH}/moveit/version.h") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters