Skip to content

Commit

Permalink
cmake/Version.cmake: Fix version detection when building from zipfile…
Browse files Browse the repository at this point in the history
… (non-git tree). Fixes #523
  • Loading branch information
Jerry Jacobs committed Dec 5, 2016
1 parent 3de5cf0 commit 0c63a2c
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions cmake/Version.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ if (GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git")
if (res EQUAL 1)
set (PROJECT_VERSION "${PROJECT_VERSION}-dirty")
endif()
endif()

string(REGEX REPLACE "^(0|[1-9][0-9]*)[.](0|[1-9][0-9]*)[.](0|[1-9][0-9]*)(-[.0-9A-Za-z-]+)?([+][.0-9A-Za-z-]+)?$"
"\\1;\\2;\\3" PROJECT_VERSION_LIST ${PROJECT_VERSION})
list(LENGTH PROJECT_VERSION_LIST len)
if(len EQUAL 3)
list(GET PROJECT_VERSION_LIST 0 PROJECT_VERSION_MAJOR)
list(GET PROJECT_VERSION_LIST 1 PROJECT_VERSION_MINOR)
list(GET PROJECT_VERSION_LIST 2 PROJECT_VERSION_PATCH)
string(REGEX REPLACE "^(0|[1-9][0-9]*)[.](0|[1-9][0-9]*)[.](0|[1-9][0-9]*)(-[.0-9A-Za-z-]+)?([+][.0-9A-Za-z-]+)?$"
"\\1;\\2;\\3" PROJECT_VERSION_LIST ${PROJECT_VERSION})
list(LENGTH PROJECT_VERSION_LIST len)
if(len EQUAL 3)
list(GET PROJECT_VERSION_LIST 0 PROJECT_VERSION_MAJOR)
list(GET PROJECT_VERSION_LIST 1 PROJECT_VERSION_MINOR)
list(GET PROJECT_VERSION_LIST 2 PROJECT_VERSION_PATCH)
endif()
elseif(EXISTS ${PROJECT_SOURCE_DIR}/.version)
# If git is not available (e.g. when building from source package)
# we can extract the package version from .version file.
Expand All @@ -44,7 +44,5 @@ else()
message(FATAL_ERROR "Unable to determine project version")
endif()

if (${CMAKE_BUILD_TYPE} MATCHES "Debug")
message(STATUS "stlink version: ${PROJECT_VERSION}")
message(STATUS " Major ${PROJECT_VERSION_MAJOR} Minor ${PROJECT_VERSION_MINOR} Patch ${PROJECT_VERSION_PATCH}")
endif()
message(STATUS "stlink version: ${PROJECT_VERSION}")
message(STATUS " Major ${PROJECT_VERSION_MAJOR} Minor ${PROJECT_VERSION_MINOR} Patch ${PROJECT_VERSION_PATCH}")

0 comments on commit 0c63a2c

Please sign in to comment.