blob: b48f1bf0e93fb1ede1e0524ee0526fabefda284f [file] [log] [blame]
Gyorgy Szing49091802020-11-24 00:33:09 +01001#-------------------------------------------------------------------------------
Imre Kis1c781ef2022-03-04 18:49:23 +01002# Copyright (c) 2020-2022, Arm Limited and Contributors. All rights reserved.
Gyorgy Szing49091802020-11-24 00:33:09 +01003#
4# SPDX-License-Identifier: BSD-3-Clause
5#
6#-------------------------------------------------------------------------------
7
8#[===[.rst:
9Add 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
36function(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 Kis1c781ef2022-03-04 18:49:23 +010053 set(TGT ${MY_PARAMS_TARGET})
Gyorgy Szing49091802020-11-24 00:33:09 +010054 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 Szing49091802020-11-24 00:33:09 +010059endfunction()