|
|
@@ -64,7 +64,7 @@ Using CMake Directly
|
|
|
|
|
|
:ref:`idf.py` is a wrapper around CMake_ for convenience. However, you can also invoke CMake directly if you prefer.
|
|
|
|
|
|
-.. code-block:: bash
|
|
|
+.. highlight:: bash
|
|
|
|
|
|
When ``idf.py`` does something, it prints each command that it runs for easy reference. For example, the ``idf.py build`` command is the same as running these commands in a bash shell (or similar commands for Windows Command Prompt)::
|
|
|
|
|
|
@@ -147,7 +147,7 @@ To manage the Python version more generally via the command line, check out the
|
|
|
Example Project
|
|
|
===============
|
|
|
|
|
|
-.. code-block:: none
|
|
|
+.. highlight:: none
|
|
|
|
|
|
An example project directory tree might look like this::
|
|
|
|
|
|
@@ -198,7 +198,7 @@ Each project has a single top-level ``CMakeLists.txt`` file that contains build
|
|
|
Minimal Example CMakeLists
|
|
|
--------------------------
|
|
|
|
|
|
-.. code-block:: cmake
|
|
|
+.. highlight:: cmake
|
|
|
|
|
|
Minimal project::
|
|
|
|
|
|
@@ -256,7 +256,7 @@ Overriding Default Build Specifications
|
|
|
|
|
|
The build sets some global build specifications (compile flags, definitions, etc.) that gets used in compiling all sources from all components.
|
|
|
|
|
|
-.. code-block:: cmake
|
|
|
+.. highlight:: cmake
|
|
|
|
|
|
For example, one of the default build specifications set is the compile option ``-Wextra``. Suppose a user wants to use override this with ``-Wno-extra``,
|
|
|
it should be done after ``project()``::
|
|
|
@@ -306,7 +306,7 @@ When ESP-IDF is collecting all the components to compile, it will do this in the
|
|
|
Minimal Component CMakeLists
|
|
|
----------------------------
|
|
|
|
|
|
-.. code-block:: cmake
|
|
|
+.. highlight:: cmake
|
|
|
|
|
|
The minimal component ``CMakeLists.txt`` file simply registers the component to the build system using ``idf_component_register``::
|
|
|
|
|
|
@@ -373,7 +373,7 @@ Other build properties are listed :ref:`here <cmake-build-properties>`.
|
|
|
Controlling Component Compilation
|
|
|
---------------------------------
|
|
|
|
|
|
-.. code-block:: cmake
|
|
|
+.. highlight:: cmake
|
|
|
|
|
|
To pass compiler options when compiling source files belonging to a particular component, use the `target_compile_options`_ function::
|
|
|
|
|
|
@@ -475,7 +475,7 @@ Imagine there is a ``car`` component, which uses the ``engine`` component, which
|
|
|
Car Component
|
|
|
^^^^^^^^^^^^^
|
|
|
|
|
|
-.. code-block:: c
|
|
|
+.. highlight:: c
|
|
|
|
|
|
The ``car.h`` header file is the public interface for the ``car`` component. This header includes ``engine.h`` directly because it uses some declarations from this header::
|
|
|
|
|
|
@@ -507,7 +507,7 @@ This means the ``car/CMakeLists.txt`` file needs to declare that ``car`` require
|
|
|
Engine Component
|
|
|
^^^^^^^^^^^^^^^^
|
|
|
|
|
|
-.. code-block:: c
|
|
|
+.. highlight:: c
|
|
|
|
|
|
The ``engine`` component also has a public header file ``include/engine.h``, but this header is simpler::
|
|
|
|
|
|
@@ -664,7 +664,7 @@ The order of components in the ``BUILD_COMPONENTS`` variable determines other or
|
|
|
Adding Link-Time Dependencies
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
|
-.. code-block:: cmake
|
|
|
+.. highlight:: cmake
|
|
|
|
|
|
The ESP-IDF CMake helper function ``idf_component_add_link_dependency`` adds a link-only dependency between one component and another. In almost all cases, it is better to use the ``PRIV_REQUIRES`` feature in ``idf_component_register`` to create a dependency. However, in some cases, it's necessary to add the link-time dependency of another component to this component, i.e., the reverse order to ``PRIV_REQUIRES`` (for example: :doc:`/api-reference/peripherals/spi_flash/spi_flash_override_driver`).
|
|
|
|
|
|
@@ -816,7 +816,7 @@ Adding Conditional Configuration
|
|
|
|
|
|
The configuration system can be used to conditionally compile some files depending on the options selected in the project configuration.
|
|
|
|
|
|
-.. code-block:: none
|
|
|
+.. highlight:: none
|
|
|
|
|
|
``Kconfig``::
|
|
|
|
|
|
@@ -859,7 +859,7 @@ This can also be used to select or stub out an implementation, as such:
|
|
|
help
|
|
|
Select this to output temperature plots
|
|
|
|
|
|
-.. code-block:: cmake
|
|
|
+.. highlight:: cmake
|
|
|
|
|
|
``CMakeLists.txt``::
|
|
|
|
|
|
@@ -932,7 +932,7 @@ Or if the file is a string, you can use the variable ``EMBED_TXTFILES``. This wi
|
|
|
idf_component_register(...
|
|
|
EMBED_TXTFILES server_root_cert.pem)
|
|
|
|
|
|
-.. code-block:: c
|
|
|
+.. highlight:: c
|
|
|
|
|
|
The file's contents will be added to the .rodata section in flash, and are available via symbol names as follows::
|
|
|
|
|
|
@@ -941,7 +941,7 @@ The file's contents will be added to the .rodata section in flash, and are avail
|
|
|
|
|
|
The names are generated from the full name of the file, as given in ``EMBED_FILES``. Characters /, ., etc. are replaced with underscores. The _binary prefix in the symbol name is added by objcopy and is the same for both text and binary files.
|
|
|
|
|
|
-.. code-block:: cmake
|
|
|
+.. highlight:: cmake
|
|
|
|
|
|
To embed a file into a project, rather than a component, you can call the function ``target_add_binary_data`` like this::
|
|
|
|
|
|
@@ -951,7 +951,7 @@ Place this line after the ``project()`` line in your project CMakeLists.txt file
|
|
|
|
|
|
For an example of using this technique, see the "main" component of the file_serving example :example_file:`protocols/http_server/file_serving/main/CMakeLists.txt` - two files are loaded at build time and linked into the firmware.
|
|
|
|
|
|
-.. code-block:: cmake
|
|
|
+.. highlight:: cmake
|
|
|
|
|
|
It is also possible to embed a generated file::
|
|
|
|
|
|
@@ -980,7 +980,7 @@ ESP-IDF has a feature called linker script generation that enables components to
|
|
|
Fully Overriding the Component Build Process
|
|
|
--------------------------------------------
|
|
|
|
|
|
-.. code-block:: cmake
|
|
|
+.. highlight:: cmake
|
|
|
|
|
|
Obviously, there are cases where all these recipes are insufficient for a certain component, for example when the component is basically a wrapper around another third-party component not originally intended to be compiled under this build system. In that case, it's possible to forego the ESP-IDF build system entirely by using a CMake feature called ExternalProject_. Example component CMakeLists::
|
|
|
|
|
|
@@ -1077,7 +1077,7 @@ After running a project build, the build directory contains binary output files
|
|
|
- ``flash_app_args`` contains arguments to flash only the app.
|
|
|
- ``flash_bootloader_args`` contains arguments to flash only the bootloader.
|
|
|
|
|
|
-.. code-block:: bash
|
|
|
+.. highlight:: bash
|
|
|
|
|
|
You can pass any of these flasher argument files to ``esptool.py`` as follows::
|
|
|
|
|
|
@@ -1105,7 +1105,7 @@ The ESP-IDF build system "wraps" CMake with the concept of "components", and hel
|
|
|
|
|
|
However, underneath the concept of "components" is a full CMake build system. It is also possible to make a component which is pure CMake.
|
|
|
|
|
|
-.. code-block:: cmake
|
|
|
+.. highlight:: cmake
|
|
|
|
|
|
Here is an example minimal "pure CMake" component CMakeLists file for a component named ``json``::
|
|
|
|
|
|
@@ -1125,7 +1125,7 @@ Using Third-Party CMake Projects with Components
|
|
|
|
|
|
CMake is used for a lot of open-source C and C++ projects — code that users can tap into for their applications. One of the benefits of having a CMake build system is the ability to import these third-party projects, sometimes even without modification! This allows for users to be able to get functionality that may not yet be provided by a component, or use another library for the same functionality.
|
|
|
|
|
|
-.. code-block:: cmake
|
|
|
+.. highlight:: cmake
|
|
|
|
|
|
Importing a library might look like this for a hypothetical library ``foo`` to be used in the ``main`` component::
|
|
|
|
|
|
@@ -1167,7 +1167,7 @@ For example, in the ``foo/CMakeLists.txt`` file::
|
|
|
Using Prebuilt Libraries with Components
|
|
|
========================================
|
|
|
|
|
|
-.. code-block:: cmake
|
|
|
+.. highlight:: cmake
|
|
|
|
|
|
Another possibility is that you have a prebuilt static library (``.a`` file), built by some other build process.
|
|
|
|
|
|
@@ -1430,7 +1430,7 @@ These are properties that describe a component. Values of component properties c
|
|
|
File Globbing & Incremental Builds
|
|
|
==================================
|
|
|
|
|
|
-.. code-block:: cmake
|
|
|
+.. highlight:: cmake
|
|
|
|
|
|
The preferred way to include source files in an ESP-IDF component is to list them manually via SRCS argument to ``idf_component_register``::
|
|
|
|