cmake: add build counter

Signed-off-by: Janusz Jankowski <janusz.jankowski@linux.intel.com>
This commit is contained in:
Janusz Jankowski 2019-02-08 22:49:47 +01:00 committed by Liam Girdwood
parent 46730e89c6
commit a4f666527e
3 changed files with 44 additions and 3 deletions

View File

@ -37,9 +37,10 @@ include(scripts/cmake/misc.cmake)
project(SOF C ASM)
# intended to be used where PROJECT_SOURCE_DIR is not set
# intended to be used where PROJECT_* variables are not set
# for example in standalone scripts like version.cmake
set(SOF_ROOT_SOURCE_DIRECTORY "${PROJECT_SOURCE_DIR}")
set(SOF_ROOT_BINARY_DIRECTORY "${PROJECT_BINARY_DIR}")
# most of other options are set on per-arch and per-target basis
set(CMAKE_ASM_FLAGS -DASSEMBLY)
@ -126,6 +127,8 @@ target_link_libraries(sof sof_options)
target_link_libraries(sof sof_ld_scripts)
target_link_libraries(sof sof_ld_flags)
sof_add_build_counter_rule()
add_subdirectory(src)
target_link_libraries(sof sof_lib)

View File

@ -0,0 +1,37 @@
# Implements build counter and adds it as post-build action for sof
cmake_minimum_required(VERSION 3.10)
set(VERSION_BUILD_COUNTER_CMAKE_PATH ${CMAKE_CURRENT_LIST_DIR}/version-build-counter.cmake)
set(BUILD_COUNTER_PATH "${SOF_ROOT_BINARY_DIRECTORY}/.build")
if(NOT EXISTS "${BUILD_COUNTER_PATH}")
file(WRITE "${BUILD_COUNTER_PATH}" "1")
endif()
file(READ "${BUILD_COUNTER_PATH}" SOF_BUILD)
if(NOT SOF_BUILD MATCHES "^[0-9]+$")
message(WARNING "Invalid SOF_BUILD - setting to 1")
set(SOF_BUILD 1)
endif()
function(sof_add_build_counter_rule)
add_custom_command(
TARGET sof
POST_BUILD
COMMAND ${CMAKE_COMMAND}
-DSOF_ROOT_BINARY_DIRECTORY=${SOF_ROOT_BINARY_DIRECTORY}
-DBUILD_COUNTER_INCREMENT=ON
-P ${VERSION_BUILD_COUNTER_CMAKE_PATH}
COMMENT "Incrementing build number in ${BUILD_COUNTER_PATH}"
VERBATIM
USES_TERMINAL
)
endfunction()
if(BUILD_COUNTER_INCREMENT)
MATH(EXPR NEXT_SOF_BUILD "(${SOF_BUILD} + 1) % 65536")
file(WRITE "${BUILD_COUNTER_PATH}" ${NEXT_SOF_BUILD})
endif()

View File

@ -50,8 +50,8 @@ if(NOT SOF_TAG)
set(SOF_TAG 0)
endif()
# TODO
set(SOF_BUILD 0)
# for SOF_BUILD
include(${CMAKE_CURRENT_LIST_DIR}/version-build-counter.cmake)
function(sof_check_version_h)
string(CONCAT header_content
@ -82,6 +82,7 @@ if("${CMAKE_SCRIPT_MODE_FILE}" STREQUAL "")
COMMAND ${CMAKE_COMMAND}
-DVERSION_H_PATH=${VERSION_H_PATH}
-DSOF_ROOT_SOURCE_DIRECTORY=${SOF_ROOT_SOURCE_DIRECTORY}
-DSOF_ROOT_BINARY_DIRECTORY=${SOF_ROOT_BINARY_DIRECTORY}
-P ${VERSION_CMAKE_PATH}
COMMENT "Checking ${VERSION_H_PATH}"
VERBATIM