2019-06-02 03:33:40 +08:00
|
|
|
# SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
|
2019-02-08 08:16:09 +08:00
|
|
|
# Generates header for which version is taken from (in order of precedence):
|
|
|
|
# 1) .tarball-version file
|
|
|
|
# 2) git
|
|
|
|
#
|
|
|
|
# Version is checked during configuration step and for every target
|
|
|
|
# that has check_version_h target as dependency
|
|
|
|
|
2019-01-12 03:58:24 +08:00
|
|
|
cmake_minimum_required(VERSION 3.10)
|
|
|
|
|
2019-02-08 08:16:09 +08:00
|
|
|
set(VERSION_CMAKE_PATH ${CMAKE_CURRENT_LIST_DIR}/version.cmake)
|
|
|
|
|
2019-02-05 19:41:25 +08:00
|
|
|
set(TARBALL_VERSION_FILE_NAME ".tarball-version")
|
2019-02-08 08:16:09 +08:00
|
|
|
set(TARBALL_VERSION_SOURCE_PATH "${SOF_ROOT_SOURCE_DIRECTORY}/${TARBALL_VERSION_FILE_NAME}")
|
2019-01-12 03:58:24 +08:00
|
|
|
|
2019-02-05 19:41:25 +08:00
|
|
|
if(EXISTS ${TARBALL_VERSION_SOURCE_PATH})
|
|
|
|
file(STRINGS ${TARBALL_VERSION_SOURCE_PATH} lines ENCODING "UTF-8")
|
|
|
|
list(GET lines 0 GIT_TAG)
|
|
|
|
list(GET lines 1 GIT_LOG_HASH)
|
|
|
|
message(STATUS "Found ${TARBALL_VERSION_FILE_NAME}")
|
|
|
|
message(STATUS "Version: ${GIT_TAG} / ${GIT_LOG_HASH}")
|
|
|
|
else()
|
|
|
|
execute_process(COMMAND git describe --abbrev=4
|
|
|
|
OUTPUT_VARIABLE GIT_TAG
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
|
|
ERROR_QUIET
|
|
|
|
)
|
|
|
|
|
|
|
|
execute_process(COMMAND git log --pretty=format:%h -1
|
|
|
|
OUTPUT_VARIABLE GIT_LOG_HASH
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
|
|
ERROR_QUIET
|
|
|
|
)
|
|
|
|
endif()
|
2019-01-12 03:58:24 +08:00
|
|
|
|
|
|
|
if(NOT GIT_TAG MATCHES "^v")
|
|
|
|
set(GIT_TAG "v0.0-0-g0000")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
string(REGEX MATCH "^v([0-9]+)[.]([0-9]+)([.]([0-9]+))?" ignored "${GIT_TAG}")
|
|
|
|
set(SOF_MAJOR ${CMAKE_MATCH_1})
|
|
|
|
set(SOF_MINOR ${CMAKE_MATCH_2})
|
|
|
|
set(SOF_MICRO ${CMAKE_MATCH_4})
|
|
|
|
|
|
|
|
if(NOT SOF_MICRO MATCHES "^[0-9]+$")
|
|
|
|
set(SOF_MICRO 0)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
string(SUBSTRING "${GIT_LOG_HASH}" 0 5 SOF_TAG)
|
|
|
|
if(NOT SOF_TAG)
|
|
|
|
set(SOF_TAG 0)
|
|
|
|
endif()
|
|
|
|
|
2019-02-09 05:49:47 +08:00
|
|
|
# for SOF_BUILD
|
|
|
|
include(${CMAKE_CURRENT_LIST_DIR}/version-build-counter.cmake)
|
2019-01-12 03:58:24 +08:00
|
|
|
|
2019-02-08 08:16:09 +08:00
|
|
|
function(sof_check_version_h)
|
2019-01-12 03:58:24 +08:00
|
|
|
string(CONCAT header_content
|
|
|
|
"#define SOF_MAJOR ${SOF_MAJOR}\n"
|
|
|
|
"#define SOF_MINOR ${SOF_MINOR}\n"
|
|
|
|
"#define SOF_MICRO ${SOF_MICRO}\n"
|
|
|
|
"#define SOF_TAG \"${SOF_TAG}\"\n"
|
|
|
|
"#define SOF_BUILD ${SOF_BUILD}\n"
|
|
|
|
)
|
|
|
|
|
2019-02-08 08:16:09 +08:00
|
|
|
if(EXISTS "${VERSION_H_PATH}")
|
|
|
|
file(READ "${VERSION_H_PATH}" old_version_content)
|
|
|
|
if("${header_content}" STREQUAL "${old_version_content}")
|
|
|
|
message(STATUS "Up-to-date ${VERSION_H_PATH}")
|
2019-01-12 03:58:24 +08:00
|
|
|
return()
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2019-02-08 08:16:09 +08:00
|
|
|
message(STATUS "Generating ${VERSION_H_PATH}")
|
|
|
|
file(WRITE "${VERSION_H_PATH}" "${header_content}")
|
2019-01-12 03:58:24 +08:00
|
|
|
endfunction()
|
|
|
|
|
2019-02-08 08:16:09 +08:00
|
|
|
# Run these only if not run as script
|
|
|
|
if("${CMAKE_SCRIPT_MODE_FILE}" STREQUAL "")
|
|
|
|
add_custom_target(
|
|
|
|
check_version_h
|
|
|
|
BYPRODUCTS ${VERSION_H_PATH}
|
|
|
|
COMMAND ${CMAKE_COMMAND}
|
|
|
|
-DVERSION_H_PATH=${VERSION_H_PATH}
|
|
|
|
-DSOF_ROOT_SOURCE_DIRECTORY=${SOF_ROOT_SOURCE_DIRECTORY}
|
2019-02-09 05:49:47 +08:00
|
|
|
-DSOF_ROOT_BINARY_DIRECTORY=${SOF_ROOT_BINARY_DIRECTORY}
|
2019-02-08 08:16:09 +08:00
|
|
|
-P ${VERSION_CMAKE_PATH}
|
|
|
|
COMMENT "Checking ${VERSION_H_PATH}"
|
2019-01-12 03:58:24 +08:00
|
|
|
VERBATIM
|
|
|
|
USES_TERMINAL
|
|
|
|
)
|
2019-02-08 08:16:09 +08:00
|
|
|
endif()
|
2019-01-12 03:58:24 +08:00
|
|
|
|
2019-02-08 08:16:09 +08:00
|
|
|
sof_check_version_h()
|