Dosyalar
rocm-systems/cmake_modules/rocprofiler_utils.cmake
T

115 satır
3.7 KiB
CMake
Ham Normal Görünüm Geçmiş

2017-11-09 17:26:19 -06:00
################################################################################
2018-08-19 04:11:04 -05:00
# Copyright (c) 2018 Advanced Micro Devices, Inc. All rights reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
2017-11-09 17:26:19 -06:00
################################################################################
2023-07-13 19:48:38 +00:00
# Parses the VERSION_STRING variable and places the first, second and third number values
# in the major, minor and patch variables.
2023-08-21 15:08:31 +00:00
function(rocprofiler_parse_version VERSION_STRING)
2023-07-13 19:48:38 +00:00
string(FIND ${VERSION_STRING} "-" STRING_INDEX)
if(${STRING_INDEX} GREATER -1)
math(EXPR STRING_INDEX "${STRING_INDEX} + 1")
string(SUBSTRING ${VERSION_STRING} ${STRING_INDEX} -1 VERSION_BUILD)
endif()
string(REGEX MATCHALL "[0123456789]+" VERSIONS ${VERSION_STRING})
list(LENGTH VERSIONS VERSION_COUNT)
if(${VERSION_COUNT} GREATER 0)
list(GET VERSIONS 0 MAJOR)
set(VERSION_MAJOR
${MAJOR}
PARENT_SCOPE)
set(TEMP_VERSION_STRING "${MAJOR}")
endif()
if(${VERSION_COUNT} GREATER 1)
list(GET VERSIONS 1 MINOR)
set(VERSION_MINOR
${MINOR}
PARENT_SCOPE)
set(TEMP_VERSION_STRING "${TEMP_VERSION_STRING}.${MINOR}")
endif()
if(${VERSION_COUNT} GREATER 2)
list(GET VERSIONS 2 PATCH)
set(VERSION_PATCH
${PATCH}
PARENT_SCOPE)
set(TEMP_VERSION_STRING "${TEMP_VERSION_STRING}.${PATCH}")
endif()
if(DEFINED VERSION_BUILD)
set(VERSION_BUILD
"${VERSION_BUILD}"
PARENT_SCOPE)
endif()
set(VERSION_STRING
"${TEMP_VERSION_STRING}"
PARENT_SCOPE)
2017-11-09 17:26:19 -06:00
2023-07-13 19:48:38 +00:00
endfunction()
2017-11-09 17:26:19 -06:00
2023-07-13 19:48:38 +00:00
# Gets the current version of the repository using versioning tags and git describe.
# Passes back a packaging version string and a library version string.
2023-08-21 15:08:31 +00:00
function(rocprofiler_get_version DEFAULT_VERSION_STRING)
2017-11-09 17:26:19 -06:00
2023-08-21 15:08:31 +00:00
rocprofiler_parse_version(${DEFAULT_VERSION_STRING})
2017-11-09 17:26:19 -06:00
2023-07-13 19:48:38 +00:00
find_program(GIT NAMES git)
2017-11-09 17:26:19 -06:00
2023-07-13 19:48:38 +00:00
if(GIT)
2017-11-09 17:26:19 -06:00
2023-07-13 19:48:38 +00:00
execute_process(
COMMAND "git describe --dirty --long --match [0-9]* 2>/dev/null"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE GIT_TAG_STRING
OUTPUT_STRIP_TRAILING_WHITESPACE
RESULT_VARIABLE RESULT)
2017-11-09 17:26:19 -06:00
2023-07-13 19:48:38 +00:00
if(${RESULT} EQUAL 0)
2017-11-09 17:26:19 -06:00
2023-08-21 15:08:31 +00:00
rocprofiler_parse_version(${GIT_TAG_STRING})
2017-11-09 17:26:19 -06:00
2023-07-13 19:48:38 +00:00
endif()
2017-11-09 17:26:19 -06:00
2023-07-13 19:48:38 +00:00
endif()
2017-11-09 17:26:19 -06:00
2023-07-13 19:48:38 +00:00
set(VERSION_STRING
"${VERSION_STRING}"
PARENT_SCOPE)
set(VERSION_MAJOR
"${VERSION_MAJOR}"
PARENT_SCOPE)
set(VERSION_MINOR
"${VERSION_MINOR}"
PARENT_SCOPE)
set(VERSION_PATCH
"${VERSION_PATCH}"
PARENT_SCOPE)
set(VERSION_BUILD
"${VERSION_BUILD}"
PARENT_SCOPE)
2017-11-09 17:26:19 -06:00
endfunction()