Is it possible to set MCUBOOT_IMAGE_VERSION from CMake?

Hi!

I am trying to streamline development a bit and want to set my image version based on the latest git tag and commits since then and I have a script that extracts that information and I print the correct message in CMakeLists.txt.

My issue is when I try to set the CONFIG_MCUBOOT_IMAGE_VERSION, it does not seem to be picked up and my version always ends as 0.0.0+0. Setting it from the command line does work. Relevant CMake lines follows:

set(CONF_FILE prj.conf thing.conf mcuboot.conf)

message("Building image version ${IMAGE_VERSION}")

set(CONFIG_MCUBOOT_IMAGE_VERSION \\"${IMAGE_VERSION}\\")
set(mcuboot_CONFIG_MCUBOOT_IMAGE_VERSION \\"${IMAGE_VERSION}\\")

Now I do all this before I call the find_package(Zephyr) and project commands and I manage to set other variables, like the signing key for MCUBoot.

I am using SDK version 1.9.1

Parents Reply Children
  • I believe that there were some CMake caching that made the option set properly. I have found a working solution using the following CMake snippet:

    if(NOT DEFINED IMAGE_VERSION)
        execute_process(COMMAND
            ${CMAKE_CURRENT_LIST_DIR}/scripts/git_get_semver.sh
            OUTPUT_VARIABLE IMAGE_VERSION
            OUTPUT_STRIP_TRAILING_WHITESPACE
        )
    endif()
    
    set(CONFIG_MCUBOOT_IMAGE_VERSION \"${IMAGE_VERSION}\")
    

    Which sets the version correctly and is over-writable on the command line using `-DIMAGE_VERION=x.y.z`

Related