diff --git a/CMake/VTKmDetermineVersion.cmake b/CMake/VTKmDetermineVersion.cmake index 25cb7f906..3c2ea924f 100644 --- a/CMake/VTKmDetermineVersion.cmake +++ b/CMake/VTKmDetermineVersion.cmake @@ -41,21 +41,27 @@ function(determine_version source_dir git_command var_prefix) # information. Just return here to avoid the warning message at the end of # this function. return () - elseif (NOT VTKm_GIT_DESCRIBE) - if(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) + elseif (NOT VTKm_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() - set(result 0) - set(output ${VTKm_GIT_DESCRIBE}) + else () + # note, output may be set to empty if VTKm_GIT_DESCRIBE is not defined. + set(output "${VTKm_GIT_DESCRIBE}") endif() + + unset(tmp_VERSION) extract_version_components("${output}" tmp) if(DEFINED tmp_VERSION) if (NOT "${tmp_VERSION}" STREQUAL "${${var_prefix}_VERSION}") @@ -74,14 +80,16 @@ endfunction() # Extracts components from a version string. See determine_version() for usage. function(extract_version_components version_string var_prefix) - string(REGEX MATCH "([0-9]+)\\.([0-9]+)\\.([0-9]+)[-]*(.*)" + string(REGEX MATCH "^v?(([0-9]+)\\.([0-9]+)\\.([0-9]+)-?(.*))$" version_matches "${version_string}") if(CMAKE_MATCH_0) - set(full ${CMAKE_MATCH_0}) - set(major ${CMAKE_MATCH_1}) - set(minor ${CMAKE_MATCH_2}) - set(patch ${CMAKE_MATCH_3}) - set(patch_extra ${CMAKE_MATCH_4}) + # 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}" PARENT_SCOPE) set(${var_prefix}_VERSION_MAJOR ${major} PARENT_SCOPE)