Skip to content
Merged
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
37 changes: 33 additions & 4 deletions system_modules/CMUTIL_VERSION.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,39 @@ ENDFUNCTION()

##
#
# Locate ${CMAKE_CURRENT_LIST_DIR}/version.txt,
# Locate ${CMAKE_CURRENT_SOURCE_DIR}/version.txt, and parse the version.
# The version is expected to be defined as a key-value `version=X.Y.Z`
#
# If the version.txt file doesn't exist, or doesn't contain version key-value, an error occurs
#
# <function>(
# <output_var>
# )
FUNCTION(CMUTIL_VERSION_GET_FROM_VERSION_FILE output_var)
SET(version_file ${ARGN})
IF("${version_file}" STREQUAL "")
SET(version_file "${CMAKE_CURRENT_SOURCE_DIR}/version.txt")
ENDIF()

SET(inject_version "")
CMUTIL_PROPERTY_FILE_READ("${version_file}" inject)
IF(NOT DEFINED inject_version OR "${inject_version}" STREQUAL "")
MESSAGE(FATAL_ERROR "${version_file} is not valid")
ENDIF()
CMUTIL_VERSION_CHECK("${inject_version}")

SET(${output_var} "${inject_version}" PARENT_SCOPE)
ENDFUNCTION()



##
#
# Locate ${CMAKE_CURRENT_SOURCE_DIR}/version.txt,
# read the first line and compare version stored in version.txt
# with ${version}.
#
# If versions does not match error occurres.
# If versions does not match error occurs.
#
# <function>(
# <version>
Expand All @@ -124,11 +152,12 @@ FUNCTION(CMUTIL_VERSION_VALIDATE_VERSION_FILE_FOR version)
SET(version_file "${CMAKE_CURRENT_SOURCE_DIR}/version.txt")
ENDIF()

SET(inject_version "")
CMUTIL_PROPERTY_FILE_READ("${version_file}" inject)
IF(NOT inject_version)
IF(NOT DEFINED inject_version OR "${inject_version}" STREQUAL "")
MESSAGE(FATAL_ERROR "${version_file} is not valid")
ENDIF()
CMUTIL_VERSION_CHECK(${inject_version})
CMUTIL_VERSION_CHECK("${inject_version}")
IF(NOT version STREQUAL inject_version)
MESSAGE(FATAL_ERROR "${version_file} is not in sync with current branch (${version} vs. ${inject_version})")
ENDIF()
Expand Down
7 changes: 7 additions & 0 deletions test/VERSION/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ ENDIF()
CMUTIL_VERSION_VALIDATE_VERSION_FILE_FOR("1.58.3")


CMUTIL_VERSION_GET_FROM_VERSION_FILE(parsed_version)
IF (NOT parsed_version STREQUAL "1.58.3")
MESSAGE(FATAL_ERROR " Error when parsing version from version.txt. Expected: \"1.58.3\", Actual: ${parsed_version}")
ELSE ()
MESSAGE("Passed test for: CMUTIL_VERSION_GET_FROM_VERSION_FILE")
ENDIF()


CMUTIL_VERSION_NORMALIZE(version_normalized "1.58.3")
IF(NOT version_normalized STREQUAL "001058003")
Expand Down
Loading