Debian Codegraph @

mesonbuild/dependencies/data/CMakeListsLLVM.txt

raw
1 # fail noisily if attempt to use this file without setting:
2 # cmake_minimum_required(VERSION ${CMAKE_VERSION})
3 # project(... LANGUAGES ...)
4
5 cmake_policy(SET CMP0000 NEW)
6
7 set(PACKAGE_FOUND FALSE)
8
9 list(REMOVE_DUPLICATES LLVM_MESON_VERSIONS)
10
11 while(TRUE)
12 #Activate CMake version selection
13 foreach(i IN LISTS LLVM_MESON_VERSIONS)
14 find_package(LLVM ${i}
15 CONFIG
16 NAMES ${LLVM_MESON_PACKAGE_NAMES}
17 QUIET)
18 if(LLVM_FOUND)
19 break()
20 endif()
21 endforeach()
22
23 # ARCHS has to be set via the CMD interface
24 if(LLVM_FOUND OR "${ARCHS}" STREQUAL "")
25 break()
26 endif()
27
28 list(GET ARCHS 0 CMAKE_LIBRARY_ARCHITECTURE)
29 list(REMOVE_AT ARCHS 0)
30 endwhile()
31
32 function(meson_llvm_cmake_dynamic_available mod out)
33 # Check if we can only compare LLVM_DYLIB_COMPONENTS, because
34 # we do not need complex component translation logic, if all
35 # is covered by one variable
36 if(mod IN_LIST LLVM_DYLIB_COMPONENTS)
37 set(${out} TRUE PARENT_SCOPE)
38 return()
39 elseif((NOT (mod IN_LIST LLVM_DYLIB_COMPONENTS))
40 AND (NOT("${LLVM_DYLIB_COMPONENTS}" STREQUAL "all")))
41 set(${out} FALSE PARENT_SCOPE)
42 return()
43 endif()
44
45 # Complex heuristic to filter all pseudo-components and skip invalid names
46 # LLVM_DYLIB_COMPONENTS will be 'all', because in other case we returned
47 # in previous check. 'all' is also handled there.
48 set(llvm_pseudo_components "native" "backend" "engine" "all-targets")
49 is_llvm_target_specifier(${mod} mod_spec INCLUDED_TARGETS)
50 string(TOUPPER "${LLVM_AVAILABLE_LIBS}" capitalized_libs)
51 string(TOUPPER "${LLVM_TARGETS_TO_BUILD}" capitalized_tgts)
52 if(mod_spec)
53 set(${out} TRUE PARENT_SCOPE)
54 elseif(mod IN_LIST capitalized_tgts)
55 set(${out} TRUE PARENT_SCOPE)
56 elseif(mod IN_LIST llvm_pseudo_components)
57 set(${out} TRUE PARENT_SCOPE)
58 elseif(LLVM${mod} IN_LIST capitalized_libs)
59 set(${out} TRUE PARENT_SCOPE)
60 else()
61 set(${out} FALSE PARENT_SCOPE)
62 endif()
63 endfunction()
64
65 function(is_static target ret)
66 if(TARGET ${target})
67 get_target_property(target_type ${target} TYPE)
68 if(target_type STREQUAL "STATIC_LIBRARY")
69 set(${ret} TRUE PARENT_SCOPE)
70 return()
71 endif()
72 endif()
73 set(${ret} FALSE PARENT_SCOPE)
74 endfunction()
75
76 # Concatenate LLVM_MESON_REQUIRED_MODULES and LLVM_MESON_OPTIONAL_MODULES
77 set(LLVM_MESON_MODULES ${LLVM_MESON_REQUIRED_MODULES} ${LLVM_MESON_OPTIONAL_MODULES})
78
79
80 # Check if LLVM exists in dynamic world
81 # Initialization before modules checking
82 if(LLVM_FOUND)
83 if(LLVM_MESON_DYLIB AND TARGET LLVM)
84 set(PACKAGE_FOUND TRUE)
85 elseif(NOT LLVM_MESON_DYLIB)
86 # Use LLVMSupport to check if static targets exist
87 set(static_tg FALSE)
88 is_static(LLVMCore static_tg)
89 if(static_tg)
90 set(PACKAGE_FOUND TRUE)
91 endif(static_tg)
92 endif()
93 endif()
94
95 if(PACKAGE_FOUND)
96 foreach(mod IN LISTS LLVM_MESON_MODULES)
97 # Reset variables
98 set(out_mods)
99 set(real_mods)
100
101 # Generate a lower and upper case version
102 string(TOLOWER "${mod}" mod_L)
103 string(TOUPPER "${mod}" mod_U)
104
105 # Special case - "all-targets" pseudo target
106 # Just append all targets, if pseudo-target exists
107 if("${mod}" STREQUAL "all-targets")
108 set(mod_L ${LLVM_TARGETS_TO_BUILD})
109 string(TOUPPER "${LLVM_TARGETS_TO_BUILD}" mod_U)
110 endif()
111
112 # Check if required module is linked is inside libLLVM.so.
113 # If not, skip this module
114 if(LLVM_MESON_DYLIB
115 AND DEFINED LLVM_DYLIB_COMPONENTS)
116 meson_llvm_cmake_dynamic_available(${mod} MOD_F)
117 meson_llvm_cmake_dynamic_available(${mod_L} MOD_L_F)
118 meson_llvm_cmake_dynamic_available(${mod_U} MOD_U_F)
119 if(MOD_F OR MOD_L_F OR MOD_U_F)
120 set(MESON_LLVM_TARGETS_${mod} LLVM)
121 endif()
122 elseif(LLVM_MESON_DYLIB AND (mod IN_LIST LLVM_MESON_REQUIRED_MODULES))
123 # Dynamic was requested, but no required variables set, we cannot continue
124 set(PACKAGE_FOUND FALSE)
125 break()
126 elseif(LLVM_MESON_DYLIB)
127 # Dynamic was requested, and we request optional modules only. Continue
128 continue()
129 else()
130 # CMake only do this for static components, and we
131 # replicate its behaviour
132 # Get the mapped components
133 llvm_map_components_to_libnames(out_mods ${mod} ${mod_L} ${mod_U})
134 list(SORT out_mods)
135 list(REMOVE_DUPLICATES out_mods)
136
137 # Make sure that the modules exist
138 foreach(i IN LISTS out_mods)
139 set(static_tg FALSE)
140 is_static(${i} static_tg)
141 if(static_tg)
142 list(APPEND real_mods ${i})
143 endif()
144 endforeach()
145
146 # Set the output variables
147 set(MESON_LLVM_TARGETS_${mod} ${real_mods})
148 foreach(i IN LISTS real_mods)
149 set(MESON_TARGET_TO_LLVM_${i} ${mod})
150 endforeach()
151 endif()
152 endforeach()
153
154 # Check the following variables:
155 # LLVM_PACKAGE_VERSION
156 # LLVM_VERSION
157 # LLVM_VERSION_STRING
158 if(NOT DEFINED PACKAGE_VERSION)
159 if(DEFINED LLVM_PACKAGE_VERSION)
160 set(PACKAGE_VERSION "${LLVM_PACKAGE_VERSION}")
161 elseif(DEFINED LLVM_VERSION)
162 set(PACKAGE_VERSION "${LLVM_VERSION}")
163 elseif(DEFINED LLVM_VERSION_STRING)
164 set(PACKAGE_VERSION "${LLVM_VERSION_STRING}")
165 endif()
166 endif()
167
168 # Check the following variables:
169 # LLVM_LIBRARIES
170 # LLVM_LIBS
171 set(libs)
172 #Hardcode LLVM, because we links with libLLVM.so when dynamic
173 if(LLVM_MESON_DYLIB)
174 get_target_property(libs LLVM IMPORTED_LOCATION)
175 elseif(DEFINED LLVM_LIBRARIES)
176 set(libs LLVM_LIBRARIES)
177 elseif(DEFINED LLVM_LIBS)
178 set(libs LLVM_LIBS)
179 endif()
180
181 # Check the following variables:
182 # LLVM_INCLUDE_DIRS
183 # LLVM_INCLUDES
184 # LLVM_INCLUDE_DIR
185 set(includes)
186 if(DEFINED LLVM_INCLUDE_DIRS)
187 set(includes LLVM_INCLUDE_DIRS)
188 elseif(DEFINED LLVM_INCLUDES)
189 set(includes LLVM_INCLUDES)
190 elseif(DEFINED LLVM_INCLUDE_DIR)
191 set(includes LLVM_INCLUDE_DIR)
192 endif()
193
194 # Check the following variables:
195 # LLVM_DEFINITIONS
196 set(definitions)
197 if(DEFINED LLVM_DEFINITIONS)
198 set(definitions LLVM_DEFINITIONS)
199 endif()
200
201 set(PACKAGE_INCLUDE_DIRS "${${includes}}")
202 set(PACKAGE_DEFINITIONS "${${definitions}}")
203 set(PACKAGE_LIBRARIES "${${libs}}")
204 endif()