From 96a0d4e857edbbb03a336cbb06c027355bfb75fc Mon Sep 17 00:00:00 2001 From: Torsten Rasmussen Date: Thu, 7 Sep 2023 12:47:44 +0200 Subject: [PATCH] [nrf fromlist] cmake: Zephyr kernel version.h and app_version.h creation Move the custom commands creating the version.h and app_version.h below the Zephyr modules sourcing. This allows custom user specific Zephyr modules to adjust the value of KERNEL_VERSION_CUSTOMIZATION and APP_VERSION_CUSTOMIZATION values and thereby make use of the functionality introduced with #61635. The creation of the version_h and app_version_h targets, which drives the custom commands, are kept at their current location. This ensure that the targets themselves are still defined when the Zephyr and Zephyr modules CMakeLists trees are sourced. Upstream PR: https://github.com/zephyrproject-rtos/zephyr/pull/62395 Signed-off-by: Torsten Rasmussen --- CMakeLists.txt | 48 ++++++++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d4711f041dc..50bf2b73266 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -546,31 +546,9 @@ if(ZEPHYR_GIT_INDEX) set(git_dependency ${ZEPHYR_GIT_INDEX}) endif() -add_custom_command( - OUTPUT ${PROJECT_BINARY_DIR}/include/generated/version.h - COMMAND ${CMAKE_COMMAND} -DZEPHYR_BASE=${ZEPHYR_BASE} - -DOUT_FILE=${PROJECT_BINARY_DIR}/include/generated/version.h - -DVERSION_TYPE=KERNEL - -DVERSION_FILE=${ZEPHYR_BASE}/VERSION - -DKERNEL_VERSION_CUSTOMIZATION="${KERNEL_VERSION_CUSTOMIZATION}" - ${build_version_argument} - -P ${ZEPHYR_BASE}/cmake/gen_version_h.cmake - DEPENDS ${ZEPHYR_BASE}/VERSION ${git_dependency} -) 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 - -DAPP_VERSION_CUSTOMIZATION="${APP_VERSION_CUSTOMIZATION}" - ${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() @@ -626,6 +604,32 @@ endforeach() set(ZEPHYR_CURRENT_MODULE_DIR) set(ZEPHYR_CURRENT_CMAKE_DIR) +add_custom_command( + OUTPUT ${PROJECT_BINARY_DIR}/include/generated/version.h + COMMAND ${CMAKE_COMMAND} -DZEPHYR_BASE=${ZEPHYR_BASE} + -DOUT_FILE=${PROJECT_BINARY_DIR}/include/generated/version.h + -DVERSION_TYPE=KERNEL + -DVERSION_FILE=${ZEPHYR_BASE}/VERSION + -DKERNEL_VERSION_CUSTOMIZATION="${KERNEL_VERSION_CUSTOMIZATION}" + ${build_version_argument} + -P ${ZEPHYR_BASE}/cmake/gen_version_h.cmake + DEPENDS ${ZEPHYR_BASE}/VERSION ${git_dependency} +) + +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 + -DAPP_VERSION_CUSTOMIZATION="${APP_VERSION_CUSTOMIZATION}" + ${build_version_argument} + -P ${ZEPHYR_BASE}/cmake/gen_version_h.cmake + DEPENDS ${APPLICATION_SOURCE_DIR}/VERSION ${git_dependency} + ) +endif() + get_property(LIBC_LINK_LIBRARIES TARGET zephyr_interface PROPERTY LIBC_LINK_LIBRARIES) zephyr_link_libraries(${LIBC_LINK_LIBRARIES})