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

Reply
  • 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

Children
No Data
Related