mdbx-cmake: refine fetch_version macro for no-git-tags case (sync cmake modules).

This commit is contained in:
Леонид Юрьев (Leonid Yuriev) 2022-04-22 21:23:00 +03:00
parent f866ad2fa3
commit a878b47343

View File

@ -92,15 +92,6 @@ macro(fetch_version name source_root_directory parent_scope)
set(${name}_GIT_REVISION 0) set(${name}_GIT_REVISION 0)
set(${name}_GIT_VERSION "") set(${name}_GIT_VERSION "")
if(GIT AND EXISTS "${source_root_directory}/.git") if(GIT AND EXISTS "${source_root_directory}/.git")
execute_process(COMMAND ${GIT} describe --tags --long --dirty=-dirty "--match=v[0-9]*"
OUTPUT_VARIABLE ${name}_GIT_DESCRIBE
OUTPUT_STRIP_TRAILING_WHITESPACE
WORKING_DIRECTORY ${source_root_directory}
RESULT_VARIABLE rc)
if(rc OR "${name}_GIT_DESCRIBE" STREQUAL "")
message(FATAL_ERROR "Please fetch tags and/or install latest version of git ('describe --tags --long --dirty --match=v[0-9]*' failed)")
endif()
execute_process(COMMAND ${GIT} show --no-patch --format=%cI HEAD execute_process(COMMAND ${GIT} show --no-patch --format=%cI HEAD
OUTPUT_VARIABLE ${name}_GIT_TIMESTAMP OUTPUT_VARIABLE ${name}_GIT_TIMESTAMP
OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_STRIP_TRAILING_WHITESPACE
@ -113,7 +104,7 @@ macro(fetch_version name source_root_directory parent_scope)
WORKING_DIRECTORY ${source_root_directory} WORKING_DIRECTORY ${source_root_directory}
RESULT_VARIABLE rc) RESULT_VARIABLE rc)
if(rc OR "${name}_GIT_TIMESTAMP" STREQUAL "%ci") if(rc OR "${name}_GIT_TIMESTAMP" STREQUAL "%ci")
message(FATAL_ERROR "Please install latest version of git ('show --no-patch --format=%cI HEAD' failed)") message(FATAL_ERROR "Please install latest version of git (`show --no-patch --format=%cI HEAD` failed)")
endif() endif()
endif() endif()
@ -123,7 +114,7 @@ macro(fetch_version name source_root_directory parent_scope)
WORKING_DIRECTORY ${source_root_directory} WORKING_DIRECTORY ${source_root_directory}
RESULT_VARIABLE rc) RESULT_VARIABLE rc)
if(rc OR "${name}_GIT_TREE" STREQUAL "") if(rc OR "${name}_GIT_TREE" STREQUAL "")
message(FATAL_ERROR "Please install latest version of git ('show --no-patch --format=%T HEAD' failed)") message(FATAL_ERROR "Please install latest version of git (`show --no-patch --format=%T HEAD` failed)")
endif() endif()
execute_process(COMMAND ${GIT} show --no-patch --format=%H HEAD execute_process(COMMAND ${GIT} show --no-patch --format=%H HEAD
@ -132,7 +123,58 @@ macro(fetch_version name source_root_directory parent_scope)
WORKING_DIRECTORY ${source_root_directory} WORKING_DIRECTORY ${source_root_directory}
RESULT_VARIABLE rc) RESULT_VARIABLE rc)
if(rc OR "${name}_GIT_COMMIT" STREQUAL "") if(rc OR "${name}_GIT_COMMIT" STREQUAL "")
message(FATAL_ERROR "Please install latest version of git ('show --no-patch --format=%H HEAD' failed)") message(FATAL_ERROR "Please install latest version of git (`show --no-patch --format=%H HEAD` failed)")
endif()
execute_process(COMMAND ${GIT} rev-list --tags --count
OUTPUT_VARIABLE tag_count
OUTPUT_STRIP_TRAILING_WHITESPACE
WORKING_DIRECTORY ${source_root_directory}
RESULT_VARIABLE rc)
if(rc)
message(FATAL_ERROR "Please install latest version of git (`git rev-list --tags --count` failed)")
endif()
if(tag_count EQUAL 0)
execute_process(COMMAND ${GIT} rev-list --all --count
OUTPUT_VARIABLE whole_count
OUTPUT_STRIP_TRAILING_WHITESPACE
WORKING_DIRECTORY ${source_root_directory}
RESULT_VARIABLE rc)
if(rc)
message(FATAL_ERROR "Please install latest version of git (`git rev-list --all --count` failed)")
endif()
if(whole_count GREATER 42)
message(FATAL_ERROR "Please fetch tags (no any tags for ${whole_count} commits)")
endif()
set(${name}_GIT_VERSION "0;0;0")
execute_process(COMMAND ${GIT} rev-list --count --all --no-merges
OUTPUT_VARIABLE ${name}_GIT_REVISION
OUTPUT_STRIP_TRAILING_WHITESPACE
WORKING_DIRECTORY ${source_root_directory}
RESULT_VARIABLE rc)
if(rc OR "${name}_GIT_REVISION" STREQUAL "")
message(FATAL_ERROR "Please install latest version of git (`rev-list --count --all --no-merges` failed)")
endif()
else(tag_count EQUAL 0)
execute_process(COMMAND ${GIT} describe --tags --long --dirty=-dirty "--match=v[0-9]*"
OUTPUT_VARIABLE ${name}_GIT_DESCRIBE
OUTPUT_STRIP_TRAILING_WHITESPACE
WORKING_DIRECTORY ${source_root_directory}
RESULT_VARIABLE rc)
if(rc OR "${name}_GIT_DESCRIBE" STREQUAL "")
if(_whole_count GREATER 42)
message(FATAL_ERROR "Please fetch tags (`describe --tags --long --dirty --match=v[0-9]*` failed)")
else()
execute_process(COMMAND ${GIT} describe --all --long --dirty=-dirty
OUTPUT_VARIABLE ${name}_GIT_DESCRIBE
OUTPUT_STRIP_TRAILING_WHITESPACE
WORKING_DIRECTORY ${source_root_directory}
RESULT_VARIABLE rc)
if(rc OR "${name}_GIT_DESCRIBE" STREQUAL "")
message(FATAL_ERROR "Please install latest version of git (`git rev-list --tags --count` and/or `git rev-list --all --count` failed)")
endif()
endif()
endif() endif()
execute_process(COMMAND ${GIT} describe --tags --abbrev=0 "--match=v[0-9]*" execute_process(COMMAND ${GIT} describe --tags --abbrev=0 "--match=v[0-9]*"
@ -141,7 +183,7 @@ macro(fetch_version name source_root_directory parent_scope)
WORKING_DIRECTORY ${source_root_directory} WORKING_DIRECTORY ${source_root_directory}
RESULT_VARIABLE rc) RESULT_VARIABLE rc)
if(rc) if(rc)
message(FATAL_ERROR "Please install latest version of git ('describe --tags --abbrev=0 --match=v[0-9]*' failed)") message(FATAL_ERROR "Please install latest version of git (`describe --tags --abbrev=0 --match=v[0-9]*` failed)")
endif() endif()
if (last_release_tag) if (last_release_tag)
set(git_revlist_arg "${last_release_tag}..HEAD") set(git_revlist_arg "${last_release_tag}..HEAD")
@ -152,7 +194,7 @@ macro(fetch_version name source_root_directory parent_scope)
WORKING_DIRECTORY ${source_root_directory} WORKING_DIRECTORY ${source_root_directory}
RESULT_VARIABLE rc) RESULT_VARIABLE rc)
if(rc) if(rc)
message(FATAL_ERROR "Please install latest version of git ('tag --sort=-version:refname' failed)") message(FATAL_ERROR "Please install latest version of git (`tag --sort=-version:refname` failed)")
endif() endif()
string(REGEX REPLACE "\n" ";" tag_list "${tag_list}") string(REGEX REPLACE "\n" ";" tag_list "${tag_list}")
set(git_revlist_arg "HEAD") set(git_revlist_arg "HEAD")
@ -169,7 +211,7 @@ macro(fetch_version name source_root_directory parent_scope)
WORKING_DIRECTORY ${source_root_directory} WORKING_DIRECTORY ${source_root_directory}
RESULT_VARIABLE rc) RESULT_VARIABLE rc)
if(rc OR "${name}_GIT_REVISION" STREQUAL "") if(rc OR "${name}_GIT_REVISION" STREQUAL "")
message(FATAL_ERROR "Please install latest version of git ('rev-list --count ${git_revlist_arg}' failed)") message(FATAL_ERROR "Please install latest version of git (`rev-list --count ${git_revlist_arg}` failed)")
endif() endif()
string(REGEX MATCH "^(v)?([0-9]+)\\.([0-9]+)\\.([0-9]+)(.*)?" git_version_valid "${${name}_GIT_DESCRIBE}") string(REGEX MATCH "^(v)?([0-9]+)\\.([0-9]+)\\.([0-9]+)(.*)?" git_version_valid "${${name}_GIT_DESCRIBE}")
@ -184,6 +226,7 @@ macro(fetch_version name source_root_directory parent_scope)
set(${name}_GIT_VERSION "0;0;0") set(${name}_GIT_VERSION "0;0;0")
endif() endif()
endif() endif()
endif(tag_count EQUAL 0)
endif() endif()
if(NOT ${name}_GIT_VERSION OR NOT ${name}_GIT_TIMESTAMP OR ${name}_GIT_REVISION STREQUAL "") if(NOT ${name}_GIT_VERSION OR NOT ${name}_GIT_TIMESTAMP OR ${name}_GIT_REVISION STREQUAL "")