Skip to content

Commit

Permalink
Allow forcing the version with -DVERSION_STRING=
Browse files Browse the repository at this point in the history
previously the scripts get_version.cmake and write_version_files.cmake
did not honor a VERSION_STRING that was set on the commandline. Now
you can use cmake -DVERSION_STRING -P <script>.cmake to force the
version to be used.
While this is not very useful in case of get_version.cmake it will be
used to write the correct release version numbers into the release
tarballs.
  • Loading branch information
arogge committed Nov 13, 2019
1 parent aaf0ea1 commit 5e6c094
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 29 deletions.
28 changes: 15 additions & 13 deletions core/cmake/BareosExtractVersionInfo.cmake
Expand Up @@ -15,23 +15,25 @@
# with this program; if not, write to the Free Software Foundation, Inc., 51
# Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

if(NOT DEFINED VERSION_STRING)
include(BareosVersion OPTIONAL RESULT_VARIABLE BareosVersionFile)
if(BareosVersionFile STREQUAL "NOTFOUND")
# no version file, try data from git
if(GIT_DESCRIBE_VERSION)
message(STATUS "Using version information from Git")
set(VERSION_STRING "${GIT_DESCRIBE_VERSION}")
set(VERSION_TIMESTAMP "${GIT_COMMIT_TIMESTAMP}")
include(BareosVersion OPTIONAL RESULT_VARIABLE BareosVersionFile)
if(BareosVersionFile STREQUAL "NOTFOUND")
# no version file, try data from git
if(GIT_DESCRIBE_VERSION)
message(STATUS "Using version information from Git")
if(DEFINED VERSION_STRING)
message(STATUS "VERSION_STRING already set to ${VERSION_STRING}. Will not overwrite")
else()
message(
FATAL_ERROR
"VERSION_STRING not set, BareosVersion.cmake not found and no version data from git available."
)
set(VERSION_STRING "${GIT_DESCRIBE_VERSION}")
endif()
set(VERSION_TIMESTAMP "${GIT_COMMIT_TIMESTAMP}")
else()
message(STATUS "Using version information from ${BareosVersionFile}")
message(
FATAL_ERROR
"VERSION_STRING not set, BareosVersion.cmake not found and no version data from git available."
)
endif()
else()
message(STATUS "Using version information from ${BareosVersionFile}")
endif()

string(REGEX MATCH
Expand Down
22 changes: 14 additions & 8 deletions get_version.cmake
Expand Up @@ -17,17 +17,23 @@

cmake_minimum_required(VERSION 3.0)

set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake" "${CMAKE_CURRENT_LIST_DIR}/core/cmake" "${CMAKE_CURRENT_LIST_DIR}/webui/cmake")
if(NOT DEFINED VERSION_STRING)
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake"
"${CMAKE_CURRENT_LIST_DIR}/core/cmake"
"${CMAKE_CURRENT_LIST_DIR}/webui/cmake")

find_package(Git QUIET)
include(BareosVersionFromGit)
find_package(Git QUIET)
include(BareosVersionFromGit)

include(BareosVersion OPTIONAL RESULT_VARIABLE BareosVersionFile)
if(BareosVersionFile STREQUAL "NOTFOUND")
if(GIT_DESCRIBE_VERSION)
include(BareosVersion OPTIONAL RESULT_VARIABLE BareosVersionFile)
if(BareosVersionFile STREQUAL "NOTFOUND")
if(GIT_DESCRIBE_VERSION)
set(VERSION_STRING "${GIT_DESCRIBE_VERSION}")
else()
message(FATAL_ERROR "BareosVersion.cmake not found and no git version available.")
else()
message(
FATAL_ERROR
"BareosVersion.cmake not found and no git version available.")
endif()
endif()
endif()
message(STATUS "${VERSION_STRING}")
2 changes: 0 additions & 2 deletions webui/cmake/BareosExtractVersionInfo.cmake
Expand Up @@ -21,9 +21,7 @@ if(NOT DEFINED VERSION_STRING)
# no version file, try data from git
if(GIT_DESCRIBE_VERSION)
message(STATUS "Using version information from Git")
#message(FATAL_ERROR "${GIT_DESCRIBE_VERSION}")
set(VERSION_STRING "${GIT_DESCRIBE_VERSION}")
set(VERSION_TIMESTAMP "${GIT_COMMIT_TIMESTAMP}")
else()
message(
FATAL_ERROR "VERSION_STRING not set, BareosVersion.cmake not found and no version data from git available."
Expand Down
13 changes: 7 additions & 6 deletions write_version_files.cmake
Expand Up @@ -24,18 +24,19 @@ set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake"
find_package(Git)
include(BareosVersionFromGit)

include(BareosVersion OPTIONAL RESULT_VARIABLE BareosVersionFile)
if(BareosVersionFile STREQUAL "NOTFOUND")
if(GIT_DESCRIBE_VERSION)
if(GIT_DESCRIBE_VERSION)
if(NOT DEFINED VERSION_STRING)
set(VERSION_STRING "${GIT_DESCRIBE_VERSION}")
else()
message(FATAL_ERROR "No version information from git available.")
endif()
set(VERSION_TIMESTAMP "${GIT_COMMIT_TIMESTAMP}")
else()
message(FATAL_ERROR "No version information from git available.")
endif()

set(version_file_header "# autogenerated by write_version_files.cmake")
set(version_file_contents "${version_file_header}\nset(VERSION_STRING \"${GIT_DESCRIBE_VERSION}\")\nset(VERSION_TIMESTAMP \"${GIT_COMMIT_TIMESTAMP}\")\n")
set(version_file_contents "${version_file_header}\nset(VERSION_STRING \"${VERSION_STRING}\")\nset(VERSION_TIMESTAMP \"${VERSION_TIMESTAMP}\")\n")

message(STATUS "Configuring source tree for version ${VERSION_STRING} with timestamp ${VERSION_TIMESTAMP}")
foreach(subdir "core" "webui")
set(version_file_name "${CMAKE_CURRENT_LIST_DIR}/${subdir}/cmake/BareosVersion.cmake")
message(STATUS "Writing ${version_file_name}")
Expand Down

0 comments on commit 5e6c094

Please sign in to comment.