Skip to content

Commit 8f54acd

Browse files
greg-ferrlubos
authored andcommitted
doc: config_and_build: regroup and rework pages
Moved sections about CMake and Kconfig from modifying.rst to separate pages and removed modifying.rst. Split Building and programming into two separate sections. Grouped guides for configuring under Configuring and building the app. NCSDK-22324 and NCSDK-21617. Signed-off-by: Grzegorz Ferenc <[email protected]>
1 parent 527d8ef commit 8f54acd

File tree

38 files changed

+626
-433
lines changed

38 files changed

+626
-433
lines changed

applications/asset_tracker_v2/doc/asset_tracker_v2_description.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ Building and running
167167
********************
168168

169169
This application can be found under :file:`applications/asset_tracker_v2` in the |NCS| folder structure.
170-
See :ref:`programming` for information about how to build and program the application.
170+
See :ref:`building` for information about how to build the application and :ref:`programming` for information about how to program it.
171171

172172
Testing
173173
=======

applications/nrf5340_audio/broadcast_sink/README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ Configuration
6363

6464
See :ref:`nrf53_audio_app_configuration` and :ref:`nrf53_audio_app_fota` for configuration options common to all nRF5340 Audio applications.
6565

66-
For information about how to configure applications in the |NCS|, see :ref:`modifying`.
66+
For information about how to configure applications in the |NCS|, see :ref:`configure_application`.
6767

6868
.. _nrf53_audio_broadcast_sink_app_building:
6969

applications/nrf5340_audio/broadcast_source/README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ Configuration
5151

5252
See :ref:`nrf53_audio_app_configuration` and :ref:`nrf53_audio_app_fota` for configuration options common to all nRF5340 Audio applications.
5353

54-
For information about how to configure applications in the |NCS|, see :ref:`modifying`.
54+
For information about how to configure applications in the |NCS|, see :ref:`configure_application`.
5555

5656
.. _nrf53_audio_broadcast_source_app_building:
5757

applications/nrf5340_audio/unicast_client/README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ Configuration
5858

5959
See :ref:`nrf53_audio_app_configuration` and :ref:`nrf53_audio_app_fota` for configuration options common to all nRF5340 Audio applications.
6060

61-
For information about how to configure applications in the |NCS|, see :ref:`modifying`.
61+
For information about how to configure applications in the |NCS|, see :ref:`configure_application`.
6262

6363
.. _nrf53_audio_unicast_client_app_building:
6464

applications/nrf5340_audio/unicast_server/README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ Configuration
6363

6464
See :ref:`nrf53_audio_app_configuration` and :ref:`nrf53_audio_app_fota` for configuration options common to all nRF5340 Audio applications.
6565

66-
For information about how to configure applications in the |NCS|, see :ref:`modifying`.
66+
For information about how to configure applications in the |NCS|, see :ref:`configure_application`.
6767

6868
.. _nrf53_audio_unicast_server_app_building:
6969

doc/_utils/redirects.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
("app_boards", "config_and_build/board_support"),
2222
("app_dev/board_support/index", "config_and_build/board_support"),
2323
("config_and_build/board_support", "config_and_build/board_support/index"),
24+
("config_and_build/output_build_files", "config_and_build/configuring_app/output_build_files"),
2425
("config_and_build/pin_control", "config_and_build/configure_app/hardware/pin_control"),
2526
("config_and_build/use_gpio_pin_directly", "config_and_build/configure_app/hardware/use_gpio_pin_directly"),
2627
("ug_bootloader", "config_and_build/bootloaders_and_dfu/bootloader"),
@@ -98,6 +99,7 @@
9899
("installation/installing", "installation/install_ncs"),
99100
("gs_modifying", "config_and_build/modifying"),
100101
("getting_started/modifying", "config_and_build/modifying"),
102+
("config_and_build/modifying", "config_and_build/configuring_app/index"),
101103
("gs_programming", "config_and_build/programming"),
102104
("getting_started/programming", "config_and_build/programming"),
103105
("gs_recommended_versions", "installation/recommended_versions"),

