Warning, /algorithms/cmake/algorithmsComponentsHelpers.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. If
0014 # components are added from a subdirectory, this variable must be propagated to
0015 # the global scope using the following helper macro:
0016 #
0017 # propagate_components_to_parent()
0018 #
0019 # For cases, where a subdirectory needs to be optionally included but does not
0020 # need to be registered as a component, the following helper function can be
0021 # used
0022 #
0023 # add_subdirectory_if(<SUBDIR> ...)
0024 #
0025 # where all additional arguments are again treated as a boolean expression that
0026 # determines whether the subdirectory should be added.
0027
0028 set(_components)
0029
0030 # add an optional directory and register its name as a component
0031 function(add_component_if path name)
0032 file(RELATIVE_PATH _rel ${PROJECT_SOURCE_DIR} "${CMAKE_CURRENT_SOURCE_DIR}/${path}")
0033 if(${ARGN})
0034 list(APPEND _components "${name}")
0035 # propagate variable outside function scope
0036 set(_components "${_components}" PARENT_SCOPE)
0037 message(STATUS "Enable component '${name}' in '${_rel}'")
0038 add_subdirectory(${path})
0039 else()
0040 message(STATUS "Ignore component '${name}' in '${_rel}'")
0041 endif()
0042 endfunction()
0043
0044 # add a directory and register its name as a component
0045 macro(add_component path name)
0046 add_component_if(${path} ${name} TRUE)
0047 endmacro()