CMake: optional modules support
This commit is contained in:
parent
a9930fe066
commit
55379b7d0f
|
@ -977,7 +977,7 @@ class CMakeDependency(ExternalDependency):
|
|||
def _extra_cmake_opts(self):
|
||||
return []
|
||||
|
||||
def _map_module_list(self, modules: List[str]) -> List[str]:
|
||||
def _map_module_list(self, modules: List[Tuple[str, bool]]) -> List[Tuple[str, bool]]:
|
||||
# Map the input module list to something else
|
||||
# This function will only be executed AFTER the initial CMake
|
||||
# interpreter pass has completed. Thus variables defined in the
|
||||
|
@ -1074,7 +1074,8 @@ class CMakeDependency(ExternalDependency):
|
|||
if self.cmakeinfo is None:
|
||||
raise self._gen_exception('Unable to obtain CMake system information')
|
||||
|
||||
modules = kwargs.get('modules', [])
|
||||
modules = [(x, True) for x in kwargs.get('modules', [])]
|
||||
modules += [(x, False) for x in kwargs.get('optional_modules', [])]
|
||||
cm_path = kwargs.get('cmake_module_path', [])
|
||||
cm_args = kwargs.get('cmake_args', [])
|
||||
if not isinstance(modules, list):
|
||||
|
@ -1255,7 +1256,7 @@ class CMakeDependency(ExternalDependency):
|
|||
|
||||
return False
|
||||
|
||||
def _detect_dep(self, name: str, modules: List[str], args: List[str]):
|
||||
def _detect_dep(self, name: str, modules: List[Tuple[str, bool]], args: List[str]):
|
||||
# Detect a dependency with CMake using the '--find-package' mode
|
||||
# and the trace output (stderr)
|
||||
#
|
||||
|
@ -1352,7 +1353,7 @@ class CMakeDependency(ExternalDependency):
|
|||
lname = name.lower()
|
||||
if '{}::{}'.format(lname, lname) == tg or lname == tg.replace('::', ''):
|
||||
mlog.debug('Guessed CMake target \'{}\''.format(i))
|
||||
modules = [i]
|
||||
modules = [(i, True)]
|
||||
break
|
||||
|
||||
# Failed to guess a target --> try the old-style method
|
||||
|
@ -1380,8 +1381,11 @@ class CMakeDependency(ExternalDependency):
|
|||
compileDefinitions = []
|
||||
compileOptions = []
|
||||
libraries = []
|
||||
for i in modules:
|
||||
for i, required in modules:
|
||||
if i not in self.targets:
|
||||
if not required:
|
||||
mlog.warning('CMake: Optional CMake target', mlog.bold(i), 'for', mlog.bold(name), 'was not found')
|
||||
continue
|
||||
raise self._gen_exception('CMake: invalid CMake target {} for {}.\n'
|
||||
'Try to explicitly specify one or more targets with the "modules" property.\n'
|
||||
'Valid targets are:\n{}'.format(i, name, list(self.targets.keys())))
|
||||
|
|
|
@ -17,8 +17,10 @@ endwhile()
|
|||
if(LLVM_FOUND)
|
||||
set(PACKAGE_FOUND TRUE)
|
||||
|
||||
llvm_map_components_to_libnames(llvm_libs ${LLVM_MESON_MODULES})
|
||||
set(MESON_RESOLVED_LLVM_MODULES ${llvm_libs})
|
||||
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})
|
||||
|
||||
# Check the following variables:
|
||||
# LLVM_PACKAGE_VERSION
|
||||
|
|
|
@ -401,7 +401,8 @@ class LLVMDependencyConfigTool(ConfigToolDependency):
|
|||
|
||||
class LLVMDependencyCMake(CMakeDependency):
|
||||
def __init__(self, env, kwargs):
|
||||
self.llvm_modules = kwargs.get('modules', [])
|
||||
self.llvm_modules = stringlistify(extract_as_list(kwargs, 'modules'))
|
||||
self.llvm_opt_modules = stringlistify(extract_as_list(kwargs, 'optional_modules'))
|
||||
super().__init__(name='LLVM', environment=env, language='cpp', kwargs=kwargs)
|
||||
|
||||
# Extract extra include directories and definitions
|
||||
|
@ -415,10 +416,13 @@ class LLVMDependencyCMake(CMakeDependency):
|
|||
return 'CMakeListsLLVM.txt'
|
||||
|
||||
def _extra_cmake_opts(self):
|
||||
return ['-DLLVM_MESON_MODULES={}'.format(';'.join(self.llvm_modules))]
|
||||
return ['-DLLVM_MESON_MODULES={}'.format(';'.join(self.llvm_modules)),
|
||||
'-DLLVM_MESON_OPT_MODULES={}'.format(';'.join(self.llvm_opt_modules))]
|
||||
|
||||
def _map_module_list(self, modules):
|
||||
return self.get_cmake_var('MESON_RESOLVED_LLVM_MODULES')
|
||||
modules = [(x, True) for x in self.get_cmake_var('MESON_RESOLVED_LLVM_MODULES')]
|
||||
modules += [(x, False) for x in self.get_cmake_var('MESON_RESOLVED_LLVM_MODULES_OPT')]
|
||||
return modules
|
||||
|
||||
def need_threads(self):
|
||||
return True
|
||||
|
|
Loading…
Reference in New Issue