doc/nrf/config_and_build.rst

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,27 @@
44
Configuration and building
55
##########################
66

7-
The |NCS| build and configuration system is based on the one from :ref:`Zephyr project <zephyr:getting_started>`, with some additions.
7+
After you have :ref:`created an application <create_application>`, you need to configure and build it in order to be able to run it.
88

9-
The figure below visualizes the tools and configuration methods in the |NCS|.
9+
The |NCS| configuration and build system is based on the one from :ref:`Zephyr <zephyr:getting_started>`, with some additions.
10+
11+
The following figure lists the main tools and configuration methods in the |NCS|.
1012
All of them have a role in the creation of an application, from configuring the libraries or applications to building them.
1113

1214
.. figure:: images/ncs-toolchain.svg
1315
:alt: nRF Connect SDK tools and configuration
1416

1517
|NCS| tools and configuration methods
1618

17-
* CMake generates build files based on the provided :file:`CMakeLists.txt` files, which use information from Kconfig and devicetree.
18-
See the `CMake documentation`_.
19-
* :ref:`Devicetree <zephyr:dt-guide>` describes the hardware.
20-
* :ref:`zephyr:kconfig` generates definitions that configure the software.
21-
* Ninja (comparable to Make) uses the build files to build the program, see the `Ninja documentation`_.
22-
* The compiler (for example, `GCC compiler`_) creates the executables.
19+
* Devicetree describes the hardware.
20+
* Kconfig generates definitions that configure the software.
21+
* Partition Manager describes the memory layout.
22+
* CMake generates build files based on the provided :file:`CMakeLists.txt` files, which use information from devicetree files, Kconfig, and Partition Manager.
23+
* Ninja (comparable to Make) uses the build files to build the program.
24+
* The compiler (for example, GCC) creates the executables.
25+
26+
For a more detailed overview, see :ref:`app_build_system`.
2327

24-
Read the guides in this section to learn how to use these tools and configuration methods in areas valid for :ref:`all supported boards <app_boards>`.
2528
Depending on the board you are working with, check also its :ref:`hardware guide <device_guides>`, as some nRF Series families have specific exceptions and rules to be applied on top of the general configuration procedures.
2629

2730
Make sure to consider :ref:`app_bootloaders` and :ref:`app_dfu` already at this stage of the application development.
@@ -32,10 +35,8 @@ Make sure to consider :ref:`app_bootloaders` and :ref:`app_dfu` already at this
3235

3336
config_and_build/config_and_build_system
3437
config_and_build/board_support/index
35-
config_and_build/configuring_app/hardware/index
38+
config_and_build/configuring_app/index
3639
config_and_build/programming
37-
config_and_build/output_build_files
38-
config_and_build/modifying
3940
config_and_build/multi_image
4041
config_and_build/bootloaders/index
4142
config_and_build/dfu/index

doc/nrf/config_and_build/config_and_build_system.rst

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ The build and configuration system in Zephyr and the |NCS| uses the following bu
3838
- :file:`Kconfig`, :file:`prj.conf`, :file:`.config`
3939
- Software configuration system also used in the Linux kernel.
4040
- `Kconfig GUI <Configuring with nRF Kconfig_>`_, :ref:`menuconfig and guiconfig <zephyr:menuconfig>`
41-
- Kconfig GUI is part of the |nRFVSC|.
41+
- | Kconfig GUI is part of the |nRFVSC|.
42+
| The :ref:`Kconfig Reference <configuration_options>` provides the documentation for each configuration option.
4243
* - :ref:`partition_manager`
4344
- :file:`pm.yml`, :file:`pm_static.yml`
4445
- Memory layout configuration system.
@@ -49,11 +50,16 @@ Each of these systems comes with a specialized syntax and purpose.
4950
See the following sections for more information.
5051
To read more about Zephyr's configuration system and its role in the application development, see :ref:`zephyr:build_overview` and :ref:`zephyr:application` in the Zephyr documentation.
5152

