1# Copyright 2021 The Meson development team
2
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6
7#     http://www.apache.org/licenses/LICENSE-2.0
8
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15
16####
17####  WARNING: This is an automatically generated file! Do not edit!
18####           Generated by tools/gen_data.py
19####
20
21
22# TODO: Remember to remove this also from tools/gen_data.py
23from pathlib import Path
24import typing as T
25
26if T.TYPE_CHECKING:
27    from .environment import Environment
28
29######################
30# BEGIN Data section #
31######################
32
33file_0_data_preload_cmake = '''\
34if(MESON_PS_LOADED)
35  return()
36endif()
37
38set(MESON_PS_LOADED ON)
39
40cmake_policy(PUSH)
41cmake_policy(SET CMP0054 NEW) # https://cmake.org/cmake/help/latest/policy/CMP0054.html
42
43# Dummy macros that have a special meaning in the meson code
44macro(meson_ps_execute_delayed_calls)
45endmacro()
46
47macro(meson_ps_reload_vars)
48endmacro()
49
50macro(meson_ps_disabled_function)
51  message(WARNING "The function '${ARGV0}' is disabled in the context of CMake subprojects.\n"
52                  "This should not be an issue but may lead to compilation errors.")
53endmacro()
54
55# Helper macro to inspect the current CMake state
56macro(meson_ps_inspect_vars)
57  set(MESON_PS_CMAKE_CURRENT_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}")
58  set(MESON_PS_CMAKE_CURRENT_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
59  meson_ps_execute_delayed_calls()
60endmacro()
61
62
63# Override some system functions with custom code and forward the args
64# to the original function
65macro(add_custom_command)
66  meson_ps_inspect_vars()
67  _add_custom_command(${ARGV})
68endmacro()
69
70macro(add_custom_target)
71  meson_ps_inspect_vars()
72  _add_custom_target(${ARGV})
73endmacro()
74
75macro(set_property)
76  meson_ps_inspect_vars()
77  _set_property(${ARGV})
78endmacro()
79
80function(set_source_files_properties)
81  set(FILES)
82  set(I 0)
83  set(PROPERTIES OFF)
84
85  while(I LESS ARGC)
86    if(NOT PROPERTIES)
87      if("${ARGV${I}}" STREQUAL "PROPERTIES")
88        set(PROPERTIES ON)
89      else()
90        list(APPEND FILES "${ARGV${I}}")
91      endif()
92
93      math(EXPR I "${I} + 1")
94    else()
95      set(ID_IDX ${I})
96      math(EXPR PROP_IDX "${ID_IDX} + 1")
97
98      set(ID   "${ARGV${ID_IDX}}")
99      set(PROP "${ARGV${PROP_IDX}}")
100
101      set_property(SOURCE ${FILES} PROPERTY "${ID}" "${PROP}")
102      math(EXPR I "${I} + 2")
103    endif()
104  endwhile()
105endfunction()
106
107# Disable some functions that would mess up the CMake meson integration
108macro(target_precompile_headers)
109  meson_ps_disabled_function(target_precompile_headers)
110endmacro()
111
112set(MESON_PS_DELAYED_CALLS add_custom_command;add_custom_target;set_property)
113meson_ps_reload_vars()
114
115cmake_policy(POP)
116'''
117
118file_1_data_CMakeLists_txt = '''\
119# fail noisily if attempt to use this file without setting:
120# cmake_minimum_required(VERSION ${CMAKE_VERSION})
121# project(... LANGUAGES ...)
122
123cmake_policy(SET CMP0000 NEW)
124
125set(PACKAGE_FOUND FALSE)
126set(_packageName "${NAME}")
127string(TOUPPER "${_packageName}" PACKAGE_NAME)
128
129while(TRUE)
130  if ("${VERSION}" STREQUAL "")
131    find_package("${NAME}" QUIET COMPONENTS ${COMPS})
132  else()
133    find_package("${NAME}" "${VERSION}" QUIET COMPONENTS ${COMPS})
134  endif()
135
136  # ARCHS has to be set via the CMD interface
137  if(${_packageName}_FOUND OR ${PACKAGE_NAME}_FOUND OR "${ARCHS}" STREQUAL "")
138    break()
139  endif()
140
141  list(GET       ARCHS 0 CMAKE_LIBRARY_ARCHITECTURE)
142  list(REMOVE_AT ARCHS 0)
143endwhile()
144
145if(${_packageName}_FOUND  OR  ${PACKAGE_NAME}_FOUND)
146  set(PACKAGE_FOUND TRUE)
147
148  # Check the following variables:
149  # FOO_VERSION
150  # Foo_VERSION
151  # FOO_VERSION_STRING
152  # Foo_VERSION_STRING
153  if(NOT DEFINED PACKAGE_VERSION)
154    if(DEFINED ${_packageName}_VERSION)
155      set(PACKAGE_VERSION "${${_packageName}_VERSION}")
156    elseif(DEFINED ${PACKAGE_NAME}_VERSION)
157      set(PACKAGE_VERSION "${${PACKAGE_NAME}_VERSION}")
158    elseif(DEFINED ${_packageName}_VERSION_STRING)
159      set(PACKAGE_VERSION "${${_packageName}_VERSION_STRING}")
160    elseif(DEFINED ${PACKAGE_NAME}_VERSION_STRING)
161      set(PACKAGE_VERSION "${${PACKAGE_NAME}_VERSION_STRING}")
162    endif()
163  endif()
164
165  # Check the following variables:
166  # FOO_LIBRARIES
167  # Foo_LIBRARIES
168  # FOO_LIBS
169  # Foo_LIBS
170  set(libs)
171  if(DEFINED ${_packageName}_LIBRARIES)
172    set(libs ${_packageName}_LIBRARIES)
173  elseif(DEFINED ${PACKAGE_NAME}_LIBRARIES)
174    set(libs ${PACKAGE_NAME}_LIBRARIES)
175  elseif(DEFINED ${_packageName}_LIBS)
176    set(libs ${_packageName}_LIBS)
177  elseif(DEFINED ${PACKAGE_NAME}_LIBS)
178    set(libs ${PACKAGE_NAME}_LIBS)
179  endif()
180
181  # Check the following variables:
182  # FOO_INCLUDE_DIRS
183  # Foo_INCLUDE_DIRS
184  # FOO_INCLUDES
185  # Foo_INCLUDES
186  # FOO_INCLUDE_DIR
187  # Foo_INCLUDE_DIR
188  set(includes)
189  if(DEFINED ${_packageName}_INCLUDE_DIRS)
190    set(includes ${_packageName}_INCLUDE_DIRS)
191  elseif(DEFINED ${PACKAGE_NAME}_INCLUDE_DIRS)
192    set(includes ${PACKAGE_NAME}_INCLUDE_DIRS)
193  elseif(DEFINED ${_packageName}_INCLUDES)
194    set(includes ${_packageName}_INCLUDES)
195  elseif(DEFINED ${PACKAGE_NAME}_INCLUDES)
196    set(includes ${PACKAGE_NAME}_INCLUDES)
197  elseif(DEFINED ${_packageName}_INCLUDE_DIR)
198    set(includes ${_packageName}_INCLUDE_DIR)
199  elseif(DEFINED ${PACKAGE_NAME}_INCLUDE_DIR)
200    set(includes ${PACKAGE_NAME}_INCLUDE_DIR)
201  endif()
202
203  # Check the following variables:
204  # FOO_DEFINITIONS
205  # Foo_DEFINITIONS
206  set(definitions)
207  if(DEFINED ${_packageName}_DEFINITIONS)
208    set(definitions ${_packageName}_DEFINITIONS)
209  elseif(DEFINED ${PACKAGE_NAME}_DEFINITIONS)
210    set(definitions ${PACKAGE_NAME}_DEFINITIONS)
211  endif()
212
213  set(PACKAGE_INCLUDE_DIRS "${${includes}}")
214  set(PACKAGE_DEFINITIONS  "${${definitions}}")
215  set(PACKAGE_LIBRARIES    "${${libs}}")
216endif()
217'''
218
219file_2_data_CMakeListsLLVM_txt = '''\
220cmake_minimum_required(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION} )
221
222set(PACKAGE_FOUND FALSE)
223
224while(TRUE)
225  find_package(LLVM REQUIRED CONFIG QUIET)
226
227  # ARCHS has to be set via the CMD interface
228  if(LLVM_FOUND OR "${ARCHS}" STREQUAL "")
229    break()
230  endif()
231
232  list(GET       ARCHS 0 CMAKE_LIBRARY_ARCHITECTURE)
233  list(REMOVE_AT ARCHS 0)
234endwhile()
235
236if(LLVM_FOUND)
237  set(PACKAGE_FOUND TRUE)
238
239  foreach(mod IN LISTS LLVM_MESON_MODULES)
240    # Reset variables
241    set(out_mods)
242    set(real_mods)
243
244    # Generate a lower and upper case version
245    string(TOLOWER "${mod}" mod_L)
246    string(TOUPPER "${mod}" mod_U)
247
248    # Get the mapped components
249    llvm_map_components_to_libnames(out_mods ${mod} ${mod_L} ${mod_U})
250    list(SORT              out_mods)
251    list(REMOVE_DUPLICATES out_mods)
252
253    # Make sure that the modules exist
254    foreach(i IN LISTS out_mods)
255      if(TARGET ${i})
256        list(APPEND real_mods ${i})
257      endif()
258    endforeach()
259
260    # Set the output variables
261    set(MESON_LLVM_TARGETS_${mod} ${real_mods})
262    foreach(i IN LISTS real_mods)
263      set(MESON_TARGET_TO_LLVM_${i} ${mod})
264    endforeach()
265  endforeach()
266
267  # Check the following variables:
268  # LLVM_PACKAGE_VERSION
269  # LLVM_VERSION
270  # LLVM_VERSION_STRING
271  if(NOT DEFINED PACKAGE_VERSION)
272    if(DEFINED LLVM_PACKAGE_VERSION)
273      set(PACKAGE_VERSION "${LLVM_PACKAGE_VERSION}")
274    elseif(DEFINED LLVM_VERSION)
275      set(PACKAGE_VERSION "${LLVM_VERSION}")
276    elseif(DEFINED LLVM_VERSION_STRING)
277      set(PACKAGE_VERSION "${LLVM_VERSION_STRING}")
278    endif()
279  endif()
280
281  # Check the following variables:
282  # LLVM_LIBRARIES
283  # LLVM_LIBS
284  set(libs)
285  if(DEFINED LLVM_LIBRARIES)
286    set(libs LLVM_LIBRARIES)
287  elseif(DEFINED LLVM_LIBS)
288    set(libs LLVM_LIBS)
289  endif()
290
291  # Check the following variables:
292  # LLVM_INCLUDE_DIRS
293  # LLVM_INCLUDES
294  # LLVM_INCLUDE_DIR
295  set(includes)
296  if(DEFINED LLVM_INCLUDE_DIRS)
297    set(includes LLVM_INCLUDE_DIRS)
298  elseif(DEFINED LLVM_INCLUDES)
299    set(includes LLVM_INCLUDES)
300  elseif(DEFINED LLVM_INCLUDE_DIR)
301    set(includes LLVM_INCLUDE_DIR)
302  endif()
303
304  # Check the following variables:
305  # LLVM_DEFINITIONS
306  set(definitions)
307  if(DEFINED LLVM_DEFINITIONS)
308    set(definitions LLVM_DEFINITIONS)
309  endif()
310
311  set(PACKAGE_INCLUDE_DIRS "${${includes}}")
312  set(PACKAGE_DEFINITIONS  "${${definitions}}")
313  set(PACKAGE_LIBRARIES    "${${libs}}")
314endif()
315'''
316
317file_3_data_CMakePathInfo_txt = '''\
318cmake_minimum_required(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION})
319
320set(TMP_PATHS_LIST)
321list(APPEND TMP_PATHS_LIST ${CMAKE_PREFIX_PATH})
322list(APPEND TMP_PATHS_LIST ${CMAKE_FRAMEWORK_PATH})
323list(APPEND TMP_PATHS_LIST ${CMAKE_APPBUNDLE_PATH})
324list(APPEND TMP_PATHS_LIST $ENV{CMAKE_PREFIX_PATH})
325list(APPEND TMP_PATHS_LIST $ENV{CMAKE_FRAMEWORK_PATH})
326list(APPEND TMP_PATHS_LIST $ENV{CMAKE_APPBUNDLE_PATH})
327list(APPEND TMP_PATHS_LIST ${CMAKE_SYSTEM_PREFIX_PATH})
328list(APPEND TMP_PATHS_LIST ${CMAKE_SYSTEM_FRAMEWORK_PATH})
329list(APPEND TMP_PATHS_LIST ${CMAKE_SYSTEM_APPBUNDLE_PATH})
330
331set(LIB_ARCH_LIST)
332if(CMAKE_LIBRARY_ARCHITECTURE_REGEX)
333  file(GLOB implicit_dirs RELATIVE /lib /lib/*-linux-gnu* )
334  foreach(dir ${implicit_dirs})
335    if("${dir}" MATCHES "${CMAKE_LIBRARY_ARCHITECTURE_REGEX}")
336      list(APPEND LIB_ARCH_LIST "${dir}")
337    endif()
338  endforeach()
339endif()
340
341# "Export" these variables:
342set(MESON_ARCH_LIST ${LIB_ARCH_LIST})
343set(MESON_PATHS_LIST ${TMP_PATHS_LIST})
344set(MESON_CMAKE_ROOT ${CMAKE_ROOT})
345set(MESON_CMAKE_SYSROOT ${CMAKE_SYSROOT})
346set(MESON_FIND_ROOT_PATH ${CMAKE_FIND_ROOT_PATH})
347
348message(STATUS ${TMP_PATHS_LIST})
349'''
350
351
352####################
353# END Data section #
354####################
355
356class DataFile:
357    def __init__(self, path: Path, sha256sum: str, data: str) -> None:
358        self.path = path
359        self.sha256sum = sha256sum
360        self.data = data
361
362    def write_once(self, path: Path) -> None:
363        if not path.exists():
364            path.write_text(self.data, encoding='utf-8')
365
366    def write_to_private(self, env: 'Environment') -> Path:
367        out_file = Path(env.scratch_dir) / 'data' / self.path.name
368        out_file.parent.mkdir(exist_ok=True)
369        self.write_once(out_file)
370        return out_file
371
372
373mesondata = {
374    'cmake/data/preload.cmake': DataFile(
375        Path('cmake/data/preload.cmake'),
376        'ce8f30159aab25b92c26c58a219a427d47838bfa0739475221d6c8993b4946e5',
377        file_0_data_preload_cmake,
378    ),
379    'dependencies/data/CMakeLists.txt': DataFile(
380        Path('dependencies/data/CMakeLists.txt'),
381        '4dca24afa13e9311f0598a6ac29690490819bd7d82cfdaa0a2fe5eea3c0fa0d5',
382        file_1_data_CMakeLists_txt,
383    ),
384    'dependencies/data/CMakeListsLLVM.txt': DataFile(
385        Path('dependencies/data/CMakeListsLLVM.txt'),
386        '412cec3315597041a978d018cdaca282dcd47693793540da88ae2f80d0cbd7cd',
387        file_2_data_CMakeListsLLVM_txt,
388    ),
389    'dependencies/data/CMakePathInfo.txt': DataFile(
390        Path('dependencies/data/CMakePathInfo.txt'),
391        '90da8b443982d9c87139b7dc84228eb58cab4315764949637208f25e2bda7db2',
392        file_3_data_CMakePathInfo_txt,
393    ),
394}
395