Setting Extra CMake Arguments only applies to initial build

When I apply an Extra CMake build argument when creating a build configuration, it only takes effect on the first build, but none after that.

For example, I have added this code to my CMakeLists.txt file:

# Set JLINK_FLASH_BUILD to TRUE in order to build an image that will boot
# from the initial flash (this will automatically confirm the applications in
# the merged.hex file)
#
# When building images for DFU updates, this should be set to FALSE
set(JLINK_FLASH_BUILD FALSE CACHE INTERNAL "Automatically confirm application for initial flash images")
if(JLINK_FLASH_BUILD)
  list(APPEND IMGTOOL_ARGS "--confirm")
endif(JLINK_FLASH_BUILD)

If I define JLINK_FLASH_BUILD in the Extra CMake Arguments part of the "Create Build Configuration", I can see that the image is built with the --confirm flag as expected. However, in an MCUboot based image with two partitions, the secondary image is NOT confirmed. The build log shows that the --confirm option is not set for the secondary image.

In addition, if I run a build from the command line, the same issue shows up. The secondary image is NOT confirmed, when it is expected to be so.

The overall issue is that in VS code, if I re-run a build where I expect the primary boot image to be confirmed with the --confirm flag, even the primary image is not confirmed.

This is easily reproduced by simply adding the above code to your CMakeLists.txt file, creating a build configuration and adding the extra CMake argument of "-DJLINK_FLASH_BUI
LD=TRUE". The initial image generated will be confirmed and boot properly. Subsequent builds of the same configuration will not be bootable.

This is using NCS v2.5.1.

Related