52-
When you :ref:`create_application`, the configuration files for each of these systems are created in the :ref:`application directory <create_application_structure>`: :file:`CMakeLists.txt` for CMake, :file:`app.overlay` for Devicetree, :file:`prj.conf` for Kconfig, and :file:`partitions.yml` for Partition Manager (if enabled).
53-
You can then edit them according to your needs (see :ref:`modifying`).
53+
When you :ref:`create_application`, the configuration files for each of these systems are created in the :ref:`application directory <create_application_structure>`: :file:`CMakeLists.txt` for CMake, :file:`app.overlay` for devicetree, :file:`prj.conf` for Kconfig, and :file:`partitions.yml` for Partition Manager (if enabled).
54+
You can then edit them according to your needs (see :ref:`building`).
5455

5556
When you start building, a CMake build is executed in two stages: configuration phase and building phase.
5657

58+
.. figure:: ../images/ncs-toolchain.svg
59+
:alt: nRF Connect SDK tools and configuration
60+
61+
|NCS| tools and configuration methods
62+
5763
.. _configuration_system_overview_config:
5864

5965
Configuration phase
@@ -114,6 +120,7 @@ The :file:`.config` file in the :file:`<build_dir>/zephyr/` directory describes
114120
Some subsystems can use their own configuration files.
115121

116122
For more information, see :ref:`configure_application` and Zephyr's :ref:`zephyr:application-kconfig`.
123+
The :ref:`Kconfig Reference <configuration_options>` provides the documentation for each configuration option in the |NCS|.
117124

118125
Memory layout configuration
119126
---------------------------
@@ -149,8 +156,9 @@ Building phase
149156
==============
150157

151158
During this phase, the final build scripts are executed.
152-
The build phase begins when the user invokes ``make`` or ``ninja``.
153-
You can customize this stage by :ref:`cmake_options`.
159+
The build phase begins when the user invokes ``make`` or `ninja <Ninja documentation_>`_.
160+
The compiler (for example, `GCC compiler`_) then creates object files used to create the final executables.
161+
You can customize this stage by :ref:`cmake_options` and using :ref:`compiler_settings`.
154162

