(cmake-macro-reference-label)= # CMake Macros (cmake-macro-spl-add-component)= ## spl_add_component Add a component to a variant. ```cmake spl_add_component( []) ``` This macro is intended to be used in the variant's parts.cmake file to add a component to the variant. The arguments are: `` : The relative path from project root to the component's directory. `` *(optional)* : The name of the target executable that this component should be linked to. If not specified, the component will be linked to the default target defined by `LINK_TARGET_NAME`. This parameter enables multi-binary support, allowing different components to be linked to different executable targets. Examples: Adding a component to the variant in its parts.cmake: ```cmake spl_add_component(src/led_driver) ``` This example adds a component located in the "src/led_driver" directory to the variant using the default target. Adding a component to a specific target executable: ```cmake spl_add_component(src/led_driver app1) ``` This example adds a component to be linked specifically to the `app1` executable target. The component name will be prefixed with the target name to ensure uniqueness (e.g., `app1_src_led_driver`). ## spl_add_named_component Add a named component to a variant. ```cmake spl_add_named_component( []) ``` This macro is intended to be used in the variant's parts.cmake file to add a named component to the variant. The arguments are: `` : The name of a CMake variable that contains the path (either absolute or relative from project root) to the component's directory. The variable name becomes the name of the component in the build system. `` *(optional)* : The name of the target executable that this component should be linked to. If not specified, the component will be linked to the default target defined by `LINK_TARGET_NAME`. This parameter enables multi-binary support, allowing different components to be linked to different executable targets. Examples: Adding a named component to the variant in its parts.cmake: ```cmake set(LED_DRIVER_COMPONENT src/led_driver) spl_add_named_component(LED_DRIVER_COMPONENT) ``` This example adds a named component to the variant using the variable `LED_DRIVER_COMPONENT` that contains the path to the component's directory. ```cmake set(LED_DRIVER_COMPONENT ${CMAKE_CURRENT_SOURCE_DIR}/some_package/src/led_driver) spl_add_named_component(LED_DRIVER_COMPONENT) ``` This example adds a named component to the variant using the variable `LED_DRIVER_COMPONENT` that contains the absolute path to the component's directory. Adding a named component to a specific target executable: ```cmake set(LED_DRIVER_COMPONENT src/led_driver) spl_add_named_component(LED_DRIVER_COMPONENT app2) ``` This example adds a named component to be linked specifically to the `app2` executable target. The component name will be prefixed with the target name to ensure uniqueness (e.g., `app2_LED_DRIVER_COMPONENT`). ## spl_add_include Add an include directory to the project's list of include directories. ```cmake spl_add_include() ``` This macro is intended to be used in the variant's parts.cmake file to add an include directory to the build's list of include directories, making header files in this directory accessible to the compiler. The arguments are: `` : The relative path to the include directory you want to add to the build's list of include directories. Example: Adding an include directory to the project: ```cmake spl_add_include(include/my_library) ``` This example adds the "include/my_library" directory to the project's list of include directories, making header files within this directory accessible to the project's source code. (spl_add_source)= ## spl_add_source Add a source file of a component to the list of sources to be compiled. ```cmake spl_add_source( [COMPILE_OPTIONS "