Gyorgy Szing | 4909180 | 2020-11-24 00:33:09 +0100 | [diff] [blame] | 1 | #------------------------------------------------------------------------------- |
Imre Kis | 1c781ef | 2022-03-04 18:49:23 +0100 | [diff] [blame] | 2 | # Copyright (c) 2020-2022, Arm Limited and Contributors. All rights reserved. |
Gyorgy Szing | 4909180 | 2020-11-24 00:33:09 +0100 | [diff] [blame] | 3 | # |
| 4 | # SPDX-License-Identifier: BSD-3-Clause |
| 5 | # |
| 6 | #------------------------------------------------------------------------------- |
| 7 | |
| 8 | #[===[.rst: |
| 9 | Add build components to the current build. |
| 10 | ------------------------------------------ |
| 11 | |
| 12 | #]===] |
| 13 | |
| 14 | |
| 15 | #[===[.rst: |
| 16 | .. cmake:command:: add_components |
| 17 | |
| 18 | .. code:: cmake |
| 19 | |
| 20 | add_components(TARGET <target name> COMPONENTS <list of component directories>) |
| 21 | |
| 22 | INPUTS: |
| 23 | |
| 24 | ``BASE_DIR`` |
| 25 | If defined components are include relative to this directory. If nor paths must be |
| 26 | relative to CMAKE_SOURCE_DIR or be absolute. |
| 27 | |
| 28 | ``TARGET`` |
| 29 | The name of an already defined target to add components to. |
| 30 | |
| 31 | ``COMPONENTS`` |
| 32 | List of components relative to :cmake:variable:`CMAKE_SOURCE_DIR` |
| 33 | |
| 34 | #]===] |
| 35 | |
| 36 | function(add_components) |
| 37 | set(options ) |
| 38 | set(oneValueArgs TARGET BASE_DIR) |
| 39 | set(multiValueArgs COMPONENTS) |
| 40 | cmake_parse_arguments(MY_PARAMS "${options}" "${oneValueArgs}" |
| 41 | "${multiValueArgs}" ${ARGN} ) |
| 42 | |
| 43 | if(NOT DEFINED MY_PARAMS_TARGET) |
| 44 | message(FATAL_ERROR "add_component: mandatory parameter TARGET not defined!") |
| 45 | endif() |
| 46 | if(NOT DEFINED MY_PARAMS_COMPONENTS) |
| 47 | message(FATAL_ERROR "add_component: mandatory parameter COMPONENTS not defined!") |
| 48 | endif() |
| 49 | if(DEFINED MY_PARAMS_BASE_DIR AND NOT MY_PARAMS_BASE_DIR MATCHES ".*/$") |
| 50 | set(MY_PARAMS_BASE_DIR "${MY_PARAMS_BASE_DIR}/") |
| 51 | endif() |
| 52 | |
Imre Kis | 1c781ef | 2022-03-04 18:49:23 +0100 | [diff] [blame] | 53 | set(TGT ${MY_PARAMS_TARGET}) |
Gyorgy Szing | 4909180 | 2020-11-24 00:33:09 +0100 | [diff] [blame] | 54 | foreach(_comp IN ITEMS ${MY_PARAMS_COMPONENTS}) |
| 55 | set(_file ${MY_PARAMS_BASE_DIR}${_comp}/component.cmake) |
| 56 | include(${_file}) |
| 57 | set(CMAKE_CONFIGURE_DEPENDS ${_file}) |
| 58 | endforeach() |
Gyorgy Szing | 4909180 | 2020-11-24 00:33:09 +0100 | [diff] [blame] | 59 | endfunction() |