How to add custom_target on NCS2.8.0

I work on NCS 2.8.0

I add follow to CMakeLists.txt

add_custom_target(
    my_release_file
    echo AAAA BBBB CCCC
    DEPENDS all
)
when run "west build -b nrf54l15dk/nrf54l15/cpuapp -t my_release_file"
error occured.
Itry it on NCS 2.6.0, it's success.
How to add custom_target on NCS2.8.0?
  • I think the cmake has changed in 2.8.0, try not use Depends all and instead of echo use command to start with something like below

    add_custom_target(
        my_release_file ALL
        COMMAND echo "AAAA BBBB CCCC"
        COMMENT "Generating custom release file"
        DEPENDS zephyr_elf # Replace with an actual target if necessary
    )
    

  • I try it. (Add to the end of CMakeLists.txt. replace zephyr_elf to exist file)

    And run "west build -b nrf54l15dk/nrf54l15/cpuapp -t my_release_file"

    result is
    -- west build: running target my_release_file
    ninja: error: unknown target 'my_release_file'

    What am I doing wrong?

  • I have put the suggestion in ncs\v2.6.1\zephyr\samples\basic\blinky\CMakeLists.txt

    And running the command west gives proper execution like below

    E:\ncs\v2.6.1\zephyr\samples\basic\blinky> west build -t my_release_file -b nrf52840dk_nrf52840
    -- west build: generating a build system
    Loading Zephyr default modules (Zephyr base (cached)).
    -- Application: E:/ncs/v2.6.1/zephyr/samples/basic/blinky
    -- CMake version: 3.21.0
    -- Using NCS Toolchain 2.6.20240304.889616714482 for building. (C:/ncs/toolchains/cf2149caf2/cmake)
    -- Cache files will be written to: E:/ncs/v2.6.1/zephyr/.cache
    -- Zephyr version: 3.5.99 (E:/ncs/v2.6.1/zephyr)
    -- Found west (found suitable version "1.2.0", minimum required is "0.14.0")
    -- Board: nrf52840dk_nrf52840
    -- Found host-tools: zephyr 0.16.5 (C:/ncs/toolchains/cf2149caf2/opt/zephyr-sdk)
    -- Found toolchain: zephyr 0.16.5 (C:/ncs/toolchains/cf2149caf2/opt/zephyr-sdk)
    -- Found Dtc: C:/ncs/toolchains/cf2149caf2/opt/bin/dtc.exe (found suitable version "1.4.7", minimum required is "1.4.6") 
    -- Found BOARD.dts: E:/ncs/v2.6.1/zephyr/boards/arm/nrf52840dk_nrf52840/nrf52840dk_nrf52840.dts
    -- Generated zephyr.dts: E:/ncs/v2.6.1/zephyr/samples/basic/blinky/build/zephyr/zephyr.dts
    -- Generated devicetree_generated.h: E:/ncs/v2.6.1/zephyr/samples/basic/blinky/build/zephyr/include/generated/devicetree_generated.h
    -- Including generated dts.cmake file: E:/ncs/v2.6.1/zephyr/samples/basic/blinky/build/zephyr/dts.cmake
    Parsing E:/ncs/v2.6.1/zephyr/Kconfig
    PS E:\ncs\v2.6.1\zephyr\samples\basic\blinky> west build -t my_release_file -b nrf52840dk_nrf52840
    PS E:\ncs\v2.6.1\zephyr\samples\basic\blinky> west build -t my_release_file -b nrf52840dk_nrf52840
    -- west build: generating a build system
    Loading Zephyr default modules (Zephyr base).
    -- Application: E:/ncs/v2.6.1/zephyr/samples/basic/blinky
    -- CMake version: 3.21.0
    -- Using NCS Toolchain 2.6.20240304.889616714482 for building. (C:/ncs/toolchains/cf2149caf2/cmake)
    -- Found Python3: C:/ncs/toolchains/cf2149caf2/opt/bin/python.exe (found suitable version "3.9.13", minimum required is "3.8") found components: Interpreter 
    -- Cache files will be written to: E:/ncs/v2.6.1/zephyr/.cache
    -- Zephyr version: 3.5.99 (E:/ncs/v2.6.1/zephyr)
    -- Found west (found suitable version "1.2.0", minimum required is "0.14.0")
    -- Board: nrf52840dk_nrf52840
    -- Found host-tools: zephyr 0.16.5 (C:/ncs/toolchains/cf2149caf2/opt/zephyr-sdk)
    -- Found toolchain: zephyr 0.16.5 (C:/ncs/toolchains/cf2149caf2/opt/zephyr-sdk)
    -- Found Dtc: C:/ncs/toolchains/cf2149caf2/opt/bin/dtc.exe (found suitable version "1.4.7", minimum required is "1.4.6") 
    -- Found BOARD.dts: E:/ncs/v2.6.1/zephyr/boards/arm/nrf52840dk_nrf52840/nrf52840dk_nrf52840.dts
    -- Generated zephyr.dts: E:/ncs/v2.6.1/zephyr/samples/basic/blinky/build/zephyr/zephyr.dts
    -- Generated devicetree_generated.h: E:/ncs/v2.6.1/zephyr/samples/basic/blinky/build/zephyr/include/generated/devicetree_generated.h
    -- Including generated dts.cmake file: E:/ncs/v2.6.1/zephyr/samples/basic/blinky/build/zephyr/dts.cmake
    Parsing E:/ncs/v2.6.1/zephyr/Kconfig
    Loaded configuration 'E:/ncs/v2.6.1/zephyr/boards/arm/nrf52840dk_nrf52840/nrf52840dk_nrf52840_defconfig'     
    Merged configuration 'E:/ncs/v2.6.1/zephyr/samples/basic/blinky/prj.conf'
    Configuration saved to 'E:/ncs/v2.6.1/zephyr/samples/basic/blinky/build/zephyr/.config'
    Kconfig header saved to 'E:/ncs/v2.6.1/zephyr/samples/basic/blinky/build/zephyr/include/generated/autoconf.h'
    -- Found GnuLd: c:/ncs/toolchains/cf2149caf2/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd.exe (found version "2.38") 
    -- The C compiler identification is GNU 12.2.0
    -- The CXX compiler identification is GNU 12.2.0
    -- The ASM compiler identification is GNU
    -- Found assembler: C:/ncs/toolchains/cf2149caf2/opt/zephyr-sdk/arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc.exe
    -- Configuring done
    -- Generating done
    -- Build files have been written to: E:/ncs/v2.6.1/zephyr/samples/basic/blinky/build
    ←[92m-- west build: running target my_release_file
    [1/1] Generating custom release file
    AAAA BBBB CCCC
    PS E:\ncs\v2.6.1\zephyr\samples\basic\blinky>


    See in the end you have your custom comment out

    [1/1] Generating custom release file
    AAAA BBBB CCCC

    Not sure how you are running your west, Did you have all the environment variables set correctly in your command line terminal? How are you doing that? 

  • I tested it for NCSv2.6.0 since you were using that

Related