2024-11-13 15:03:16 +03:00
|
|
|
|
# Copyright (c) 2012-2024 Леонид Юрьев aka Leonid Yuriev <leo@yuriev.ru>
|
|
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
2019-08-31 17:13:02 +03:00
|
|
|
|
|
2022-11-07 23:37:27 +03:00
|
|
|
|
if(CMAKE_VERSION VERSION_LESS 3.8.2)
|
|
|
|
|
cmake_minimum_required(VERSION 3.0.2)
|
|
|
|
|
elseif(CMAKE_VERSION VERSION_LESS 3.12)
|
2021-08-03 17:17:22 +03:00
|
|
|
|
cmake_minimum_required(VERSION 3.8.2)
|
|
|
|
|
else()
|
|
|
|
|
cmake_minimum_required(VERSION 3.12)
|
|
|
|
|
endif()
|
|
|
|
|
|
2019-08-31 17:13:02 +03:00
|
|
|
|
cmake_policy(PUSH)
|
2021-08-03 17:17:22 +03:00
|
|
|
|
cmake_policy(VERSION ${CMAKE_MINIMUM_REQUIRED_VERSION})
|
2019-08-31 17:13:02 +03:00
|
|
|
|
|
2020-10-20 15:42:50 +03:00
|
|
|
|
macro(add_compile_flags languages)
|
|
|
|
|
foreach(_lang ${languages})
|
2019-08-31 17:13:02 +03:00
|
|
|
|
string(REPLACE ";" " " _flags "${ARGN}")
|
|
|
|
|
if(CMAKE_CXX_COMPILER_LOADED AND _lang STREQUAL "CXX")
|
|
|
|
|
set("${_lang}_FLAGS" "${${_lang}_FLAGS} ${_flags}")
|
|
|
|
|
endif()
|
|
|
|
|
if(CMAKE_C_COMPILER_LOADED AND _lang STREQUAL "C")
|
|
|
|
|
set("${_lang}_FLAGS" "${${_lang}_FLAGS} ${_flags}")
|
|
|
|
|
endif()
|
|
|
|
|
endforeach()
|
|
|
|
|
unset(_lang)
|
|
|
|
|
unset(_flags)
|
|
|
|
|
endmacro(add_compile_flags)
|
|
|
|
|
|
2022-03-28 23:07:15 +03:00
|
|
|
|
macro(remove_flag varname flag)
|
2024-11-13 15:03:16 +03:00
|
|
|
|
string(REGEX REPLACE "^(.*)( ${flag} )(.*)$" "\\1 \\3" ${varname}
|
|
|
|
|
${${varname}})
|
|
|
|
|
string(REGEX REPLACE "^((.+ )*)(${flag})(( .+)*)$" "\\1\\4" ${varname}
|
|
|
|
|
${${varname}})
|
2022-03-28 23:07:15 +03:00
|
|
|
|
endmacro(remove_flag)
|
|
|
|
|
|
|
|
|
|
macro(remove_compile_flag languages flag)
|
|
|
|
|
foreach(_lang ${languages})
|
|
|
|
|
if(CMAKE_CXX_COMPILER_LOADED AND _lang STREQUAL "CXX")
|
|
|
|
|
remove_flag(${_lang}_FLAGS ${flag})
|
|
|
|
|
endif()
|
|
|
|
|
if(CMAKE_C_COMPILER_LOADED AND _lang STREQUAL "C")
|
|
|
|
|
remove_flag(${_lang}_FLAGS ${flag})
|
|
|
|
|
endif()
|
|
|
|
|
endforeach()
|
|
|
|
|
unset(_lang)
|
|
|
|
|
endmacro(remove_compile_flag)
|
|
|
|
|
|
2019-08-31 17:13:02 +03:00
|
|
|
|
macro(set_source_files_compile_flags)
|
|
|
|
|
foreach(file ${ARGN})
|
|
|
|
|
get_filename_component(_file_ext ${file} EXT)
|
|
|
|
|
set(_lang "")
|
|
|
|
|
if("${_file_ext}" STREQUAL ".m")
|
|
|
|
|
set(_lang OBJC)
|
2024-11-13 15:03:16 +03:00
|
|
|
|
# CMake believes that Objective C is a flavor of C++, not C, and uses g++
|
|
|
|
|
# compiler for .m files. LANGUAGE property forces CMake to use CC for
|
|
|
|
|
# ${file}
|
2019-08-31 17:13:02 +03:00
|
|
|
|
set_source_files_properties(${file} PROPERTIES LANGUAGE C)
|
|
|
|
|
elseif("${_file_ext}" STREQUAL ".mm")
|
|
|
|
|
set(_lang OBJCXX)
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
if(_lang)
|
|
|
|
|
get_source_file_property(_flags ${file} COMPILE_FLAGS)
|
|
|
|
|
if("${_flags}" STREQUAL "NOTFOUND")
|
|
|
|
|
set(_flags "${CMAKE_${_lang}_FLAGS}")
|
|
|
|
|
else()
|
|
|
|
|
set(_flags "${_flags} ${CMAKE_${_lang}_FLAGS}")
|
|
|
|
|
endif()
|
|
|
|
|
# message(STATUS "Set (${file} ${_flags}")
|
2024-11-13 15:03:16 +03:00
|
|
|
|
set_source_files_properties(${file} PROPERTIES COMPILE_FLAGS "${_flags}")
|
2019-08-31 17:13:02 +03:00
|
|
|
|
endif()
|
|
|
|
|
endforeach()
|
|
|
|
|
unset(_file_ext)
|
|
|
|
|
unset(_lang)
|
|
|
|
|
endmacro(set_source_files_compile_flags)
|
|
|
|
|
|
2024-11-13 15:03:16 +03:00
|
|
|
|
macro(fetch_version name source_root_directory parent_scope
|
|
|
|
|
build_directory_for_json_output)
|
2024-11-12 12:25:51 +03:00
|
|
|
|
set(_version_4dot "")
|
|
|
|
|
set(_git_describe "")
|
|
|
|
|
set(_git_timestamp "")
|
|
|
|
|
set(_git_tree "")
|
|
|
|
|
set(_git_commit "")
|
|
|
|
|
set(_git_revision 0)
|
|
|
|
|
set(_git_version "")
|
|
|
|
|
set(_version_from "")
|
|
|
|
|
set(_git_root FALSE)
|
|
|
|
|
|
|
|
|
|
find_program(GIT git)
|
|
|
|
|
if(GIT)
|
2024-11-13 15:03:16 +03:00
|
|
|
|
execute_process(
|
|
|
|
|
COMMAND ${GIT} rev-parse --show-toplevel
|
2024-11-12 12:25:51 +03:00
|
|
|
|
OUTPUT_VARIABLE _git_root
|
|
|
|
|
ERROR_VARIABLE _git_root_error
|
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
|
|
|
WORKING_DIRECTORY ${source_root_directory}
|
|
|
|
|
RESULT_VARIABLE _rc)
|
|
|
|
|
if(_rc OR _git_root STREQUAL "")
|
|
|
|
|
if(EXISTS "${source_root_directory}/.git")
|
2024-11-13 15:03:16 +03:00
|
|
|
|
message(ERROR
|
|
|
|
|
"`git rev-parse --show-toplevel` failed '${_git_root_error}'")
|
2024-11-12 12:25:51 +03:00
|
|
|
|
else()
|
2024-11-13 15:03:16 +03:00
|
|
|
|
message(VERBOSE
|
|
|
|
|
"`git rev-parse --show-toplevel` failed '${_git_root_error}'")
|
2024-11-12 12:25:51 +03:00
|
|
|
|
endif()
|
|
|
|
|
else()
|
|
|
|
|
set(_source_root "${source_root_directory}")
|
|
|
|
|
if(NOT CMAKE_VERSION VERSION_LESS 3.20)
|
|
|
|
|
cmake_path(NORMAL_PATH _git_root)
|
|
|
|
|
cmake_path(NORMAL_PATH _source_root)
|
|
|
|
|
endif()
|
|
|
|
|
if(_source_root STREQUAL _git_root AND EXISTS "${_git_root}/VERSION.json")
|
2024-11-13 15:03:16 +03:00
|
|
|
|
message(
|
|
|
|
|
FATAL_ERROR
|
|
|
|
|
"Несколько источников информации о версии, допустим только один из: репозиторий git, либо файл VERSION.json"
|
|
|
|
|
)
|
2024-11-12 12:25:51 +03:00
|
|
|
|
endif()
|
|
|
|
|
endif()
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
if(EXISTS "${source_root_directory}/VERSION.json")
|
|
|
|
|
set(_version_from "${source_root_directory}/VERSION.json")
|
|
|
|
|
|
|
|
|
|
if(CMAKE_VERSION VERSION_LESS 3.19)
|
2024-11-13 15:03:16 +03:00
|
|
|
|
message(
|
|
|
|
|
FATAL_ERROR "Требуется CMake версии >= 3.19 для чтения VERSION.json")
|
2024-11-12 12:25:51 +03:00
|
|
|
|
endif()
|
2024-11-13 15:03:16 +03:00
|
|
|
|
file(
|
|
|
|
|
STRINGS "${_version_from}" _versioninfo_json NEWLINE_CONSUME
|
|
|
|
|
LIMIT_COUNT 9
|
|
|
|
|
LIMIT_INPUT 999
|
|
|
|
|
ENCODING UTF-8)
|
2024-11-12 12:25:51 +03:00
|
|
|
|
string(JSON _git_describe GET ${_versioninfo_json} git_describe)
|
|
|
|
|
string(JSON _git_timestamp GET "${_versioninfo_json}" "git_timestamp")
|
|
|
|
|
string(JSON _git_tree GET "${_versioninfo_json}" "git_tree")
|
|
|
|
|
string(JSON _git_commit GET "${_versioninfo_json}" "git_commit")
|
|
|
|
|
string(JSON _version_4dot GET "${_versioninfo_json}" "version_4dot")
|
|
|
|
|
unset(_json_object)
|
|
|
|
|
string(REPLACE "." ";" _version_list "${_version_4dot}")
|
|
|
|
|
|
|
|
|
|
if(NOT _version_4dot)
|
2024-11-13 15:03:16 +03:00
|
|
|
|
message(
|
|
|
|
|
ERROR
|
|
|
|
|
"Unable to retrieve ${name} version from \"${_version_from}\" file.")
|
2024-11-12 12:25:51 +03:00
|
|
|
|
set(_version_list ${_git_version})
|
|
|
|
|
string(REPLACE ";" "." _version_4dot "${_git_version}")
|
|
|
|
|
else()
|
|
|
|
|
string(REPLACE "." ";" _version_list ${_version_4dot})
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
elseif(_git_root AND _source_root STREQUAL _git_root)
|
|
|
|
|
set(_version_from git)
|
|
|
|
|
|
2024-11-13 15:03:16 +03:00
|
|
|
|
execute_process(
|
|
|
|
|
COMMAND ${GIT} show --no-patch --format=%cI HEAD
|
2024-11-12 12:25:51 +03:00
|
|
|
|
OUTPUT_VARIABLE _git_timestamp
|
2019-08-31 17:13:02 +03:00
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
2020-04-30 03:45:47 +03:00
|
|
|
|
WORKING_DIRECTORY ${source_root_directory}
|
2024-11-12 12:25:51 +03:00
|
|
|
|
RESULT_VARIABLE _rc)
|
|
|
|
|
if(_rc OR _git_timestamp STREQUAL "%cI")
|
2024-11-13 15:03:16 +03:00
|
|
|
|
execute_process(
|
|
|
|
|
COMMAND ${GIT} show --no-patch --format=%ci HEAD
|
2024-11-12 12:25:51 +03:00
|
|
|
|
OUTPUT_VARIABLE _git_timestamp
|
2019-08-31 17:13:02 +03:00
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
2020-04-30 03:45:47 +03:00
|
|
|
|
WORKING_DIRECTORY ${source_root_directory}
|
2024-11-12 12:25:51 +03:00
|
|
|
|
RESULT_VARIABLE _rc)
|
|
|
|
|
if(_rc OR _git_timestamp STREQUAL "%ci")
|
2024-11-13 15:03:16 +03:00
|
|
|
|
message(
|
|
|
|
|
FATAL_ERROR
|
|
|
|
|
"Please install latest version of git (`show --no-patch --format=%cI HEAD` failed)"
|
|
|
|
|
)
|
2019-08-31 17:13:02 +03:00
|
|
|
|
endif()
|
|
|
|
|
endif()
|
|
|
|
|
|
2024-11-13 15:03:16 +03:00
|
|
|
|
execute_process(
|
|
|
|
|
COMMAND ${GIT} show --no-patch --format=%T HEAD
|
2024-11-12 12:25:51 +03:00
|
|
|
|
OUTPUT_VARIABLE _git_tree
|
2019-08-31 17:13:02 +03:00
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
2020-04-30 03:45:47 +03:00
|
|
|
|
WORKING_DIRECTORY ${source_root_directory}
|
2024-11-12 12:25:51 +03:00
|
|
|
|
RESULT_VARIABLE _rc)
|
|
|
|
|
if(_rc OR _git_tree STREQUAL "")
|
2024-11-13 15:03:16 +03:00
|
|
|
|
message(
|
|
|
|
|
FATAL_ERROR
|
|
|
|
|
"Please install latest version of git (`show --no-patch --format=%T HEAD` failed)"
|
|
|
|
|
)
|
2019-08-31 17:13:02 +03:00
|
|
|
|
endif()
|
|
|
|
|
|
2024-11-13 15:03:16 +03:00
|
|
|
|
execute_process(
|
|
|
|
|
COMMAND ${GIT} show --no-patch --format=%H HEAD
|
2024-11-12 12:25:51 +03:00
|
|
|
|
OUTPUT_VARIABLE _git_commit
|
2019-08-31 17:13:02 +03:00
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
2020-04-30 03:45:47 +03:00
|
|
|
|
WORKING_DIRECTORY ${source_root_directory}
|
2024-11-12 12:25:51 +03:00
|
|
|
|
RESULT_VARIABLE _rc)
|
|
|
|
|
if(_rc OR _git_commit STREQUAL "")
|
2024-11-13 15:03:16 +03:00
|
|
|
|
message(
|
|
|
|
|
FATAL_ERROR
|
|
|
|
|
"Please install latest version of git (`show --no-patch --format=%H HEAD` failed)"
|
|
|
|
|
)
|
2019-08-31 17:13:02 +03:00
|
|
|
|
endif()
|
|
|
|
|
|
2024-11-13 15:03:16 +03:00
|
|
|
|
execute_process(
|
|
|
|
|
COMMAND ${GIT} status --untracked-files=no --porcelain
|
2024-11-12 12:25:51 +03:00
|
|
|
|
OUTPUT_VARIABLE _git_status
|
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
|
|
|
WORKING_DIRECTORY ${source_root_directory}
|
|
|
|
|
RESULT_VARIABLE _rc)
|
|
|
|
|
if(_rc)
|
2024-11-13 15:03:16 +03:00
|
|
|
|
message(
|
|
|
|
|
FATAL_ERROR
|
|
|
|
|
"Please install latest version of git (`status --untracked-files=no --porcelain` failed)"
|
|
|
|
|
)
|
2024-11-12 12:25:51 +03:00
|
|
|
|
endif()
|
|
|
|
|
if(NOT _git_status STREQUAL "")
|
|
|
|
|
set(_git_commit "${_git_commit}-dirty")
|
|
|
|
|
endif()
|
|
|
|
|
unset(_git_status)
|
|
|
|
|
|
2024-11-13 15:03:16 +03:00
|
|
|
|
execute_process(
|
|
|
|
|
COMMAND ${GIT} rev-list --tags --count
|
2024-11-12 12:25:51 +03:00
|
|
|
|
OUTPUT_VARIABLE _tag_count
|
2020-06-12 21:01:41 +03:00
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
|
|
|
WORKING_DIRECTORY ${source_root_directory}
|
2024-11-12 12:25:51 +03:00
|
|
|
|
RESULT_VARIABLE _rc)
|
|
|
|
|
if(_rc)
|
2024-11-13 15:03:16 +03:00
|
|
|
|
message(
|
|
|
|
|
FATAL_ERROR
|
|
|
|
|
"Please install latest version of git (`git rev-list --tags --count` failed)"
|
|
|
|
|
)
|
2020-06-12 21:01:41 +03:00
|
|
|
|
endif()
|
2022-04-22 21:23:00 +03:00
|
|
|
|
|
2024-11-12 12:25:51 +03:00
|
|
|
|
if(_tag_count EQUAL 0)
|
2024-11-13 15:03:16 +03:00
|
|
|
|
execute_process(
|
|
|
|
|
COMMAND ${GIT} rev-list --all --count
|
2024-11-12 12:25:51 +03:00
|
|
|
|
OUTPUT_VARIABLE _whole_count
|
2020-10-19 16:19:48 +03:00
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
|
|
|
WORKING_DIRECTORY ${source_root_directory}
|
2024-11-12 12:25:51 +03:00
|
|
|
|
RESULT_VARIABLE _rc)
|
|
|
|
|
if(_rc)
|
2024-11-13 15:03:16 +03:00
|
|
|
|
message(
|
|
|
|
|
FATAL_ERROR
|
|
|
|
|
"Please install latest version of git (`git rev-list --all --count` failed)"
|
|
|
|
|
)
|
2022-04-22 21:23:00 +03:00
|
|
|
|
endif()
|
2024-11-12 12:25:51 +03:00
|
|
|
|
if(_whole_count GREATER 42)
|
2024-11-13 15:03:16 +03:00
|
|
|
|
message(
|
|
|
|
|
FATAL_ERROR
|
|
|
|
|
"Please fetch tags (no any tags for ${_whole_count} commits)")
|
2022-04-22 21:23:00 +03:00
|
|
|
|
endif()
|
2024-11-12 12:25:51 +03:00
|
|
|
|
set(_git_version "0;0;0")
|
2024-11-13 15:03:16 +03:00
|
|
|
|
execute_process(
|
|
|
|
|
COMMAND ${GIT} rev-list --count --all --no-merges
|
2024-11-12 12:25:51 +03:00
|
|
|
|
OUTPUT_VARIABLE _git_revision
|
2022-04-22 21:23:00 +03:00
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
|
|
|
WORKING_DIRECTORY ${source_root_directory}
|
2024-11-12 12:25:51 +03:00
|
|
|
|
RESULT_VARIABLE _rc)
|
|
|
|
|
if(_rc OR _git_revision STREQUAL "")
|
2024-11-13 15:03:16 +03:00
|
|
|
|
message(
|
|
|
|
|
FATAL_ERROR
|
|
|
|
|
"Please install latest version of git (`rev-list --count --all --no-merges` failed)"
|
|
|
|
|
)
|
2020-06-12 21:01:41 +03:00
|
|
|
|
endif()
|
2024-11-12 12:25:51 +03:00
|
|
|
|
else(_tag_count EQUAL 0)
|
2024-11-13 15:03:16 +03:00
|
|
|
|
execute_process(
|
|
|
|
|
COMMAND ${GIT} describe --tags --long --dirty=-dirty "--match=v[0-9]*"
|
2024-11-12 12:25:51 +03:00
|
|
|
|
OUTPUT_VARIABLE _git_describe
|
2022-04-22 21:23:00 +03:00
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
|
|
|
WORKING_DIRECTORY ${source_root_directory}
|
2024-11-12 12:25:51 +03:00
|
|
|
|
RESULT_VARIABLE _rc)
|
|
|
|
|
if(_rc OR _git_describe STREQUAL "")
|
2024-11-13 15:03:16 +03:00
|
|
|
|
execute_process(
|
|
|
|
|
COMMAND ${GIT} rev-list --all --count
|
2024-11-12 12:25:51 +03:00
|
|
|
|
OUTPUT_VARIABLE _whole_count
|
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
|
|
|
WORKING_DIRECTORY ${source_root_directory}
|
2024-11-13 15:03:16 +03:00
|
|
|
|
RESULT_VARIABLE _rc)
|
|
|
|
|
if(_rc)
|
|
|
|
|
message(
|
|
|
|
|
FATAL_ERROR
|
|
|
|
|
"Please install latest version of git (`git rev-list --all --count` failed)"
|
|
|
|
|
)
|
2024-11-12 12:25:51 +03:00
|
|
|
|
endif()
|
2022-04-22 21:23:00 +03:00
|
|
|
|
if(_whole_count GREATER 42)
|
2024-11-13 15:03:16 +03:00
|
|
|
|
message(
|
|
|
|
|
FATAL_ERROR
|
|
|
|
|
"Please fetch tags (`describe --tags --long --dirty --match=v[0-9]*` failed)"
|
|
|
|
|
)
|
2022-04-22 21:23:00 +03:00
|
|
|
|
else()
|
2024-11-13 15:03:16 +03:00
|
|
|
|
execute_process(
|
|
|
|
|
COMMAND ${GIT} describe --all --long --dirty=-dirty
|
2024-11-12 12:25:51 +03:00
|
|
|
|
OUTPUT_VARIABLE _git_describe
|
2022-04-22 21:23:00 +03:00
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
|
|
|
WORKING_DIRECTORY ${source_root_directory}
|
2024-11-12 12:25:51 +03:00
|
|
|
|
RESULT_VARIABLE _rc)
|
|
|
|
|
if(_rc OR _git_describe STREQUAL "")
|
2024-11-13 15:03:16 +03:00
|
|
|
|
message(
|
|
|
|
|
FATAL_ERROR
|
|
|
|
|
"Please install latest version of git (`git rev-list --tags --count` and/or `git rev-list --all --count` failed)"
|
|
|
|
|
)
|
2022-04-22 21:23:00 +03:00
|
|
|
|
endif()
|
2020-10-19 16:19:48 +03:00
|
|
|
|
endif()
|
2022-04-22 21:23:00 +03:00
|
|
|
|
endif()
|
2019-08-31 17:13:02 +03:00
|
|
|
|
|
2024-11-13 15:03:16 +03:00
|
|
|
|
execute_process(
|
|
|
|
|
COMMAND ${GIT} describe --tags --abbrev=0 "--match=v[0-9]*"
|
2024-11-12 12:25:51 +03:00
|
|
|
|
OUTPUT_VARIABLE _last_release_tag
|
2022-04-22 21:23:00 +03:00
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
|
|
|
WORKING_DIRECTORY ${source_root_directory}
|
2024-11-12 12:25:51 +03:00
|
|
|
|
RESULT_VARIABLE _rc)
|
|
|
|
|
if(_rc)
|
2024-11-13 15:03:16 +03:00
|
|
|
|
message(
|
|
|
|
|
FATAL_ERROR
|
|
|
|
|
"Please install latest version of git (`describe --tags --abbrev=0 --match=v[0-9]*` failed)"
|
|
|
|
|
)
|
2022-04-22 21:23:00 +03:00
|
|
|
|
endif()
|
2024-11-13 15:03:16 +03:00
|
|
|
|
if(_last_release_tag)
|
2024-11-12 12:25:51 +03:00
|
|
|
|
set(_git_revlist_arg "${_last_release_tag}..HEAD")
|
2022-04-22 21:23:00 +03:00
|
|
|
|
else()
|
2024-11-13 15:03:16 +03:00
|
|
|
|
execute_process(
|
|
|
|
|
COMMAND ${GIT} tag --sort=-version:refname
|
2024-11-12 12:25:51 +03:00
|
|
|
|
OUTPUT_VARIABLE _tag_list
|
2022-04-22 21:23:00 +03:00
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
|
|
|
WORKING_DIRECTORY ${source_root_directory}
|
2024-11-12 12:25:51 +03:00
|
|
|
|
RESULT_VARIABLE _rc)
|
|
|
|
|
if(_rc)
|
2024-11-13 15:03:16 +03:00
|
|
|
|
message(
|
|
|
|
|
FATAL_ERROR
|
|
|
|
|
"Please install latest version of git (`tag --sort=-version:refname` failed)"
|
|
|
|
|
)
|
2022-04-22 21:23:00 +03:00
|
|
|
|
endif()
|
2024-11-12 12:25:51 +03:00
|
|
|
|
string(REGEX REPLACE "\n" ";" _tag_list "${_tag_list}")
|
|
|
|
|
set(_git_revlist_arg "HEAD")
|
|
|
|
|
foreach(_tag IN LISTS _tag_list)
|
|
|
|
|
if(NOT _last_release_tag)
|
2024-11-13 15:03:16 +03:00
|
|
|
|
string(REGEX MATCH "^v[0-9]+(\.[0-9]+)+" _last_release_tag
|
|
|
|
|
"${_tag}")
|
2024-11-12 12:25:51 +03:00
|
|
|
|
set(_git_revlist_arg "${_tag}..HEAD")
|
2022-04-22 21:23:00 +03:00
|
|
|
|
endif()
|
2024-11-12 12:25:51 +03:00
|
|
|
|
endforeach(_tag)
|
2022-04-22 21:23:00 +03:00
|
|
|
|
endif()
|
2024-11-13 15:03:16 +03:00
|
|
|
|
execute_process(
|
|
|
|
|
COMMAND ${GIT} rev-list --count "${_git_revlist_arg}"
|
2024-11-12 12:25:51 +03:00
|
|
|
|
OUTPUT_VARIABLE _git_revision
|
2022-04-22 21:23:00 +03:00
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
|
|
|
WORKING_DIRECTORY ${source_root_directory}
|
2024-11-12 12:25:51 +03:00
|
|
|
|
RESULT_VARIABLE _rc)
|
|
|
|
|
if(_rc OR _git_revision STREQUAL "")
|
2024-11-13 15:03:16 +03:00
|
|
|
|
message(
|
|
|
|
|
FATAL_ERROR
|
|
|
|
|
"Please install latest version of git (`rev-list --count ${_git_revlist_arg}` failed)"
|
|
|
|
|
)
|
2022-04-22 21:23:00 +03:00
|
|
|
|
endif()
|
|
|
|
|
|
2024-11-13 15:03:16 +03:00
|
|
|
|
string(REGEX MATCH "^(v)?([0-9]+)\\.([0-9]+)\\.([0-9]+)(.*)?"
|
|
|
|
|
_git_version_valid "${_git_describe}")
|
2024-11-12 12:25:51 +03:00
|
|
|
|
if(_git_version_valid)
|
2024-11-13 15:03:16 +03:00
|
|
|
|
string(REGEX REPLACE "^(v)?([0-9]+)\\.([0-9]+)\\.([0-9]+)(.*)?"
|
|
|
|
|
"\\2;\\3;\\4" _git_version ${_git_describe})
|
2019-08-31 17:13:02 +03:00
|
|
|
|
else()
|
2024-11-13 15:03:16 +03:00
|
|
|
|
string(REGEX MATCH "^(v)?([0-9]+)\\.([0-9]+)(.*)?" _git_version_valid
|
|
|
|
|
"${_git_describe}")
|
2024-11-12 12:25:51 +03:00
|
|
|
|
if(_git_version_valid)
|
2024-11-13 15:03:16 +03:00
|
|
|
|
string(REGEX REPLACE "^(v)?([0-9]+)\\.([0-9]+)(.*)?" "\\2;\\3;0"
|
|
|
|
|
_git_version ${_git_describe})
|
2022-04-22 21:23:00 +03:00
|
|
|
|
else()
|
2024-11-13 15:03:16 +03:00
|
|
|
|
message(
|
|
|
|
|
AUTHOR_WARNING
|
|
|
|
|
"Bad ${name} version \"${_git_describe}\"; falling back to 0.0.0 (have you made an initial release?)"
|
|
|
|
|
)
|
2024-11-12 12:25:51 +03:00
|
|
|
|
set(_git_version "0;0;0")
|
2022-04-22 21:23:00 +03:00
|
|
|
|
endif()
|
2019-08-31 17:13:02 +03:00
|
|
|
|
endif()
|
2024-11-12 12:25:51 +03:00
|
|
|
|
endif(_tag_count EQUAL 0)
|
2019-08-31 17:13:02 +03:00
|
|
|
|
|
2024-11-12 12:25:51 +03:00
|
|
|
|
list(APPEND _git_version "${_git_revision}")
|
|
|
|
|
set(_version_list "${_git_version}")
|
|
|
|
|
string(REPLACE ";" "." _version_4dot "${_version_list}")
|
2019-08-31 17:13:02 +03:00
|
|
|
|
|
2024-11-12 12:25:51 +03:00
|
|
|
|
elseif(GIT)
|
2024-11-13 15:03:16 +03:00
|
|
|
|
message(
|
|
|
|
|
FATAL_ERROR
|
|
|
|
|
"Нет источника информации о версии (${source_root_directory}), требуется один из: репозиторий git, либо VERSION.json"
|
|
|
|
|
)
|
2024-11-12 12:25:51 +03:00
|
|
|
|
else()
|
|
|
|
|
message(FATAL_ERROR "Требуется git для получения информации о версии")
|
|
|
|
|
endif()
|
2019-08-31 17:13:02 +03:00
|
|
|
|
|
2024-11-12 12:25:51 +03:00
|
|
|
|
list(LENGTH _version_list _version_list_length)
|
|
|
|
|
list(GET _version_list 0 _version_major)
|
|
|
|
|
list(GET _version_list 1 _version_minor)
|
|
|
|
|
list(GET _version_list 2 _version_release)
|
|
|
|
|
list(GET _version_list 3 _version_revision)
|
2019-08-31 17:13:02 +03:00
|
|
|
|
|
2024-11-13 15:03:16 +03:00
|
|
|
|
if(NOT _git_describe
|
|
|
|
|
OR NOT _git_timestamp
|
|
|
|
|
OR NOT _git_tree
|
|
|
|
|
OR NOT _git_commit
|
|
|
|
|
OR _git_revision STREQUAL ""
|
|
|
|
|
OR NOT _version_list_length EQUAL 4
|
|
|
|
|
OR _version_major STREQUAL ""
|
|
|
|
|
OR _version_minor STREQUAL ""
|
|
|
|
|
OR _version_release STREQUAL ""
|
|
|
|
|
OR _version_revision STREQUAL "")
|
2024-11-12 12:25:51 +03:00
|
|
|
|
message(ERROR "Unable to retrieve ${name} version from ${_version_from}.")
|
2019-08-31 17:13:02 +03:00
|
|
|
|
else()
|
2024-11-12 12:25:51 +03:00
|
|
|
|
list(APPEND _git_version "${_git_revision}")
|
2019-08-31 17:13:02 +03:00
|
|
|
|
endif()
|
|
|
|
|
|
2020-05-06 02:49:00 +03:00
|
|
|
|
if(${parent_scope})
|
2024-11-13 15:03:16 +03:00
|
|
|
|
set(${name}_VERSION_MAJOR
|
|
|
|
|
"${_version_major}"
|
|
|
|
|
PARENT_SCOPE)
|
|
|
|
|
set(${name}_VERSION_MINOR
|
|
|
|
|
"${_version_minor}"
|
|
|
|
|
PARENT_SCOPE)
|
|
|
|
|
set(${name}_VERSION_RELEASE
|
|
|
|
|
"${_version_release}"
|
|
|
|
|
PARENT_SCOPE)
|
|
|
|
|
set(${name}_VERSION_REVISION
|
|
|
|
|
"${_version_revision}"
|
|
|
|
|
PARENT_SCOPE)
|
|
|
|
|
set(${name}_VERSION
|
|
|
|
|
"${_version_4dot}"
|
|
|
|
|
PARENT_SCOPE)
|
2024-11-12 12:25:51 +03:00
|
|
|
|
|
2024-11-13 15:03:16 +03:00
|
|
|
|
set(${name}_GIT_DESCRIBE
|
|
|
|
|
"${_git_describe}"
|
|
|
|
|
PARENT_SCOPE)
|
|
|
|
|
set(${name}_GIT_TIMESTAMP
|
|
|
|
|
"${_git_timestamp}"
|
|
|
|
|
PARENT_SCOPE)
|
|
|
|
|
set(${name}_GIT_TREE
|
|
|
|
|
"${_git_tree}"
|
|
|
|
|
PARENT_SCOPE)
|
|
|
|
|
set(${name}_GIT_COMMIT
|
|
|
|
|
"${_git_commit}"
|
|
|
|
|
PARENT_SCOPE)
|
|
|
|
|
set(${name}_GIT_REVISION
|
|
|
|
|
"${_git_revision}"
|
|
|
|
|
PARENT_SCOPE)
|
2024-11-12 12:25:51 +03:00
|
|
|
|
else()
|
|
|
|
|
set(${name}_VERSION_MAJOR "${_version_major}")
|
|
|
|
|
set(${name}_VERSION_MINOR "${_version_minor}")
|
|
|
|
|
set(${name}_VERSION_RELEASE "${_version_release}")
|
|
|
|
|
set(${name}_VERSION_REVISION "${_version_revision}")
|
|
|
|
|
set(${name}_VERSION "${_version_4dot}")
|
|
|
|
|
|
|
|
|
|
set(${name}_GIT_DESCRIBE "${_git_describe}")
|
|
|
|
|
set(${name}_GIT_TIMESTAMP "${_git_timestamp}")
|
|
|
|
|
set(${name}_GIT_TREE "${_git_tree}")
|
|
|
|
|
set(${name}_GIT_COMMIT "${_git_commit}")
|
|
|
|
|
set(${name}_GIT_REVISION "${_git_revision}")
|
|
|
|
|
endif()
|
2020-05-06 02:49:00 +03:00
|
|
|
|
|
2024-11-12 12:25:51 +03:00
|
|
|
|
if(_version_from STREQUAL "git")
|
2024-11-13 15:03:16 +03:00
|
|
|
|
string(
|
|
|
|
|
CONFIGURE
|
|
|
|
|
"{
|
2024-11-12 12:25:51 +03:00
|
|
|
|
\"git_describe\" : \"@_git_describe@\",
|
|
|
|
|
\"git_timestamp\" : \"@_git_timestamp@\",
|
|
|
|
|
\"git_tree\" : \"@_git_tree@\",
|
|
|
|
|
\"git_commit\" : \"@_git_commit@\",
|
2024-11-13 15:03:16 +03:00
|
|
|
|
\"version_4dot\" : \"@_version_4dot@\"\n}"
|
|
|
|
|
_versioninfo_json
|
|
|
|
|
@ONLY ESCAPE_QUOTES)
|
|
|
|
|
file(WRITE "${build_directory_for_json_output}/VERSION.json"
|
|
|
|
|
"${_versioninfo_json}")
|
2020-04-15 17:09:37 +03:00
|
|
|
|
endif()
|
2019-08-31 17:13:02 +03:00
|
|
|
|
endmacro(fetch_version)
|
|
|
|
|
|
|
|
|
|
cmake_policy(POP)
|