llvm.org GIT mirror llvm / 405386b
[CMake] Fix `is_llvm_target_library` and support out-of-order components Summary: This patch is required by D28855, and enables us to rely on CMake's ability to handle out of order target dependencies. Reviewers: mgorny, chapuni, bryant Subscribers: llvm-commits, jgosnell Differential Revision: https://reviews.llvm.org/D28869 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@294514 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Bieneman 3 years ago
2 changed file(s) with 79 addition(s) and 11 deletion(s). Raw diff Collapse all Expand all
77 message(AUTHOR_WARNING "link_system_libs no longer needed")
88 endfunction()
99
10
10 # is_llvm_target_library(
11 # library
12 # Name of the LLVM library to check
13 # return_var
14 # Output variable name
15 # ALL_TARGETS;INCLUDED_TARGETS;OMITTED_TARGETS
16 # ALL_TARGETS - default looks at the full list of known targets
17 # INCLUDED_TARGETS - looks only at targets being configured
18 # OMITTED_TARGETS - looks only at targets that are not being configured
19 # )
1120 function(is_llvm_target_library library return_var)
21 cmake_parse_arguments(ARG "ALL_TARGETS;INCLUDED_TARGETS;OMITTED_TARGETS" "" "" ${ARGN})
1222 # Sets variable `return_var' to ON if `library' corresponds to a
1323 # LLVM supported target. To OFF if it doesn't.
1424 set(${return_var} OFF PARENT_SCOPE)
1525 string(TOUPPER "${library}" capitalized_lib)
16 string(TOUPPER "${LLVM_ALL_TARGETS}" targets)
26 if(ARG_INCLUDED_TARGETS)
27 string(TOUPPER "${LLVM_TARGETS_TO_BUILD}" targets)
28 elseif(ARG_OMITTED_TARGETS)
29 set(omitted_targets ${LLVM_ALL_TARGETS})
30 list(REMOVE_ITEM omitted_targets ${LLVM_TARGETS_TO_BUILD})
31 string(TOUPPER "${omitted_targets}" targets)
32 else()
33 string(TOUPPER "${LLVM_ALL_TARGETS}" targets)
34 endif()
1735 foreach(t ${targets})
1836 if( capitalized_lib STREQUAL t OR
19 capitalized_lib STREQUAL "LLVM${t}" OR
20 capitalized_lib STREQUAL "LLVM${t}CODEGEN" OR
21 capitalized_lib STREQUAL "LLVM${t}ASMPARSER" OR
22 capitalized_lib STREQUAL "LLVM${t}ASMPRINTER" OR
23 capitalized_lib STREQUAL "LLVM${t}DISASSEMBLER" OR
24 capitalized_lib STREQUAL "LLVM${t}INFO" )
37 capitalized_lib STREQUAL "${t}" OR
38 capitalized_lib STREQUAL "${t}DESC" OR
39 capitalized_lib STREQUAL "${t}CODEGEN" OR
40 capitalized_lib STREQUAL "${t}ASMPARSER" OR
41 capitalized_lib STREQUAL "${t}ASMPRINTER" OR
42 capitalized_lib STREQUAL "${t}DISASSEMBLER" OR
43 capitalized_lib STREQUAL "${t}INFO" OR
44 capitalized_lib STREQUAL "${t}UTILS" )
2545 set(${return_var} ON PARENT_SCOPE)
2646 break()
2747 endif()
2848 endforeach()
2949 endfunction(is_llvm_target_library)
3050
51 function(is_llvm_target_specifier library return_var)
52 is_llvm_target_library(${library} ${return_var} ${ARGN})
53 string(TOUPPER "${library}" capitalized_lib)
54 if(NOT ${return_var})
55 if( capitalized_lib STREQUAL "ALLTARGETSASMPARSERS" OR
56 capitalized_lib STREQUAL "ALLTARGETSDESCS" OR
57 capitalized_lib STREQUAL "ALLTARGETSDISASSEMBLERS" OR
58 capitalized_lib STREQUAL "ALLTARGETSINFOS" OR
59 capitalized_lib STREQUAL "NATIVE" OR
60 capitalized_lib STREQUAL "NATIVECODEGEN" )
61 set(${return_var} ON PARENT_SCOPE)
62 endif()
63 endif()
64 endfunction()
3165
3266 macro(llvm_config executable)
3367 cmake_parse_arguments(ARG "USE_SHARED" "" "" ${ARGN})
91125 get_property(LLVM_AVAILABLE_LIBS GLOBAL PROPERTY LLVM_LIBS)
92126 endif()
93127 string(TOUPPER "${LLVM_AVAILABLE_LIBS}" capitalized_libs)
128
129 get_property(LLVM_TARGETS_CONFIGURED GLOBAL PROPERTY LLVM_TARGETS_CONFIGURED)
130
131 # Generally in our build system we avoid order-dependence. Unfortunately since
132 # not all targets create the same set of libraries we actually need to ensure
133 # that all build targets associated with a target are added before we can
134 # process target dependencies.
135 if(NOT LLVM_TARGETS_CONFIGURED)
136 foreach(c ${link_components})
137 is_llvm_target_specifier(${c} iltl_result ALL_TARGETS)
138 if(iltl_result)
139 message(FATAL_ERROR "Specified target library before target registration is complete.")
140 endif()
141 endforeach()
142 endif()
94143
95144 # Expand some keywords:
96145 list(FIND LLVM_TARGETS_TO_BUILD "${LLVM_NATIVE_ARCH}" have_native_backend)
140189 if( TARGET LLVM${c}Disassembler )
141190 list(APPEND expanded_components "LLVM${c}Disassembler")
142191 endif()
192 if( TARGET LLVM${c}Info )
193 list(APPEND expanded_components "LLVM${c}Info")
194 endif()
195 if( TARGET LLVM${c}Utils )
196 list(APPEND expanded_components "LLVM${c}Utils")
197 endif()
143198 elseif( c STREQUAL "native" )
144199 # already processed
145200 elseif( c STREQUAL "nativecodegen" )
197252 list(FIND capitalized_libs LLVM${capitalized} lib_idx)
198253 if( lib_idx LESS 0 )
199254 # The component is unknown. Maybe is an omitted target?
200 is_llvm_target_library(${c} iltl_result)
201 if( NOT iltl_result )
202 message(FATAL_ERROR "Library `${c}' not found in list of llvm libraries.")
255 is_llvm_target_library(${c} iltl_result OMITTED_TARGETS)
256 if(iltl_result)
257 # A missing library to a directly referenced omitted target would be bad.
258 message(FATAL_ERROR "Library '${c}' is a direct reference to a target library for an omitted target.")
259 else()
260 # If it is not an omitted target we should assume it is a component
261 # that hasn't yet been processed by CMake. Missing components will
262 # cause errors later in the configuration, so we can safely assume
263 # that this is valid here.
264 list(APPEND expanded_components LLVM${c})
203265 endif()
204266 else( lib_idx LESS 0 )
205267 list(GET LLVM_AVAILABLE_LIBS ${lib_idx} canonical_lib)
1616 message(STATUS "Targeting ${t}")
1717 add_subdirectory(${t})
1818 endforeach()
19
20 # Currently we do not allow libraries from lib to reference targets directly.
21 # This property is used to enforce that convention. It is important because the
22 # logic in llvm_map_components_to_libnames is order dependent on the target
23 # libraries being created.
24 set_property(GLOBAL PROPERTY LLVM_TARGETS_CONFIGURED On)