CMakePresets to west build arguments

Dear Nordic support team,

We are using the SDK v2.6.1 to build targets for nRF52840 chips, and are using multiple configurations defined in a CMakePreset.json file.

It works well with the nRF Connect extension for VS Code.

However for CI / CD needs, we don't want a GUI to build our targets from command line, and I cannot find a way to do so without copying the lines provided in the 'Output' of the nRF Connect extension, such as:

[10:35:49] west build --build-dir /home/aurelien/anderson/embedded_app/build_hw04 /home/aurelien/anderson/embedded_app --pristine --board hw04 --no-sysbuild -- -DNCS_TOOLCHAIN_VERSION=NONE -DBOARD_ROOT=/home/aurelien/anderson;/home/aurelien/anderson/embedded_app;/home/aurelien/anderson/paakeazy_projects/io_test;/home/aurelien/anderson/paakeazy_projects/audio_recording -DFOTA_UPDATE=TRUE -D_CMAKE_PRESET_NAME=build_hw04 -Db0_OVERLAY_CONFIG=/home/aurelien/ncs/v2.6.1/nrf/subsys/partition_manager/partition_manager_enabled.conf -Dmcuboot_OVERLAY_CONFIG=/home/aurelien/ncs/v2.6.1/nrf/subsys/bootloader/image/multi_image_mcuboot.conf;/home/aurelien/ncs/v2.6.1/nrf/subsys/bootloader/image/fw_info.conf;/home/aurelien/ncs/v2.6.1/nrf/subsys/bootloader/image/build_s1.conf;/home/aurelien/ncs/v2.6.1/nrf/subsys/partition_manager/ext_flash_mcuboot_secondary.conf;/home/aurelien/ncs/v2.6.1/nrf/subsys/partition_manager/partition_manager_enabled.conf;/home/aurelien/anderson/embedded_app/child_image/mcuboot.conf -Ds1_image_OVERLAY_CONFIG=/home/aurelien/ncs/v2.6.1/nrf/subsys/partition_manager/partition_manager_enabled.conf -Dmcuboot_CONFIG_BOOT_SIGNATURE_KEY_FILE="/home/aurelien/anderson/embedded_app/signature_keys/mcuboot-priv-rsa.pem" -DCACHED_CONF_FILE=/home/aurelien/anderson/embedded_app/prj.conf -DEXTRA_CONF_FILE=/home/aurelien/anderson/embedded_app/mcuboot_active.conf;/home/aurelien/anderson/embedded_app/overlay-secure-boot.conf

All the 'west build' parameters are already written in the .json file, it would ease the maintainability not to copy them and only rely on the .json file to perform pristine builds from command line.
How can I do that ? VSCode does it, so I'm guessing this is possible.
Thanks in advance,
BR
Aurélien
Parents
  • Hi Aurélien,

    You can build using a preset by adding the --preset flag to the build command:

    west build -d ${targetDir} -- --preset ${presetName}

    For example, if you have a build directory called build_dir and the following preset with the name my_preset:

    {
        "version": 2,
        "cmakeMinimumRequired": {
            "major": 3,
            "minor": 20
        },
        "configurePresets": [
            {
                "name": "my_preset",
                "displayName": "Build for nRF7002 DK nRF5340 application MCU",
                "generator": "Ninja",
                "binaryDir": "${sourceDir}/build_dir",
                "cacheVariables": {
                    "NCS_TOOLCHAIN_VERSION": "NONE",
                    "BOARD": "nrf7002dk_nrf5340_cpuapp",
                    "CACHED_CONF_FILE": "${sourceDir}/prj.conf"
                }
            }
        ]
    }

    Then you can use the following command to build on command line using the preset:

    west build -d build_dir -- --preset my_preset

    Make sure that the build directory in the preset (binaryDir) matches the build directory provided in the west build command.

    Best regards,
    Marte

  • Thank you for the reply, it seems very promising, but I need some additional help for this issue

    My arborescency looks like this:

    main_folder
        |_ project_1
            |_ CMakeLists.txt
            |_ CMakePresets.json
            |_ source files
        |_ project_2
            |_ CMakeLists.txt
            |_ CMakePresets.json
            |_ source files
        |_ boards / arm
            |_ hw01
                |_ board.cmake 
                |_ hw01_defconfig
                |_ hw01-pinctrl.dtsi
                |_ Kconfig.board
                |_ [...]
            |_ hw02
            |_ hw03
    
    

    In the VSCode config, the boards we defines can be found in the different projects thanks to the following parameter:

        "nrf-connect.boardRoots": [
            "${workspaceFolder}/boards",
            "${workspaceFolder}/project_1/boards",
            "${workspaceFolder}/project_2/boards",
        ],

    But when I go to main_project/project_1 and I enter the west command it cannot fine the defined boards : 


    CMake Error at /home/aurelien/ncs/v2.6.1/zephyr/cmake/modules/boards.cmake:167 (message):
      Invalid BOARD; see above.
    Call Stack (most recent call first):
      /home/aurelien/ncs/v2.6.1/zephyr/cmake/modules/zephyr_default.cmake:129 (include)
      /home/aurelien/ncs/v2.6.1/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:66 (include)
      /home/aurelien/ncs/v2.6.1/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:92 (include_boilerplate)
      CMakeLists.txt:18 (find_package)
    
    -- Configuring incomplete, errors occurred!
    FATAL ERROR: command exited with status 1: /snap/bin/cmake -DWEST_PYTHON=/home/aurelien/ncs/toolchains/2be090971e/usr/local/bin/python3.9 -B/home/aurelien/main_project/project_1/build_hw03 -GNinja --preset build_hw03 -S/home/aurelien/main_project/project_1

    How can I add the path to the boards directory in the shell environment so west is able to find it ? 

    Please note that the "board" is set in the CMakePresets, for instance : 

    {
                "name": "build_hw02",
                "displayName": "Build for hw02",
                "generator": "Ninja",
                "binaryDir": "${sourceDir}/build_hw02",
                "cacheVariables": {
                    "NCS_TOOLCHAIN_VERSION": "NONE",
                    "BOARD": "hw02",
                    "CONF_FILE": "${sourceDir}/prj.conf",
                    "_CMAKE_PRESET_NAME": "${presetName}"
                }
            },

    Many thanks for your precious support.

    Best regards
    Aurélien

