Back to home page

EIC code displayed by LXR

 
 

    


Warning, /acts/cmake/ActsComponentsHelpers.cmake is written in an unsupported language. File is not indexed.

0001 # Provide helper functions to simplify the handling of (optional) components
0002 #
0003 # Components must always be placed in a separate directory which can than
0004 # be added using either of the two provided functions
0005 #
0006 #     add_component(<SUBDIR> <NAME>)
0007 #     add_component_if(<SUBDIR> <NAME> ...) # for optional components
0008 #
0009 # Both functions are wrappers around `add_subdirectory` that also register a
0010 # component under the given name. All additional arguments to the second
0011 # function are treated as a boolean expression that determines whether the
0012 # subdirectory should be added and the component registered. The list of
0013 # components is stored in the global `_components` variable, and all components,
0014 # including the ones that are not built, in `_known_components`. If components
0015 # are added from a subdirectory, these variables must be propagated to the
0016 # global scope using the following helper macro:
0017 #
0018 #     propagate_components_to_parent()
0019 #
0020 # For cases, where a subdirectory needs to be optionally included but does not
0021 # need to be registered as a component, the following helper function can be
0022 # used
0023 #
0024 #     add_subdirectory_if(<SUBDIR> ...)
0025 #
0026 # where all additional arguments are again treated as a boolean expression that
0027 # determines whether the subdirectory should be added.
0028 #
0029 # The external packages a component needs when it is used from an installation
0030 # are declared from within the component directory with
0031 #
0032 #     add_component_dependencies(<NAME> <PACKAGE>...)
0033 #
0034 # and are found again at the version used for the build.
0035 
0036 set(_components)
0037 set(_known_components)
0038 
0039 # add an optional directory and register its name as a component
0040 function(add_component_if path name)
0041     file(
0042         RELATIVE_PATH
0043         _rel
0044         ${PROJECT_SOURCE_DIR}
0045         "${CMAKE_CURRENT_SOURCE_DIR}/${path}"
0046     )
0047     list(APPEND _known_components "${name}")
0048     set(_known_components "${_known_components}" PARENT_SCOPE)
0049     if(${ARGN})
0050         list(APPEND _components "${name}")
0051         # propagate variable outside function scope
0052         set(_components "${_components}" PARENT_SCOPE)
0053         message(STATUS "Enable component '${name}' in '${_rel}'")
0054         add_subdirectory(${path})
0055     else()
0056         message(STATUS "Ignore component '${name}' in '${_rel}'")
0057     endif()
0058 endfunction()
0059 
0060 # add a directory and register its name as a component
0061 macro(add_component path name)
0062     add_component_if(${path} ${name} TRUE)
0063 endmacro()
0064 
0065 # record the external packages a component needs, to be written to its
0066 # dependency file together with the versions found at build time
0067 function(add_component_dependencies name)
0068     set_property(
0069         GLOBAL
0070         APPEND
0071         PROPERTY ACTS_COMPONENT_DEPENDENCIES_${name} ${ARGN}
0072     )
0073 endfunction()
0074 
0075 # propagate the list of components to the parent scope
0076 macro(propagate_components_to_parent)
0077     set(_components "${_components}" PARENT_SCOPE)
0078     set(_known_components "${_known_components}" PARENT_SCOPE)
0079 endmacro()
0080 
0081 # add an optional subdirectory that is **not** registered as a component
0082 function(add_subdirectory_if path)
0083     file(
0084         RELATIVE_PATH
0085         _rel
0086         ${PROJECT_SOURCE_DIR}
0087         "${CMAKE_CURRENT_SOURCE_DIR}/${path}"
0088     )
0089     if(${ARGN})
0090         message(STATUS "Enable subdirectory '${_rel}'")
0091         add_subdirectory(${path})
0092     else()
0093         message(STATUS "Ignore subdirectory '${_rel}'")
0094     endif()
0095 endfunction()