cmake: generated application version header when VERSION file is present

Allow applications to create a VERSION file in their application folder.

The presence of a VERSION file will create a app_version_h target which
generates an app_version.h file using same infrastructure as the Zephyr
kernel version.h generation.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
This commit is contained in:
Torsten Rasmussen 2023-03-23 08:45:26 +01:00 committed by Carles Cufí
commit 99064c2646

View file

@ -552,6 +552,21 @@ add_custom_command(
) )
add_custom_target(version_h DEPENDS ${PROJECT_BINARY_DIR}/include/generated/version.h) add_custom_target(version_h DEPENDS ${PROJECT_BINARY_DIR}/include/generated/version.h)
if(EXISTS ${APPLICATION_SOURCE_DIR}/VERSION)
add_custom_command(
OUTPUT ${PROJECT_BINARY_DIR}/include/generated/app_version.h
COMMAND ${CMAKE_COMMAND} -DZEPHYR_BASE=${ZEPHYR_BASE}
-DOUT_FILE=${PROJECT_BINARY_DIR}/include/generated/app_version.h
-DVERSION_TYPE=APP
-DVERSION_FILE=${APPLICATION_SOURCE_DIR}/VERSION
${build_version_argument}
-P ${ZEPHYR_BASE}/cmake/gen_version_h.cmake
DEPENDS ${APPLICATION_SOURCE_DIR}/VERSION ${git_dependency}
)
add_custom_target(app_version_h DEPENDS ${PROJECT_BINARY_DIR}/include/generated/app_version.h)
add_dependencies(zephyr_interface app_version_h)
endif()
# Unfortunately, the order in which CMakeLists.txt code is processed # Unfortunately, the order in which CMakeLists.txt code is processed
# matters so we need to be careful about how we order the processing # matters so we need to be careful about how we order the processing
# of subdirectories. One example is "Compiler flags added late in the # of subdirectories. One example is "Compiler flags added late in the