Debian Codegraph @

cmake/tribits/core/utils/TribitsGatherBuildTargets.cmake

raw
1 # @HEADER
2 # *****************************************************************************
3 # TriBITS: Tribal Build, Integrate, and Test System
4 #
5 # Copyright 2013-2016 NTESS and the TriBITS contributors.
6 # SPDX-License-Identifier: BSD-3-Clause
7 # *****************************************************************************
8 # @HEADER
9
10
11 # Function to get a list all of buildsystem targets of the type matching the
12 # given list starting in a subdir and in below subdirs.
13 #
14 # Usage::
15 #
16 # tribits_get_all_build_targets_including_in_subdirs(
17 # <subdir> <targetTypesList> <targetsListVarOut> )
18 #
19 # On output the variable ``<targetsListVarOut>`` will contain a list of all of
20 # the build targets match match the targets types listed in
21 # ``<targetTypesList>`` which is a quoted list of the form
22 # ``"<targettype0>;<targettype2>;..."``. For example, to get all of the
23 # real library and executable targets, run::
24 #
25 # tribits_get_all_build_targets_including_in_subdirs(
26 # <subdir>
27 # "STATIC_LIBRARY;SHARED_LIBRARY;EXECUTABLE"
28 # <targetsListVarOut> )
29 #
30 function(tribits_get_all_build_targets_including_in_subdirs srcdir targetTypesList
31 targetsListVarOut
32 )
33
34 set(targetsList "")
35
36 # Recurse into subdirectories.
37 get_property(dirs DIRECTORY "${srcdir}" PROPERTY SUBDIRECTORIES)
38 foreach(d IN LISTS dirs)
39 tribits_get_all_build_targets_including_in_subdirs(${d} "${targetTypesList}"
40 targetsSubdirList)
41 list(APPEND targetsList ${targetsSubdirList})
42 endforeach()
43
44 # Get the targets from this directory.
45 get_property(allTargetsThisDir DIRECTORY "${srcdir}" PROPERTY BUILDSYSTEM_TARGETS)
46 tribits_filter_only_build_targets(allTargetsThisDir "${targetTypesList}"
47 buildTargetsThisDir)
48 list(APPEND targetsList ${buildTargetsThisDir})
49
50 # Return
51 set(${targetsListVarOut} ${targetsList} PARENT_SCOPE)
52
53 endfunction()
54
55
56 function(tribits_filter_only_build_targets targetListInVar targetTypesList
57 targetListOutVar
58 )
59
60 set(targetListOut "")
61
62 foreach (target IN LISTS ${targetListInVar})
63 get_property(targetType TARGET ${target} PROPERTY TYPE)
64 foreach (desiredTargetType IN ITEMS ${targetTypesList})
65 if (desiredTargetType STREQUAL targetType)
66 list(APPEND targetListOut ${target})
67 break()
68 endif()
69 endforeach()
70 endforeach()
71
72 set(${targetListOutVar} ${targetListOut} PARENT_SCOPE)
73
74 endfunction()