155163
The result of this process is a complete application in a format suitable for flashing on the desired target board.
156164
See :ref:`output build files <app_build_output_files>` for details.
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
.. _building_advanced:
2+
3+
Advanced building procedures
4+
############################
5+
6+
.. contents::
7+
:local:
8+
:depth: 2
9+
10+
You can customize the basic :ref:`building <building>` procedures in a variety of ways, depending on the configuration of your project.
11+
12+
.. _compiler_settings:
13+
14+
Advanced compiler settings
15+
**************************
16+
17+
The application has full control over the build process.
18+
19+
Using Zephyr's configuration options is the standard way of controlling how the system is built.
20+
These options can be found under Zephyr's menuconfig **Build and Link Features** > **Compiler Options**.
21+
For example, to turn off optimizations, select :kconfig:option:`CONFIG_NO_OPTIMIZATIONS`.
22+
23+
Compiler options not controlled by the Zephyr build system can be controlled through the :kconfig:option:`CONFIG_COMPILER_OPT` Kconfig option.
24+
25+
.. _gs_modifying_build_types:
26+
.. _modifying_build_types:
27+
28+
Configuring build types
29+
***********************
30+
31+
When the ``CONF_FILE`` variable contains a single file and this file name follows the naming pattern :file:`prj_<buildtype>.conf`, then the build type will be inferred to be *<buildtype>*.
32+
The build type cannot be set explicitly.
33+
The *<buildtype>* can be any string, but it is common to use ``release`` and ``debug``.
34+
35+
For information about how to set variables, see :ref:`zephyr:important-build-vars` in the Zephyr documentation.
36+
37+
The following software components can be made dependent on the build type:
38+
39+
* The Partition Manager's :ref:`static configuration <ug_pm_static>`.
40+
When the build type has been inferred, the file :file:`pm_static_<buildtype>.yml` will have precedence over :file:`pm_static.yml`.
41+
* The :ref:`child image Kconfig configuration <ug_multi_image_permanent_changes>`.
42+
Certain child image configuration files located in the :file:`child_image/` directory can be defined per build type.
43+
44+
The devicetree configuration is not affected by the build type.
45+
46+
.. note::
47+
For an example of an application that uses build types, see the :ref:`nrf_desktop` application (:ref:`nrf_desktop_requirements_build_types`) or the :ref:`nrf_machine_learning_app` application (:ref:`nrf_machine_learning_app_requirements_build_types`).
48+
49+
.. tabs::
50+
51+
.. group-tab:: nRF Connect for VS Code
52+
53+
To select the build type in the |nRFVSC|:
54+
55+
1. When `building an application <How to build an application_>`_ as described in the |nRFVSC| documentation, follow the steps for setting up the build configuration.
56+
#. In the **Add Build Configuration** screen, select the desired :file:`.conf` file from the :guilabel:`Configuration` drop-down menu.
57+
#. Fill in other configuration options, if applicable, and click :guilabel:`Build Configuration`.
58+
59+
.. group-tab:: Command line
60+
61+
To select the build type when building the application from command line, specify the build type by adding the following parameter to the ``west build`` command:
62+
63+
.. parsed-literal::
64+
:class: highlight
65+
66+
-- -DCONF_FILE=prj_\ *selected_build_type*\.conf
67+
68+
For example, you can replace the *selected_build_type* variable to build the ``release`` firmware for ``nrf52840dk_nrf52840`` by running the following command in the project directory:
69+
70+
.. parsed-literal::
71+
:class: highlight
72+
73+
west build -b nrf52840dk_nrf52840 -d build_nrf52840dk_nrf52840 -- -DCONF_FILE=prj_release.conf
74+
75+
The ``build_nrf52840dk_nrf52840`` parameter specifies the output directory for the build files.
76+
77+
If the selected board does not support the selected build type, the build is interrupted.
78+
For example, for the :ref:`nrf_machine_learning_app` application, if the ``nus`` build type is not supported by the selected board, the following notification appears:
79+
80+
.. code-block:: console
81+
82+
Configuration file for build type ``nus`` is missing.
83+
84+
Optional build parameters
85+
*************************
86+
87+
Here are some of the possible options you can use:
88+
89+
* Some applications contain configuration overlay files that enable specific features.
90+
These can be added to the ``west build`` command as follows:
91+
92+
.. parsed-literal::
93+
:class: highlight
94+
95+
west build -b *build_target* -- -DOVERLAY_CONFIG="overlay-feature1.conf;overlay-feature2.conf"
96+
97+
See :ref:`configuration_permanent_change` and Zephyr's :ref:`zephyr:west-building-cmake-args` for more information.
98+
* You can include the *directory_name* parameter to build from a directory other than the current directory.
99+
* You can use the *build_target@board_revision* parameter to get extra devicetree overlays with new features available for a board version.
100+
The *board_revision* is printed on the label of your DK, just below the PCA number.
101+
For example, if you run the west build command with an additional parameter ``@1.0.0`` for nRF9160 build target, it adds the external flash on the nRF9160 DK that was available since :ref:`board version v0.14.0 <nrf9160_board_revisions>`.
102+
* You can :ref:`start menuconfig with the west command <configuration_temporary_change>` to configure your application.
103+
* You can :ref:`reuse an existing build directory <zephyr:west-building-pristine>` for building another application for another board or build target by passing ``-p=auto`` to ``west build``.
104+
105+
For more information on other optional build parameters, run the ``west build -h`` help text command.
106+
107+
.. |output_files_note| replace:: For more information about files generated as output of the build process, see :ref:`app_build_output_files`.
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
.. _configuring_cmake:
2+
3+
Adding files and configuring CMake
4+
##################################
5+
6+
.. contents::
7+
:local:
8+
:depth: 2
9+
10+
As described in more detail in :ref:`app_build_system`, the Zephyr and |NCS| build systems are based on `CMake <CMake documentation_>`_.
11+
For this reason, every application in Zephyr and the |NCS| must have a :file:`CMakeLists.txt` file.
12+
This file is the entry point of the build system as it specifies the application source files for the compiler to include in the :ref:`configuration phase <app_build_system>`.
13+
14+
Maintaining CMakeLists.txt
15+
**************************
16+
17+
The recommended method to maintain and update the :file:`CMakeLists.txt` file is to use the |nRFVSC|.
18+
The extension provides support for the `source control with west`_ and `CMake build system`_, including `build configuration management <How to work with build configurations_>`_ and `source and config files overview <Details View_>`_.
19+
20+
.. _modifying_files_compiler:
21+
22+
Adding source files to CMakeLists.txt
23+
*************************************
24+
25+
You can add source files to the ``app`` CMake target with the :c:func:`target_sources` function provided by CMake.
26+
27+
Pay attention to the following configuration options:
28+
29+
* If your application is complex, you can split it into subdirectories.
30+
These subdirectories can provide their own :file:`CMakeLists.txt` files.
31+
(The main :file:`CMakeLists.txt` file needs to include those.)
32+
* The build system searches for header files in include directories.
33+
Add additional include directories for your application with the :c:func:`target_include_directories` function provided by CMake.
34+
For example, if you want to include an :file:`inc` directory, the code would look like the following:
35+
36+
.. code-block:: c
37+
38+
target_include_directories(app PRIVATE inc)
39+
40+
See :ref:`zephyr:zephyr-app-cmakelists` in the Zephyr documentation for more information about how to edit :file:`CMakeLists.txt`.
41+
42+
.. note::
43+
You can also read the `CMake Tutorial`_ in the CMake documentation for a better understanding of how :file:`CMakeLists.txt` are used in a CMake project.
44+
This tutorial however differs from Zephyr and |NCS| project configurations, so use it only as reference.
45+
46+
.. _cmake_options:
47+
48+
Providing CMake options
49+
***********************
50+
51+
You can provide additional options for building your application to the CMake process, which can be useful, for example, to switch between different build scenarios.
52+
These options are specified when CMake is run, thus not during the actual build, but when configuring the build.
53+
54+
For information about what variables can be set and how to add these variables in your project, see :ref:`zephyr:important-build-vars` in the Zephyr documentation.
55+
56+
.. tabs::
57+
58+
.. group-tab:: nRF Connect for VS Code
59+
60+
If you work with the |nRFVSC|, you can specify project-specific CMake options when you add the :term:`build configuration` for a new |NCS| project.
61+
See `How to build an application`_ in the |nRFVSC| documentation.
62+
63+
.. group-tab:: Command line
64+
65+
If you work on the command line, pass the additional options to the ``west build`` command when :ref:`building`.
66+
The options must be added after a ``--`` at the end of the command.
67+
See :ref:`zephyr:west-building-cmake-args` for more information.

doc/nrf/config_and_build/configuring_app/hardware/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Follow the steps in `How to create devicetree files`_ and use one of the followi
1111
* `Devicetree language support`_
1212

1313
The following guides provide information about configuring specific aspects of hardware support related to devicetree.
14-
Read them together with Zephyr's :ref:`zephyr:hardware_support` and :ref:`zephyr:dt-guide` guides.
14+
Read them together with Zephyr's :ref:`zephyr:hardware_support` and :ref:`zephyr:dt-guide` guides, and the official `Devicetree Specification`_.
1515

1616
.. toctree::
1717
:maxdepth: 1

0 commit comments

Comments
 (0)