forked from thesofproject/sof
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathversion-build-counter.cmake
More file actions
39 lines (30 loc) · 1.03 KB
/
version-build-counter.cmake
File metadata and controls
39 lines (30 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# SPDX-License-Identifier: BSD-3-Clause
# 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()