Reply
  • Thank you for the reply, it seems very promising, but I need some additional help for this issue

    My arborescency looks like this:

    main_folder
        |_ project_1
            |_ CMakeLists.txt
            |_ CMakePresets.json
            |_ source files
        |_ project_2
            |_ CMakeLists.txt
            |_ CMakePresets.json
            |_ source files
        |_ boards / arm
            |_ hw01
                |_ board.cmake 
                |_ hw01_defconfig
                |_ hw01-pinctrl.dtsi
                |_ Kconfig.board
                |_ [...]
            |_ hw02
            |_ hw03
    
    

    In the VSCode config, the boards we defines can be found in the different projects thanks to the following parameter:

        "nrf-connect.boardRoots": [
            "${workspaceFolder}/boards",
            "${workspaceFolder}/project_1/boards",
            "${workspaceFolder}/project_2/boards",
        ],

    But when I go to main_project/project_1 and I enter the west command it cannot fine the defined boards : 


    CMake Error at /home/aurelien/ncs/v2.6.1/zephyr/cmake/modules/boards.cmake:167 (message):
      Invalid BOARD; see above.
    Call Stack (most recent call first):
      /home/aurelien/ncs/v2.6.1/zephyr/cmake/modules/zephyr_default.cmake:129 (include)
      /home/aurelien/ncs/v2.6.1/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:66 (include)
      /home/aurelien/ncs/v2.6.1/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:92 (include_boilerplate)
      CMakeLists.txt:18 (find_package)
    
    -- Configuring incomplete, errors occurred!
    FATAL ERROR: command exited with status 1: /snap/bin/cmake -DWEST_PYTHON=/home/aurelien/ncs/toolchains/2be090971e/usr/local/bin/python3.9 -B/home/aurelien/main_project/project_1/build_hw03 -GNinja --preset build_hw03 -S/home/aurelien/main_project/project_1

    How can I add the path to the boards directory in the shell environment so west is able to find it ? 

    Please note that the "board" is set in the CMakePresets, for instance : 

    {
                "name": "build_hw02",
                "displayName": "Build for hw02",
                "generator": "Ninja",
                "binaryDir": "${sourceDir}/build_hw02",
                "cacheVariables": {
                    "NCS_TOOLCHAIN_VERSION": "NONE",
                    "BOARD": "hw02",
                    "CONF_FILE": "${sourceDir}/prj.conf",
                    "_CMAKE_PRESET_NAME": "${presetName}"
                }
            },

    Many thanks for your precious support.

    Best regards
    Aurélien

Children
No Data
Related