MergedLoadStoreMotion.cpp: Fix msc17 build. Member initializer is unavailable.
[oota-llvm.git] / cmake / modules / LLVM-Config.cmake
1 function(get_system_libs return_var)
2   message(AUTHOR_WARNING "get_system_libs no longer needed")
3   set(${return_var} "" PARENT_SCOPE)
4 endfunction()
5
6
7 function(link_system_libs target)
8   message(AUTHOR_WARNING "link_system_libs no longer needed")
9 endfunction()
10
11
12 function(is_llvm_target_library library return_var)
13   # Sets variable `return_var' to ON if `library' corresponds to a
14   # LLVM supported target. To OFF if it doesn't.
15   set(${return_var} OFF PARENT_SCOPE)
16   string(TOUPPER "${library}" capitalized_lib)
17   string(TOUPPER "${LLVM_ALL_TARGETS}" targets)
18   foreach(t ${targets})
19     if( capitalized_lib STREQUAL t OR
20         capitalized_lib STREQUAL "LLVM${t}" OR
21         capitalized_lib STREQUAL "LLVM${t}CODEGEN" OR
22         capitalized_lib STREQUAL "LLVM${t}ASMPARSER" OR
23         capitalized_lib STREQUAL "LLVM${t}ASMPRINTER" OR
24         capitalized_lib STREQUAL "LLVM${t}DISASSEMBLER" OR
25         capitalized_lib STREQUAL "LLVM${t}INFO" )
26       set(${return_var} ON PARENT_SCOPE)
27       break()
28     endif()
29   endforeach()
30 endfunction(is_llvm_target_library)
31
32
33 macro(llvm_config executable)
34   explicit_llvm_config(${executable} ${ARGN})
35 endmacro(llvm_config)
36
37
38 function(explicit_llvm_config executable)
39   set( link_components ${ARGN} )
40
41   llvm_map_components_to_libnames(LIBRARIES ${link_components})
42   get_target_property(t ${executable} TYPE)
43   if("${t}" STREQUAL "STATIC_LIBRARY")
44     target_link_libraries(${executable} ${cmake_2_8_12_INTERFACE} ${LIBRARIES})
45   elseif("${t}" STREQUAL "SHARED_LIBRARY" OR "${t}" STREQUAL "MODULE_LIBRARY")
46     target_link_libraries(${executable} ${cmake_2_8_12_PRIVATE} ${LIBRARIES})
47   else()
48     # Use plain form for legacy user.
49     target_link_libraries(${executable} ${LIBRARIES})
50   endif()
51 endfunction(explicit_llvm_config)
52
53
54 # This is a variant intended for the final user:
55 function(llvm_map_components_to_libraries OUT_VAR)
56   explicit_map_components_to_libraries(result ${ARGN})
57   set( ${OUT_VAR} ${result} ${sys_result} PARENT_SCOPE )
58 endfunction(llvm_map_components_to_libraries)
59
60 # Map LINK_COMPONENTS to actual libnames.
61 function(llvm_map_components_to_libnames out_libs)
62   set( link_components ${ARGN} )
63   if(NOT LLVM_AVAILABLE_LIBS)
64     # Inside LLVM itself available libs are in a global property.
65     get_property(LLVM_AVAILABLE_LIBS GLOBAL PROPERTY LLVM_LIBS)
66   endif()
67   string(TOUPPER "${LLVM_AVAILABLE_LIBS}" capitalized_libs)
68
69   # Expand some keywords:
70   list(FIND LLVM_TARGETS_TO_BUILD "${LLVM_NATIVE_ARCH}" have_native_backend)
71   list(FIND link_components "engine" engine_required)
72   if( NOT engine_required EQUAL -1 )
73     list(FIND LLVM_TARGETS_WITH_JIT "${LLVM_NATIVE_ARCH}" have_jit)
74     if( NOT have_native_backend EQUAL -1 AND NOT have_jit EQUAL -1 )
75       list(APPEND link_components "jit")
76       list(APPEND link_components "native")
77     else()
78       list(APPEND link_components "interpreter")
79     endif()
80   endif()
81   list(FIND link_components "native" native_required)
82   if( NOT native_required EQUAL -1 )
83     if( NOT have_native_backend EQUAL -1 )
84       list(APPEND link_components ${LLVM_NATIVE_ARCH})
85     endif()
86   endif()
87
88   # Translate symbolic component names to real libraries:
89   foreach(c ${link_components})
90     # add codegen, asmprinter, asmparser, disassembler
91     list(FIND LLVM_TARGETS_TO_BUILD ${c} idx)
92     if( NOT idx LESS 0 )
93       if( TARGET LLVM${c}CodeGen )
94         list(APPEND expanded_components "LLVM${c}CodeGen")
95       else()
96         if( TARGET LLVM${c} )
97           list(APPEND expanded_components "LLVM${c}")
98         else()
99           message(FATAL_ERROR "Target ${c} is not in the set of libraries.")
100         endif()
101       endif()
102       if( TARGET LLVM${c}AsmPrinter )
103         list(APPEND expanded_components "LLVM${c}AsmPrinter")
104       endif()
105       if( TARGET LLVM${c}AsmParser )
106         list(APPEND expanded_components "LLVM${c}AsmParser")
107       endif()
108       if( TARGET LLVM${c}Desc )
109         list(APPEND expanded_components "LLVM${c}Desc")
110       endif()
111       if( TARGET LLVM${c}Info )
112         list(APPEND expanded_components "LLVM${c}Info")
113       endif()
114       if( TARGET LLVM${c}Disassembler )
115         list(APPEND expanded_components "LLVM${c}Disassembler")
116       endif()
117     elseif( c STREQUAL "native" )
118       # already processed
119     elseif( c STREQUAL "nativecodegen" )
120       list(APPEND expanded_components "LLVM${LLVM_NATIVE_ARCH}CodeGen")
121       if( TARGET LLVM${LLVM_NATIVE_ARCH}Desc )
122         list(APPEND expanded_components "LLVM${LLVM_NATIVE_ARCH}Desc")
123       endif()
124       if( TARGET LLVM${LLVM_NATIVE_ARCH}Info )
125         list(APPEND expanded_components "LLVM${LLVM_NATIVE_ARCH}Info")
126       endif()
127     elseif( c STREQUAL "backend" )
128       # same case as in `native'.
129     elseif( c STREQUAL "engine" )
130       # already processed
131     elseif( c STREQUAL "all" )
132       list(APPEND expanded_components ${LLVM_AVAILABLE_LIBS})
133     else( NOT idx LESS 0 )
134       # Canonize the component name:
135       string(TOUPPER "${c}" capitalized)
136       list(FIND capitalized_libs LLVM${capitalized} lib_idx)
137       if( lib_idx LESS 0 )
138         # The component is unknown. Maybe is an omitted target?
139         is_llvm_target_library(${c} iltl_result)
140         if( NOT iltl_result )
141           message(FATAL_ERROR "Library `${c}' not found in list of llvm libraries.")
142         endif()
143       else( lib_idx LESS 0 )
144         list(GET LLVM_AVAILABLE_LIBS ${lib_idx} canonical_lib)
145         list(APPEND expanded_components ${canonical_lib})
146       endif( lib_idx LESS 0 )
147     endif( NOT idx LESS 0 )
148   endforeach(c)
149
150   set(${out_libs} ${expanded_components} PARENT_SCOPE)
151 endfunction()
152
153 # Expand dependencies while topologically sorting the list of libraries:
154 function(llvm_expand_dependencies out_libs)
155   set(expanded_components ${ARGN})
156   list(LENGTH expanded_components lst_size)
157   set(cursor 0)
158   set(processed)
159   while( cursor LESS lst_size )
160     list(GET expanded_components ${cursor} lib)
161     get_property(lib_deps GLOBAL PROPERTY LLVMBUILD_LIB_DEPS_${lib})
162     list(APPEND expanded_components ${lib_deps})
163     # Remove duplicates at the front:
164     list(REVERSE expanded_components)
165     list(REMOVE_DUPLICATES expanded_components)
166     list(REVERSE expanded_components)
167     list(APPEND processed ${lib})
168     # Find the maximum index that doesn't have to be re-processed:
169     while(NOT "${expanded_components}" MATCHES "^${processed}.*" )
170       list(REMOVE_AT processed -1)
171     endwhile()
172     list(LENGTH processed cursor)
173     list(LENGTH expanded_components lst_size)
174   endwhile( cursor LESS lst_size )
175   set(${out_libs} ${expanded_components} PARENT_SCOPE)
176 endfunction()
177
178 function(explicit_map_components_to_libraries out_libs)
179   llvm_map_components_to_libnames(link_libs ${ARGN})
180   llvm_expand_dependencies(expanded_components ${link_libs})
181   # Return just the libraries included in this build:
182   set(result)
183   foreach(c ${expanded_components})
184     if( TARGET ${c} )
185       set(result ${result} ${c})
186     endif()
187   endforeach(c)
188   set(${out_libs} ${result} PARENT_SCOPE)
189 endfunction(explicit_map_components_to_libraries)