|
| 1 | +# OBS CMake common version helper module |
| 2 | + |
| 3 | +include_guard(GLOBAL) |
| 4 | + |
| 5 | +set(_plugin_version ${_plugin_default_version}) |
| 6 | +set(_plugin_version_canonical ${_plugin_default_version}) |
| 7 | + |
| 8 | +# Attempt to automatically discover expected OBS version |
| 9 | +if(NOT DEFINED PLUGIN_VERSION_OVERRIDE AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git") |
| 10 | + execute_process( |
| 11 | + COMMAND git describe --always --tags --dirty=-modified |
| 12 | + OUTPUT_VARIABLE _plugin_version |
| 13 | + ERROR_VARIABLE _git_describe_err |
| 14 | + WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" |
| 15 | + RESULT_VARIABLE _plugin_version_result |
| 16 | + OUTPUT_STRIP_TRAILING_WHITESPACE |
| 17 | + ) |
| 18 | + |
| 19 | + if(_git_describe_err) |
| 20 | + message(FATAL_ERROR "Could not fetch OBS version tag from git.\n" ${_git_describe_err}) |
| 21 | + endif() |
| 22 | + |
| 23 | + if(_plugin_version_result EQUAL 0) |
| 24 | + string(REGEX REPLACE "v?([0-9]+)\\.([0-9]+)\\.([0-9]+).*" "\\1;\\2;\\3" _plugin_version_canonical ${_plugin_version}) |
| 25 | + endif() |
| 26 | +elseif(DEFINED PLUGIN_VERSION_OVERRIDE) |
| 27 | + if(PLUGIN_VERSION_OVERRIDE MATCHES "v?([0-9]+)\\.([0-9]+)\\.([0-9]+).*") |
| 28 | + string( |
| 29 | + REGEX REPLACE |
| 30 | + "v?([0-9]+)\\.([0-9]+)\\.([0-9]+).*" |
| 31 | + "\\1;\\2;\\3" |
| 32 | + _plugin_version_canonical |
| 33 | + ${PLUGIN_VERSION_OVERRIDE} |
| 34 | + ) |
| 35 | + set(_plugin_version ${PLUGIN_VERSION_OVERRIDE}) |
| 36 | + else() |
| 37 | + message(FATAL_ERROR "Invalid version supplied - must be <MAJOR>.<MINOR>.<PATCH>[-(rc|beta)<NUMBER>].") |
| 38 | + endif() |
| 39 | +endif() |
| 40 | + |
| 41 | +# Set beta/rc versions if suffix included in version string |
| 42 | +if(_plugin_version MATCHES "v?[0-9]+\\.[0-9]+\\.[0-9]+-rc[0-9]+") |
| 43 | + string(REGEX REPLACE "v?[0-9]+\\.[0-9]+\\.[0-9]+-rc([0-9]+).*$" "\\1" _plugin_release_candidate ${_plugin_version}) |
| 44 | +elseif(_plugin_version MATCHES "v?[0-9]+\\.[0-9]+\\.[0-9]+-beta[0-9]+") |
| 45 | + string(REGEX REPLACE "v?[0-9]+\\.[0-9]+\\.[0-9]+-beta([0-9]+).*$" "\\1" _plugin_beta ${_plugin_version}) |
| 46 | +endif() |
| 47 | + |
| 48 | +list(GET _plugin_version_canonical 0 PLUGIN_VERSION_MAJOR) |
| 49 | +list(GET _plugin_version_canonical 1 PLUGIN_VERSION_MINOR) |
| 50 | +list(GET _plugin_version_canonical 2 PLUGIN_VERSION_PATCH) |
| 51 | + |
| 52 | +set(PLUGIN_RELEASE_CANDIDATE ${_plugin_release_candidate}) |
| 53 | +set(PLUGIN_BETA ${_plugin_beta}) |
| 54 | + |
| 55 | +string(REPLACE ";" "." PLUGIN_VERSION_CANONICAL "${_plugin_version_canonical}") |
| 56 | +string(REPLACE ";" "." PLUGIN_VERSION "${_plugin_version}") |
| 57 | + |
| 58 | +if(PLUGIN_RELEASE_CANDIDATE GREATER 0) |
| 59 | + message( |
| 60 | + AUTHOR_WARNING |
| 61 | + "******************************************************************************\n" |
| 62 | + " + ${_name} - Release candidate detected, PLUGIN_VERSION is now: ${PLUGIN_VERSION}\n" |
| 63 | + "******************************************************************************" |
| 64 | + ) |
| 65 | +elseif(PLUGIN_BETA GREATER 0) |
| 66 | + message( |
| 67 | + AUTHOR_WARNING |
| 68 | + "******************************************************************************\n" |
| 69 | + " + ${_name} - Beta detected, PLUGIN_VERSION is now: ${PLUGIN_VERSION}\n" |
| 70 | + "******************************************************************************" |
| 71 | + ) |
| 72 | +endif() |
| 73 | + |
| 74 | +unset(_plugin_default_version) |
| 75 | +unset(_plugin_version) |
| 76 | +unset(_plugin_version_canonical) |
| 77 | +unset(_plugin_release_candidate) |
| 78 | +unset(_plugin_beta) |
| 79 | +unset(_plugin_version_result) |
0 commit comments