cmake: LLVM better modules handling

pull/5185/head
Daniel Mensinger 6 years ago
parent 3f539e01ae
commit 1fba945b61
No known key found for this signature in database
GPG Key ID: 54DD94C131E277D4
  1. 5
      mesonbuild/dependencies/base.py
  2. 31
      mesonbuild/dependencies/data/CMakeListsLLVM.txt
  3. 32
      mesonbuild/dependencies/dev.py
  4. 2
      test cases/frameworks/15 llvm/meson.build

@ -1462,7 +1462,7 @@ class CMakeDependency(ExternalDependency):
self.compile_args = compileOptions + compileDefinitions + list(map(lambda x: '-I{}'.format(x), incDirs)) self.compile_args = compileOptions + compileDefinitions + list(map(lambda x: '-I{}'.format(x), incDirs))
self.link_args = libraries self.link_args = libraries
def get_first_cmake_var_of(self, var_list): def get_first_cmake_var_of(self, var_list: List[str]) -> List[str]:
# Return the first found CMake variable in list var_list # Return the first found CMake variable in list var_list
for i in var_list: for i in var_list:
if i in self.vars: if i in self.vars:
@ -1470,7 +1470,7 @@ class CMakeDependency(ExternalDependency):
return [] return []
def get_cmake_var(self, var): def get_cmake_var(self, var: str) -> List[str]:
# Return the value of the CMake variable var or an empty list if var does not exist # Return the value of the CMake variable var or an empty list if var does not exist
if var in self.vars: if var in self.vars:
return self.vars[var] return self.vars[var]
@ -1779,6 +1779,7 @@ set(CMAKE_SIZEOF_VOID_P "{}")
def log_details(self) -> str: def log_details(self) -> str:
modules = [self._original_module_name(x) for x in self.found_modules] modules = [self._original_module_name(x) for x in self.found_modules]
modules = sorted(set(modules))
if modules: if modules:
return 'modules: ' + ', '.join(modules) return 'modules: ' + ', '.join(modules)
return '' return ''

@ -17,10 +17,33 @@ endwhile()
if(LLVM_FOUND) if(LLVM_FOUND)
set(PACKAGE_FOUND TRUE) set(PACKAGE_FOUND TRUE)
llvm_map_components_to_libnames(llvm_libs ${LLVM_MESON_MODULES}) foreach(mod IN LISTS LLVM_MESON_MODULES)
llvm_map_components_to_libnames(llvm_libs_opt ${LLVM_MESON_OPT_MODULES}) # Reset variables
set(MESON_RESOLVED_LLVM_MODULES ${llvm_libs}) set(out_mods)
set(MESON_RESOLVED_LLVM_MODULES_OPT ${llvm_libs_opt}) set(real_mods)
# Generate a lower and upper case version
string(TOLOWER "${mod}" mod_L)
string(TOUPPER "${mod}" mod_U)
# Get the mapped components
llvm_map_components_to_libnames(out_mods ${mod} ${mod_L} ${mod_U})
list(SORT out_mods)
list(REMOVE_DUPLICATES out_mods)
# Make sure that the modules exist
foreach(i IN LISTS out_mods)
if(TARGET ${i})
list(APPEND real_mods ${i})
endif()
endforeach()
# Set the output variables
set(MESON_LLVM_TARGETS_${mod} ${real_mods})
foreach(i IN LISTS real_mods)
set(MESON_TARGET_TO_LLVM_${i} ${mod})
endforeach()
endforeach()
# Check the following variables: # Check the following variables:
# LLVM_PACKAGE_VERSION # LLVM_PACKAGE_VERSION

@ -20,7 +20,7 @@ import glob
import os import os
import re import re
from .. import mesonlib from .. import mesonlib, mlog
from ..mesonlib import version_compare, stringlistify, extract_as_list, MachineChoice from ..mesonlib import version_compare, stringlistify, extract_as_list, MachineChoice
from .base import ( from .base import (
DependencyException, DependencyMethods, ExternalDependency, PkgConfigDependency, DependencyException, DependencyMethods, ExternalDependency, PkgConfigDependency,
@ -405,7 +405,6 @@ class LLVMDependencyCMake(CMakeDependency):
def __init__(self, env, kwargs): def __init__(self, env, kwargs):
self.llvm_modules = stringlistify(extract_as_list(kwargs, 'modules')) self.llvm_modules = stringlistify(extract_as_list(kwargs, 'modules'))
self.llvm_opt_modules = stringlistify(extract_as_list(kwargs, 'optional_modules')) self.llvm_opt_modules = stringlistify(extract_as_list(kwargs, 'optional_modules'))
self.module_map = {}
super().__init__(name='LLVM', environment=env, language='cpp', kwargs=kwargs) super().__init__(name='LLVM', environment=env, language='cpp', kwargs=kwargs)
# Extract extra include directories and definitions # Extract extra include directories and definitions
@ -419,22 +418,27 @@ class LLVMDependencyCMake(CMakeDependency):
return 'CMakeListsLLVM.txt' return 'CMakeListsLLVM.txt'
def _extra_cmake_opts(self) -> List[str]: def _extra_cmake_opts(self) -> List[str]:
return ['-DLLVM_MESON_MODULES={}'.format(';'.join(self.llvm_modules)), return ['-DLLVM_MESON_MODULES={}'.format(';'.join(self.llvm_modules + self.llvm_opt_modules))]
'-DLLVM_MESON_OPT_MODULES={}'.format(';'.join(self.llvm_opt_modules))]
def _map_module_list(self, modules: List[Tuple[str, bool]]) -> List[Tuple[str, bool]]: def _map_module_list(self, modules: List[Tuple[str, bool]]) -> List[Tuple[str, bool]]:
res_modules = self.get_cmake_var('MESON_RESOLVED_LLVM_MODULES') res = []
res_opt_modules = self.get_cmake_var('MESON_RESOLVED_LLVM_MODULES_OPT') for mod, required in modules:
modules = [(x, True) for x in res_modules] cm_targets = self.get_cmake_var('MESON_LLVM_TARGETS_{}'.format(mod))
modules += [(x, False) for x in res_opt_modules] if not cm_targets:
self.module_map = { if required:
**dict(zip(res_modules, self.llvm_modules)), raise self._gen_exception('LLVM module {} was not found'.format(mod))
**dict(zip(res_opt_modules, self.llvm_opt_modules)) else:
} mlog.warning('Optional LLVM module', mlog.bold(mod), 'was not found')
return modules continue
for i in cm_targets:
res += [(i, required)]
return res
def _original_module_name(self, module: str) -> str: def _original_module_name(self, module: str) -> str:
return self.module_map.get(module, module) orig_name = self.get_cmake_var('MESON_TARGET_TO_LLVM_{}'.format(module))
if orig_name:
return orig_name[0]
return module
def need_threads(self) -> bool: def need_threads(self) -> bool:
return True return True

@ -35,7 +35,7 @@ foreach static : [true, false]
llvm_dep = dependency( llvm_dep = dependency(
'llvm', 'llvm',
modules : ['bitwriter', 'asmprinter', 'executionengine', 'target', modules : ['bitwriter', 'asmprinter', 'executionengine', 'target',
'mcjit', 'nativecodegen'], 'mcjit', 'nativecodegen', 'amdgpu'],
required : false, required : false,
static : static, static : static,
) )

Loading…
Cancel
Save