@@ -21,7 +21,7 @@ set(VERSION_CMAKE_PATH ${CMAKE_CURRENT_LIST_DIR}/version.cmake)
2121# In the real world, some CI results use a random timezone without
2222# telling which one or don't provide any time at all.
2323string (TIMESTAMP build_start_time UTC)
24- message (STATUS "version.cmake starting SOF build at ${build_start_time} UTC" )
24+ message (STATUS "SOF version.cmake starting at ${build_start_time} UTC" )
2525
2626# Most CI engines test a temporary merge of the pull request with a
2727# moving target: the latest target branch. In that case the SHA version
@@ -124,6 +124,13 @@ endif()
124124# for SOF_BUILD
125125include (${CMAKE_CURRENT_LIST_DIR} /version -build -counter.cmake)
126126
127+ # (Re)-generate "${VERSION_H_PATH}" but overwrite the old one only if
128+ # different to avoid a full rebuild. TODO: check how Zephyr solves this
129+ # problem, see Zephyr commit 91709778a4878c
130+ #
131+ # This function is called only below; not supposed to be used elsewhere.
132+ # This entire file is run at CMake configure time _and_ invoked
133+ # again at build time.
127134function (sof_check_version_h)
128135 string (CONCAT header_content
129136 "#define SOF_MAJOR ${SOF_MAJOR} \n "
@@ -135,20 +142,24 @@ function(sof_check_version_h)
135142 "#define SOF_SRC_HASH 0x${SOF_SRC_HASH} \n "
136143 )
137144
138- # Regenerating the same file would cause a full rebuild.
139145 if (EXISTS "${VERSION_H_PATH} " )
140146 file (READ "${VERSION_H_PATH} " old_version_content)
141147 if ("${header_content} " STREQUAL "${old_version_content} " )
142- message (STATUS "Up-to-date ${VERSION_H_PATH} " )
148+ message (STATUS "Unchanged ${VERSION_H_PATH} " )
143149 return ()
144150 endif ()
145- endif ()
151+ endif ()
146152
147- message (STATUS "Generating ${VERSION_H_PATH} " )
148153 file (WRITE "${VERSION_H_PATH} " "${header_content} " )
154+ message (STATUS "Generated new ${VERSION_H_PATH} " )
149155endfunction ()
150156
151- # Run these only if not run as script
157+ # This ${VERSION_CMAKE_PATH} file is run in two (very) different ways:
158+ #
159+ # 1. explicitly included by some other, top-level CMakeLists.txt file, and
160+ # 2. directly and "recursively" invoking itself with 'cmake -P myself' here.
161+ #
162+ # Add this check_version_h target only in case 1. (no "infinite recursion")
152163if ("${CMAKE_SCRIPT_MODE_FILE} " STREQUAL "" )
153164 add_custom_target (
154165 check_version_h
@@ -158,7 +169,7 @@ if("${CMAKE_SCRIPT_MODE_FILE}" STREQUAL "")
158169 -DSOF_ROOT_SOURCE_DIRECTORY=${SOF_ROOT_SOURCE_DIRECTORY}
159170 -DSOF_ROOT_BINARY_DIRECTORY=${SOF_ROOT_BINARY_DIRECTORY}
160171 -P ${VERSION_CMAKE_PATH}
161- COMMENT "Checking ${VERSION_H_PATH } "
172+ COMMENT "cmake -P ${VERSION_CMAKE_PATH } "
162173 VERBATIM
163174 USES_TERMINAL
164175 )
0 commit comments