Skip to content

Commit

Permalink
Update version string setting proceedure
Browse files Browse the repository at this point in the history
Package maintainers can override the git repo detection by providing
their own release version string using cmake -DRELEASE_STRING="you_version"
For all other users we check for a git repo and default to the last release
version string if none is found
  • Loading branch information
dominicgs committed Mar 13, 2017
1 parent ed5d4f1 commit 1b6084d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 25 deletions.
55 changes: 32 additions & 23 deletions cmake/set_release.cmake
Original file line number Diff line number Diff line change
@@ -1,26 +1,35 @@
set(LATEST_RELEASE "2017-03-R2")
# This script controls the version string that is passed at compile time.
# To override the version, use cmake -DRELEASE_STRING="you_version"
# If RELEASE_STRING is not explicitly set we attempt to use the latest git
# commit. If cmake isn't being run from within a git repository we use the
# LATEST_RELEASE variable, which developers should set before a release is
# tagged

if(NOT DEFINED RELEASE_STRING)
set(LATEST_RELEASE "2017-03-R2")

execute_process(
COMMAND git log -n 1 --format=%h
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
RESULT_VARIABLE GIT_EXIT_ERROR
ERROR_QUIET
OUTPUT_VARIABLE GIT_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if (GIT_EXIT_ERROR)
# We're probably not in a git repo
set(RELEASE ${LATEST_RELEASE})
else (GIT_EXIT_ERROR)
# We're in a git repo
execute_process(
COMMAND git status -s --untracked-files=no
OUTPUT_VARIABLE DIRTY
COMMAND git log -n 1 --format=%h
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
RESULT_VARIABLE GIT_EXIT_ERROR
ERROR_QUIET
OUTPUT_VARIABLE GIT_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if ( NOT "${DIRTY}" STREQUAL "" )
set(DIRTY_FLAG "*")
else()
set(DIRTY_FLAG "")
endif()
set(RELEASE "git-${GIT_VERSION}${DIRTY_FLAG}")
endif (GIT_EXIT_ERROR)
if (GIT_EXIT_ERROR)
# We're probably not in a git repo
set(RELEASE_STRING ${LATEST_RELEASE})
else (GIT_EXIT_ERROR)
# We're in a git repo
execute_process(
COMMAND git status -s --untracked-files=no
OUTPUT_VARIABLE DIRTY
)
if ( NOT "${DIRTY}" STREQUAL "" )
set(DIRTY_FLAG "*")
else()
set(DIRTY_FLAG "")
endif()
set(RELEASE_STRING "git-${GIT_VERSION}${DIRTY_FLAG}")
endif (GIT_EXIT_ERROR)
endif(NOT DEFINED RELEASE_STRING)
4 changes: 2 additions & 2 deletions lib/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
# Based slightly upon the hackrf cmake setup.

include(${PROJECT_SOURCE_DIR}/../cmake/set_release.cmake)
add_definitions( -DRELEASE="${RELEASE}" )
message(STATUS "Setting version string ${RELEASE}")
add_definitions( -DRELEASE="${RELEASE_STRING}" )
message(STATUS "Setting version string ${RELEASE_STRING}")

# Source
set(c_sources ${CMAKE_CURRENT_SOURCE_DIR}/bluetooth_packet.c
Expand Down

0 comments on commit 1b6084d

Please sign in to comment.