mirror of https://github.com/oxen-io/oxen-core.git
Better version tag generation (from oxenss/lokinet)
This commit is contained in:
parent
d229bc77ed
commit
507a9d22ea
|
@ -1,4 +1,5 @@
|
|||
# Copyright (c) 2014-2018, The Monero Project
|
||||
# Copyright (c) 2019-2022, The Oxen Project
|
||||
#
|
||||
# All rights reserved.
|
||||
#
|
||||
|
@ -33,32 +34,27 @@ execute_process(COMMAND "${GIT}" rev-parse --short=9 HEAD RESULT_VARIABLE RET OU
|
|||
|
||||
if(RET)
|
||||
# Something went wrong, set the version tag to -unknown
|
||||
|
||||
message(WARNING "Cannot determine current commit. Make sure that you are building either from a Git working tree or from a source archive.")
|
||||
set(VERSIONTAG "unknown")
|
||||
configure_file("version.cpp.in" "version.cpp")
|
||||
else()
|
||||
string(SUBSTRING ${COMMIT} 0 9 COMMIT)
|
||||
message(STATUS "You are currently on commit ${COMMIT}")
|
||||
|
||||
|
||||
# Get all the tags
|
||||
execute_process(COMMAND "${GIT}" rev-list --tags --max-count=1 --abbrev-commit RESULT_VARIABLE RET OUTPUT_VARIABLE TAGGEDCOMMIT OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
|
||||
|
||||
if(NOT TAGGEDCOMMIT)
|
||||
message(WARNING "Cannot determine most recent tag. Make sure that you are building either from a Git working tree or from a source archive.")
|
||||
set(VERSIONTAG "${COMMIT}")
|
||||
else()
|
||||
message(STATUS "The most recent tag was at ${TAGGEDCOMMIT}")
|
||||
|
||||
# Check if we're building that tagged commit or a different one
|
||||
if(COMMIT STREQUAL TAGGEDCOMMIT)
|
||||
message(STATUS "You are building a tagged release")
|
||||
message(STATUS "${COMMIT} is a tagged release; setting version tag to 'release'")
|
||||
set(VERSIONTAG "release")
|
||||
else()
|
||||
message(STATUS "You are ahead of or behind a tagged release")
|
||||
message(STATUS "You are not building a tagged release; setting version tag to '${COMMIT}'")
|
||||
set(VERSIONTAG "${COMMIT}")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
configure_file("version.cpp.in" "version.cpp")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
configure_file("${SRC}" "${DEST}" @ONLY)
|
||||
|
|
|
@ -1,55 +0,0 @@
|
|||
# Copyright (c) 2014-2018, The Monero Project
|
||||
#
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without modification, are
|
||||
# permitted provided that the following conditions are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
# conditions and the following disclaimer.
|
||||
#
|
||||
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
# of conditions and the following disclaimer in the documentation and/or other
|
||||
# materials provided with the distribution.
|
||||
#
|
||||
# 3. Neither the name of the copyright holder nor the names of its contributors may be
|
||||
# used to endorse or promote products derived from this software without specific
|
||||
# prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
# THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
||||
# THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
function (write_static_version_header hash)
|
||||
set(VERSIONTAG "${hash}")
|
||||
configure_file("${CMAKE_SOURCE_DIR}/src/version.cpp.in" "${CMAKE_BINARY_DIR}/version.cpp")
|
||||
endfunction ()
|
||||
|
||||
find_package(Git QUIET)
|
||||
set(GIT_INDEX_FILE "${PROJECT_SOURCE_DIR}/.git/index")
|
||||
if(EXISTS "${GIT_INDEX_FILE}" AND ( GIT_FOUND OR Git_FOUND) )
|
||||
message(STATUS "Found Git: ${GIT_EXECUTABLE}")
|
||||
set(VERSIONTAG "@VERSIONTAG@") # Will be replaced again by GenVersion.cmake, below.
|
||||
configure_file("${CMAKE_SOURCE_DIR}/src/version.cpp.in" "${CMAKE_BINARY_DIR}/version.cpp.in")
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT "${CMAKE_BINARY_DIR}/version.cpp"
|
||||
COMMAND "${CMAKE_COMMAND}"
|
||||
"-D" "GIT=${GIT_EXECUTABLE}"
|
||||
"-P" "${CMAKE_SOURCE_DIR}/cmake/GenVersion.cmake"
|
||||
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}"
|
||||
DEPENDS "${CMAKE_BINARY_DIR}/version.cpp.in"
|
||||
"${CMAKE_SOURCE_DIR}/src/version.cpp.in"
|
||||
"${GIT_INDEX_FILE}")
|
||||
else()
|
||||
message(WARNING "Git was not found; setting release tag to 'unknown'")
|
||||
write_static_version_header("unknown")
|
||||
endif()
|
||||
add_custom_target(genversion ALL
|
||||
DEPENDS "${CMAKE_BINARY_DIR}/version.cpp")
|
|
@ -47,10 +47,6 @@ function (oxen_add_executable target binary)
|
|||
set_property(GLOBAL PROPERTY oxen_executable_targets "${exec_tgt}")
|
||||
endfunction ()
|
||||
|
||||
include(Version)
|
||||
add_library(version ${CMAKE_BINARY_DIR}/version.cpp)
|
||||
add_dependencies(version genversion)
|
||||
|
||||
add_subdirectory(common)
|
||||
add_subdirectory(crypto)
|
||||
add_subdirectory(ringct)
|
||||
|
@ -92,3 +88,38 @@ endif()
|
|||
|
||||
add_subdirectory(device)
|
||||
add_subdirectory(device_trezor)
|
||||
|
||||
|
||||
if(OXEN_VERSIONTAG)
|
||||
set(VERSIONTAG "${OXEN_VERSIONTAG}")
|
||||
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/version.cpp.in" "${CMAKE_CURRENT_BINARY_DIR}/version.cpp")
|
||||
else()
|
||||
set(GIT_INDEX_FILE "${PROJECT_SOURCE_DIR}/.git/index")
|
||||
find_package(Git)
|
||||
if(EXISTS ${GIT_INDEX_FILE} AND ( GIT_FOUND OR Git_FOUND) )
|
||||
message(STATUS "Found Git: ${GIT_EXECUTABLE}")
|
||||
|
||||
set(genversion_args "-DGIT=${GIT_EXECUTABLE}")
|
||||
foreach(v oxen_VERSION oxen_VERSION_MAJOR oxen_VERSION_MINOR oxen_VERSION_PATCH OXEN_RELEASE_CODENAME OXEN_RELEASE_SUFFIX)
|
||||
list(APPEND genversion_args "-D${v}=${${v}}")
|
||||
endforeach()
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/version.cpp"
|
||||
COMMAND
|
||||
"${CMAKE_COMMAND}"
|
||||
${genversion_args}
|
||||
"-DSRC=${CMAKE_CURRENT_SOURCE_DIR}/version.cpp.in"
|
||||
"-DDEST=${CMAKE_CURRENT_BINARY_DIR}/version.cpp"
|
||||
"-P" "${PROJECT_SOURCE_DIR}/cmake/GenVersion.cmake"
|
||||
DEPENDS
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/version.cpp.in"
|
||||
"${GIT_INDEX_FILE}")
|
||||
else()
|
||||
message(STATUS "Git was not found! Setting version tag to to nogit")
|
||||
set(VERSIONTAG "nogit")
|
||||
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/version.cpp.in" "${CMAKE_CURRENT_BINARY_DIR}/version.cpp")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
add_library(version "${CMAKE_CURRENT_BINARY_DIR}/version.cpp")
|
||||
|
|
|
@ -2,9 +2,9 @@
|
|||
|
||||
using namespace std::literals;
|
||||
|
||||
const std::array<uint16_t, 3> OXEN_VERSION = {@PROJECT_VERSION_MAJOR@, @PROJECT_VERSION_MINOR@, @PROJECT_VERSION_PATCH@};
|
||||
const std::array<uint16_t, 3> OXEN_VERSION = {@oxen_VERSION_MAJOR@, @oxen_VERSION_MINOR@, @oxen_VERSION_PATCH@};
|
||||
|
||||
const std::string_view OXEN_VERSION_TAG = "@VERSIONTAG@"sv;
|
||||
const std::string_view OXEN_VERSION_STR = "@PROJECT_VERSION@"sv;
|
||||
const std::string_view OXEN_VERSION_STR = "@oxen_VERSION@"sv;
|
||||
const std::string_view OXEN_RELEASE_NAME = "@OXEN_RELEASE_CODENAME@"sv;
|
||||
const std::string_view OXEN_VERSION_FULL = "@PROJECT_VERSION@-@VERSIONTAG@@OXEN_RELEASE_SUFFIX@"sv;
|
||||
const std::string_view OXEN_VERSION_FULL = "@oxen_VERSION@-@VERSIONTAG@@OXEN_RELEASE_SUFFIX@"sv;
|
||||
|
|
Loading…
Reference in New Issue