Skip to content
Snippets Groups Projects
Commit 2a64bbae authored by Mathieu Westphal (Kitware)'s avatar Mathieu Westphal (Kitware) :zap:
Browse files

Adding a VTK_VERSION_FULL and related methods

This adds a VTK_VERSION_FULL in cmake
thanks to a new VTKDtermineVersion.cmake using git

This adds a vtkVersion::GetVersionFull method.
parent 820646fd
No related branches found
No related tags found
No related merge requests found
#=========================================================================
#
# Program: VTK
#
# Copyright (c) Kitware, Inc.
# All rights reserved.
# See Copyright.txt or http://www.VTK.org/HTML/Copyright.html for details.
#
# This software is distributed WITHOUT ANY WARRANTY; without even
# the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
# PURPOSE. See the above copyright notice for more information.
#
#=========================================================================
# Used to determine the version for VTK source using "git describe", if git
# is found. On success sets following variables in caller's scope:
# ${var_prefix}_VERSION
# ${var_prefix}_MAJOR_VERSION
# ${var_prefix}_MINOR_VERSION
# ${var_prefix}_BUILD_VERSION
# ${var_prefix}_BUILD_VERSION_EXTRA
# ${var_prefix}_VERSION_FULL
# ${var_prefix}_VERSION_IS_RELEASE is true, if patch-extra is empty.
#
# If git is not found, or git describe cannot be run successfully, then these
# variables are left unchanged and status message is printed.
#
# Arguments are:
# source_dir : Source directory
# git_command : git executable
# var_prefix : prefix for variables e.g. "VTK".
function(determine_version source_dir git_command var_prefix)
if ("$Format:$" STREQUAL "")
# We are in an exported tarball and should use the shipped version
# information. Just return here to avoid the warning message at the end of
# this function.
return ()
elseif (NOT VTK_GIT_DESCRIBE AND
EXISTS ${git_command} AND
EXISTS ${source_dir}/.git)
execute_process(
COMMAND ${git_command} describe
WORKING_DIRECTORY ${source_dir}
RESULT_VARIABLE result
OUTPUT_VARIABLE output
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_STRIP_TRAILING_WHITESPACE)
if (NOT result EQUAL 0)
# git describe failed (bad return code).
set(output "")
endif()
else ()
# note, output may be set to empty if VTK_GIT_DESCRIBE is not defined.
set(output "${VTK_GIT_DESCRIBE}")
endif()
unset(tmp_VERSION)
extract_version_components("${output}" tmp)
if(DEFINED tmp_VERSION)
if (NOT "${tmp_VERSION}" STREQUAL "${${var_prefix}_VERSION}")
message(WARNING
"Version from git (${tmp_VERSION}) disagrees with hard coded version (${${var_prefix}_VERSION}). Either update the git tags or version.txt.")
endif()
foreach(suffix VERSION VERSION_MAJOR VERSION_MINOR VERSION_PATCH
VERSION_PATCH_EXTRA VERSION_FULL VERSION_IS_RELEASE)
set(${var_prefix}_${suffix} ${tmp_${suffix}} PARENT_SCOPE)
endforeach()
else()
message(STATUS
"Could not use git to determine source version, using version ${${var_prefix}_VERSION_FULL}")
endif()
endfunction()
# Extracts components from a version string. See determine_version() for usage.
function(extract_version_components version_string var_prefix)
string(REGEX MATCH "^v?(([0-9]+)\\.([0-9]+)\\.([0-9]+)-?(.*))$"
version_matches "${version_string}")
if(CMAKE_MATCH_0)
# note, we don't use CMAKE_MATCH_0 for `full` since it may or may not have
# the `v` prefix.
set(full ${CMAKE_MATCH_1})
set(major ${CMAKE_MATCH_2})
set(minor ${CMAKE_MATCH_3})
set(patch ${CMAKE_MATCH_4})
set(patch_extra ${CMAKE_MATCH_5})
set(${var_prefix}_VERSION "${major}.${minor}.${patch}" PARENT_SCOPE)
set(${var_prefix}_MAJOR_VERSION ${major} PARENT_SCOPE)
set(${var_prefix}_MINOR_VERSION ${minor} PARENT_SCOPE)
set(${var_prefix}_BUILD_VERSION ${patch} PARENT_SCOPE)
set(${var_prefix}_BUILD_VERSION_EXTRA ${patch_extra} PARENT_SCOPE)
set(${var_prefix}_VERSION_FULL ${full} PARENT_SCOPE)
if("${major}.${minor}.${patch}" VERSION_EQUAL "${full}")
set(${var_prefix}_VERSION_IS_RELEASE TRUE PARENT_SCOPE)
else()
set(${var_prefix}_VERSION_IS_RELEASE FALSE PARENT_SCOPE)
endif()
endif()
endfunction()
......@@ -26,9 +26,12 @@ if (APPLE)
endif ()
# must be before the following iOS / Android
find_package(Git QUIET)
include(VTKDetermineVersion)
include(vtkVersion)
set(VTK_VERSION
"${VTK_MAJOR_VERSION}.${VTK_MINOR_VERSION}.${VTK_BUILD_VERSION}")
determine_version("${CMAKE_CURRENT_SOURCE_DIR}" "${GIT_EXECUTABLE}" "VTK")
option(VTK_IOS_BUILD "Build vtk.framework for iOS" OFF)
mark_as_advanced(VTK_IOS_BUILD)
......
......@@ -50,6 +50,7 @@ public:
* with an identifier which timestamps a particular source tree.
*/
static const char* GetVTKVersion() { return VTK_VERSION; }
static const char* GetVTKVersionFull() { return VTK_VERSION_FULL; }
static int GetVTKMajorVersion() { return VTK_MAJOR_VERSION; }
static int GetVTKMinorVersion() { return VTK_MINOR_VERSION; }
static int GetVTKBuildVersion() { return VTK_BUILD_VERSION; }
......
......@@ -19,5 +19,6 @@
#define VTK_MINOR_VERSION @VTK_MINOR_VERSION@
#define VTK_BUILD_VERSION @VTK_BUILD_VERSION@
#define VTK_VERSION "@VTK_VERSION@"
#define VTK_VERSION_FULL "@VTK_VERSION_FULL@"
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment