mirror of https://github.com/thesofproject/sof.git
cmake: refactor version.h rule
Signed-off-by: Janusz Jankowski <janusz.jankowski@linux.intel.com>
This commit is contained in:
parent
72871397f2
commit
46730e89c6
|
@ -37,6 +37,10 @@ include(scripts/cmake/misc.cmake)
|
|||
|
||||
project(SOF C ASM)
|
||||
|
||||
# intended to be used where PROJECT_SOURCE_DIR is not set
|
||||
# for example in standalone scripts like version.cmake
|
||||
set(SOF_ROOT_SOURCE_DIRECTORY "${PROJECT_SOURCE_DIR}")
|
||||
|
||||
# most of other options are set on per-arch and per-target basis
|
||||
set(CMAKE_ASM_FLAGS -DASSEMBLY)
|
||||
|
||||
|
@ -74,7 +78,6 @@ set(CONFIG_H_PATH ${GENERATED_DIRECTORY}/include/config.h)
|
|||
set(VERSION_H_PATH ${GENERATED_DIRECTORY}/include/version.h)
|
||||
|
||||
include(scripts/cmake/version.cmake)
|
||||
sof_add_version_h_rule(${PROJECT_SOURCE_DIR}/scripts/cmake/version.cmake)
|
||||
|
||||
include(scripts/cmake/dist.cmake)
|
||||
|
||||
|
@ -103,7 +106,7 @@ endif()
|
|||
|
||||
include(scripts/cmake/kconfig.cmake)
|
||||
|
||||
add_dependencies(sof_options genconfig)
|
||||
add_dependencies(sof_options genconfig check_version_h)
|
||||
target_include_directories(sof_options INTERFACE ${GENERATED_DIRECTORY}/include)
|
||||
|
||||
if(BUILD_UNIT_TESTS)
|
||||
|
|
|
@ -1,7 +1,16 @@
|
|||
# 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
|
||||
|
||||
cmake_minimum_required(VERSION 3.10)
|
||||
|
||||
set(VERSION_CMAKE_PATH ${CMAKE_CURRENT_LIST_DIR}/version.cmake)
|
||||
|
||||
set(TARBALL_VERSION_FILE_NAME ".tarball-version")
|
||||
set(TARBALL_VERSION_SOURCE_PATH "${PROJECT_SOURCE_DIR}/${TARBALL_VERSION_FILE_NAME}")
|
||||
set(TARBALL_VERSION_SOURCE_PATH "${SOF_ROOT_SOURCE_DIRECTORY}/${TARBALL_VERSION_FILE_NAME}")
|
||||
|
||||
if(EXISTS ${TARBALL_VERSION_SOURCE_PATH})
|
||||
file(STRINGS ${TARBALL_VERSION_SOURCE_PATH} lines ENCODING "UTF-8")
|
||||
|
@ -44,7 +53,7 @@ endif()
|
|||
# TODO
|
||||
set(SOF_BUILD 0)
|
||||
|
||||
function(sof_check_version_h version_h_path)
|
||||
function(sof_check_version_h)
|
||||
string(CONCAT header_content
|
||||
"#define SOF_MAJOR ${SOF_MAJOR}\n"
|
||||
"#define SOF_MINOR ${SOF_MINOR}\n"
|
||||
|
@ -53,25 +62,31 @@ function(sof_check_version_h version_h_path)
|
|||
"#define SOF_BUILD ${SOF_BUILD}\n"
|
||||
)
|
||||
|
||||
if(EXISTS "${version_h_path}")
|
||||
file(READ "${version_h_path}" old_version_content)
|
||||
if(header_content STREQUAL old_version_content)
|
||||
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}")
|
||||
return()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
message(STATUS "Generating ${version_h_path}")
|
||||
file(WRITE "${version_h_path}" "${header_content}")
|
||||
message(STATUS "Generating ${VERSION_H_PATH}")
|
||||
file(WRITE "${VERSION_H_PATH}" "${header_content}")
|
||||
endfunction()
|
||||
|
||||
function(sof_add_version_h_rule
|
||||
version_cmake_path)
|
||||
|
||||
add_custom_command(OUTPUT ${VERSION_H_PATH}
|
||||
COMMAND ${CMAKE_COMMAND} -DVERSION_H_PATH=${VERSION_H_PATH} -P ${version_cmake_path}
|
||||
# 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}
|
||||
-P ${VERSION_CMAKE_PATH}
|
||||
COMMENT "Checking ${VERSION_H_PATH}"
|
||||
VERBATIM
|
||||
USES_TERMINAL
|
||||
)
|
||||
endfunction()
|
||||
endif()
|
||||
|
||||
sof_check_version_h("${VERSION_H_PATH}")
|
||||
sof_check_version_h()
|
||||
|
|
|
@ -201,6 +201,7 @@ target_link_libraries(sof_ld_flags INTERFACE "-T${PROJECT_BINARY_DIR}/${platform
|
|||
include(ExternalProject)
|
||||
|
||||
ExternalProject_Add(rimage_ep
|
||||
DEPENDS check_version_h
|
||||
DOWNLOAD_COMMAND ""
|
||||
SOURCE_DIR "${PROJECT_SOURCE_DIR}/rimage"
|
||||
PREFIX "${PROJECT_BINARY_DIR}/rimage_ep"
|
||||
|
|
Loading…
Reference in New Issue