Skip to content

Commit

Permalink
cmake: add build counter
Browse files Browse the repository at this point in the history
Signed-off-by: Janusz Jankowski <[email protected]>
  • Loading branch information
jajanusz authored and lgirdwood committed Feb 11, 2019
1 parent 46730e8 commit a4f6665
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 3 deletions.
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
37 changes: 37 additions & 0 deletions scripts/cmake/version-build-counter.cmake
Original file line number Diff line number Diff line change
@@ -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()
5 changes: 3 additions & 2 deletions scripts/cmake/version.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a4f6665

Please sign in to comment.