cmake: LLVM better modules handling
This commit is contained in:
parent
3f539e01ae
commit
1fba945b61
|
@ -1462,7 +1462,7 @@ class CMakeDependency(ExternalDependency):
|
|||
self.compile_args = compileOptions + compileDefinitions + list(map(lambda x: '-I{}'.format(x), incDirs))
|
||||
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
|
||||
for i in var_list:
|
||||
if i in self.vars:
|
||||
|
@ -1470,7 +1470,7 @@ class CMakeDependency(ExternalDependency):
|
|||
|
||||
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
|
||||
if var in self.vars:
|
||||
return self.vars[var]
|
||||
|
@ -1779,6 +1779,7 @@ set(CMAKE_SIZEOF_VOID_P "{}")
|
|||
|
||||
def log_details(self) -> str:
|
||||
modules = [self._original_module_name(x) for x in self.found_modules]
|
||||
modules = sorted(set(modules))
|
||||
if modules:
|
||||
return 'modules: ' + ', '.join(modules)
|
||||
return ''
|
||||
|
|
|
@ -17,10 +17,33 @@ endwhile()
|
|||
if(LLVM_FOUND)
|
||||
set(PACKAGE_FOUND TRUE)
|
||||
|
||||
llvm_map_components_to_libnames(llvm_libs ${LLVM_MESON_MODULES})
|
||||
llvm_map_components_to_libnames(llvm_libs_opt ${LLVM_MESON_OPT_MODULES})
|
||||
set(MESON_RESOLVED_LLVM_MODULES ${llvm_libs})
|
||||
set(MESON_RESOLVED_LLVM_MODULES_OPT ${llvm_libs_opt})
|
||||
foreach(mod IN LISTS LLVM_MESON_MODULES)
|
||||
# Reset variables
|
||||
set(out_mods)
|
||||
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:
|
||||
# LLVM_PACKAGE_VERSION
|
||||
|
|
|
@ -20,7 +20,7 @@ import glob
|
|||
import os
|
||||
import re
|
||||
|
||||
from .. import mesonlib
|
||||
from .. import mesonlib, mlog
|
||||
from ..mesonlib import version_compare, stringlistify, extract_as_list, MachineChoice
|
||||
from .base import (
|
||||
DependencyException, DependencyMethods, ExternalDependency, PkgConfigDependency,
|
||||
|
@ -405,7 +405,6 @@ class LLVMDependencyCMake(CMakeDependency):
|
|||
def __init__(self, env, kwargs):
|
||||
self.llvm_modules = stringlistify(extract_as_list(kwargs, '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)
|
||||
|
||||
# Extract extra include directories and definitions
|
||||
|
@ -419,22 +418,27 @@ class LLVMDependencyCMake(CMakeDependency):
|
|||
return 'CMakeListsLLVM.txt'
|
||||
|
||||
def _extra_cmake_opts(self) -> List[str]:
|
||||
return ['-DLLVM_MESON_MODULES={}'.format(';'.join(self.llvm_modules)),
|
||||
'-DLLVM_MESON_OPT_MODULES={}'.format(';'.join(self.llvm_opt_modules))]
|
||||
return ['-DLLVM_MESON_MODULES={}'.format(';'.join(self.llvm_modules + self.llvm_opt_modules))]
|
||||
|
||||
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_opt_modules = self.get_cmake_var('MESON_RESOLVED_LLVM_MODULES_OPT')
|
||||
modules = [(x, True) for x in res_modules]
|
||||
modules += [(x, False) for x in res_opt_modules]
|
||||
self.module_map = {
|
||||
**dict(zip(res_modules, self.llvm_modules)),
|
||||
**dict(zip(res_opt_modules, self.llvm_opt_modules))
|
||||
}
|
||||
return modules
|
||||
res = []
|
||||
for mod, required in modules:
|
||||
cm_targets = self.get_cmake_var('MESON_LLVM_TARGETS_{}'.format(mod))
|
||||
if not cm_targets:
|
||||
if required:
|
||||
raise self._gen_exception('LLVM module {} was not found'.format(mod))
|
||||
else:
|
||||
mlog.warning('Optional LLVM module', mlog.bold(mod), 'was not found')
|
||||
continue
|
||||
for i in cm_targets:
|
||||
res += [(i, required)]
|
||||
return res
|
||||
|
||||
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:
|
||||
return True
|
||||
|
|
|
@ -35,7 +35,7 @@ foreach static : [true, false]
|
|||
llvm_dep = dependency(
|
||||
'llvm',
|
||||
modules : ['bitwriter', 'asmprinter', 'executionengine', 'target',
|
||||
'mcjit', 'nativecodegen'],
|
||||
'mcjit', 'nativecodegen', 'amdgpu'],
|
||||
required : false,
|
||||
static : static,
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue