ParaViewDetermineVersion.cmake
Go to the documentation of this file.
1 # SPDX-FileCopyrightText: Copyright (c) Kitware Inc.
2 # SPDX-License-Identifier: BSD-3-Clause
3 
4 # Used to determine the version for ParaView source using "git describe", if git
5 # is found. On success sets following variables in caller's scope:
6 # ${var_prefix}_VERSION
7 # ${var_prefix}_VERSION_MAJOR
8 # ${var_prefix}_VERSION_MINOR
9 # ${var_prefix}_VERSION_PATCH
10 # ${var_prefix}_VERSION_PATCH_EXTRA
11 # ${var_prefix}_VERSION_FULL
12 # ${var_prefix}_VERSION_IS_RELEASE is true, if patch-extra is empty.
13 #
14 # If git is not found, or git describe cannot be run successfully, then these
15 # variables are left unchanged and status message is printed.
16 #
17 # Arguments are:
18 # source_dir : Source directory
19 # git_command : git executable
20 # var_prefix : prefix for variables e.g. "PARAVIEW".
21 function(determine_version source_dir git_command var_prefix)
22  if ("$Format:$" STREQUAL "")
23  # We are in an exported tarball and should use the shipped version
24  # information. Just return here to avoid the warning message at the end of
25  # this function.
26  return ()
27  elseif (NOT PARAVIEW_GIT_DESCRIBE AND
28  EXISTS ${git_command} AND
29  EXISTS ${source_dir}/.git)
30  execute_process(
31  COMMAND ${git_command} describe
32  WORKING_DIRECTORY ${source_dir}
33  RESULT_VARIABLE result
34  OUTPUT_VARIABLE output
35  ERROR_QUIET
36  OUTPUT_STRIP_TRAILING_WHITESPACE
37  ERROR_STRIP_TRAILING_WHITESPACE)
38  if (NOT result EQUAL 0)
39  # git describe failed (bad return code).
40  set(output "")
41  endif()
42  else ()
43  # note, output may be set to empty if PARAVIEW_GIT_DESCRIBE is not defined.
44  set(output "${PARAVIEW_GIT_DESCRIBE}")
45  endif()
46 
47  unset(tmp_VERSION)
48  extract_version_components(${source_dir} "${output}" tmp)
49  if(DEFINED tmp_VERSION)
50  if (NOT "${tmp_VERSION}" STREQUAL "${${var_prefix}_VERSION}")
51  message(WARNING
52  "Version from git (${tmp_VERSION}) disagrees with hard coded version (${${var_prefix}_VERSION}). Either update the git tags or version.txt.")
53  if (NOT "$ENV{CI}" STREQUAL "")
54  message(WARNING
55  "Please update your fork tags, using this command: `git fetch origin --tags && git push gitlab --tags`.")
56  endif ()
57  endif()
58  foreach(suffix BRANCH VERSION VERSION_MAJOR VERSION_MINOR VERSION_PATCH
59  VERSION_PATCH_EXTRA VERSION_FULL VERSION_IS_RELEASE)
60  set(${var_prefix}_${suffix} ${tmp_${suffix}} PARENT_SCOPE)
61  endforeach()
62  else()
63  message(STATUS
64  "Could not use git to determine source version, using version ${${var_prefix}_VERSION_FULL}")
65  endif()
66 endfunction()
67 
68 # Extracts components from a version string. See determine_version() for usage.
69 function(extract_version_components source_dir version_string var_prefix)
70  string(REGEX MATCH "^v?(([0-9]+)\\.([0-9]+)\\.([0-9]+)-?(.*))$"
71  version_matches "${version_string}")
72  if(CMAKE_MATCH_0)
73  # note, we don't use CMAKE_MATCH_0 for `full` since it may or may not have
74  # the `v` prefix.
75  set(full ${CMAKE_MATCH_1})
76  set(major ${CMAKE_MATCH_2})
77  set(minor ${CMAKE_MATCH_3})
78  set(patch ${CMAKE_MATCH_4})
79  set(patch_extra ${CMAKE_MATCH_5})
80  set(branch "")
81  if (patch_extra)
82  if (NOT source_dir)
83  set(source_dir "${ParaView_SOURCE_DIR}")
84  endif ()
85  execute_process(
86  COMMAND ${git_command}
87  name-rev
88  --name-only
89  --no-undefined # error if these names don't work
90  --refs=refs/tags/* # tags
91  --refs=refs/heads/* # branches
92  --refs=refs/pipelines/* # CI
93  HEAD
94  WORKING_DIRECTORY ${source_dir}
95  RESULT_VARIABLE result
96  OUTPUT_VARIABLE output
97  ERROR_QUIET
98  OUTPUT_STRIP_TRAILING_WHITESPACE
99  ERROR_STRIP_TRAILING_WHITESPACE)
100  if (result EQUAL 0)
101  # The branch name.
102  set(branch "${output}")
103  endif()
104  endif ()
105 
106  set(${var_prefix}_BRANCH "${branch}" PARENT_SCOPE)
107  set(${var_prefix}_VERSION "${major}.${minor}" PARENT_SCOPE)
108  set(${var_prefix}_VERSION_MAJOR ${major} PARENT_SCOPE)
109  set(${var_prefix}_VERSION_MINOR ${minor} PARENT_SCOPE)
110  set(${var_prefix}_VERSION_PATCH ${patch} PARENT_SCOPE)
111  set(${var_prefix}_VERSION_PATCH_EXTRA ${patch_extra} PARENT_SCOPE)
112  set(${var_prefix}_VERSION_FULL ${full} PARENT_SCOPE)
113  if("${major}.${minor}.${patch}" VERSION_EQUAL "${full}" AND
114  # Date-based patch versions are never releases.
115  patch LESS "20000101")
116  set(${var_prefix}_VERSION_IS_RELEASE TRUE PARENT_SCOPE)
117  else()
118  set(${var_prefix}_VERSION_IS_RELEASE FALSE PARENT_SCOPE)
119  endif()
120  endif()
121 endfunction()
function extract_version_components(source_dir, version_string, var_prefix)
name
#define VERSION
Definition: jconfigint.h:17
function determine_version(source_dir, git_command, var_prefix)