cmake/generate_version_file: catch errors at the end

The directory-based extraction can fail if the directory was renamed
before netgen was configured (e.g., CMake's ExternalProject will
generally rename the top-level directory to `src` for consistency).

If the directory name extraction failed, an empty string ended up in the
binary which causes runtime failures when trying to parse as an integer.
This commit is contained in:
Ben Boeckel 2021-03-18 10:13:14 -04:00
parent 9d94294f30
commit 1020b99948

View File

@ -15,12 +15,14 @@ if(status AND NOT status EQUAL 0)
get_filename_component(git_version_string ${CMAKE_CURRENT_LIST_DIR}/.. NAME) get_filename_component(git_version_string ${CMAKE_CURRENT_LIST_DIR}/.. NAME)
string(REGEX REPLACE "^netgen(.*)" "\\1" git_version_string "${git_version_string}") string(REGEX REPLACE "^netgen(.*)" "\\1" git_version_string "${git_version_string}")
endif() endif()
else()
MESSAGE(WARNING "Could not determine git-version from source code - assuming 6.2.0.0")
set(git_version_string "v6.2.0.0")
endif() endif()
endif() endif()
if (NOT git_version_string)
message(WARNING "Could not determine git-version from source code - assuming 6.2.0.0")
set(git_version_string "v6.2.0.0")
endif ()
string(REGEX REPLACE "^v([0-9]+)\\..*" "\\1" NETGEN_VERSION_MAJOR "${git_version_string}") string(REGEX REPLACE "^v([0-9]+)\\..*" "\\1" NETGEN_VERSION_MAJOR "${git_version_string}")
string(REGEX REPLACE "^v[0-9]+\\.([0-9]+).*" "\\1" NETGEN_VERSION_MINOR "${git_version_string}") string(REGEX REPLACE "^v[0-9]+\\.([0-9]+).*" "\\1" NETGEN_VERSION_MINOR "${git_version_string}")
string(REGEX REPLACE "^v[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" NETGEN_VERSION_PATCH "${git_version_string}") string(REGEX REPLACE "^v[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" NETGEN_VERSION_PATCH "${git_version_string}")