Add an option to dependencies called 'method'. This can be used to

configure a detection method, for those types of dependencies that have
more than one means of detection.

The default detection methods are unchanged if 'method' is not
specified, and all dependencies support the method 'auto', which is the
same as not specifying a method.

The dependencies which do support multiple detection methods
additionally support other values, depending on the dependency.
pull/1588/head
Aaron Small 8 years ago
parent b89af8b6dd
commit 76c8491d77
  1. 106
      mesonbuild/dependencies.py
  2. 13
      mesonbuild/mlog.py
  3. 7
      mesonbuild/modules/qt4.py
  4. 7
      mesonbuild/modules/qt5.py
  5. 6
      run_unittests.py
  6. 14
      test cases/frameworks/4 qt/meson.build
  7. 1
      test cases/frameworks/4 qt/meson_options.txt

@ -34,10 +34,20 @@ class DependencyException(MesonException):
'''Exceptions raised while trying to find dependencies''' '''Exceptions raised while trying to find dependencies'''
class Dependency: class Dependency:
def __init__(self, type_name='unknown'): def __init__(self, type_name, kwargs):
self.name = "null" self.name = "null"
self.is_found = False self.is_found = False
self.type_name = type_name self.type_name = type_name
method = kwargs.get('method', 'auto')
# Set the detection method. If the method is set to auto, use any available method.
# If method is set to a specific string, allow only that detection method.
if method == "auto":
self.methods = self.get_methods()
elif method in self.get_methods():
self.methods = [method]
else:
raise MesonException('Unsupported detection method: {}, allowed methods are {}'.format(method, mlog.format_list(["auto"] + self.get_methods())))
def __repr__(self): def __repr__(self):
s = '<{0} {1}: {2}>' s = '<{0} {1}: {2}>'
@ -57,6 +67,9 @@ class Dependency:
As an example, gtest-all.cc when using GTest.""" As an example, gtest-all.cc when using GTest."""
return [] return []
def get_methods(self):
return ['auto']
def get_name(self): def get_name(self):
return self.name return self.name
@ -71,7 +84,7 @@ class Dependency:
class InternalDependency(Dependency): class InternalDependency(Dependency):
def __init__(self, version, incdirs, compile_args, link_args, libraries, sources, ext_deps): def __init__(self, version, incdirs, compile_args, link_args, libraries, sources, ext_deps):
super().__init__('internal') super().__init__('internal', {})
self.version = version self.version = version
self.include_directories = incdirs self.include_directories = incdirs
self.compile_args = compile_args self.compile_args = compile_args
@ -95,7 +108,7 @@ class PkgConfigDependency(Dependency):
class_pkgbin = None class_pkgbin = None
def __init__(self, name, environment, kwargs): def __init__(self, name, environment, kwargs):
Dependency.__init__(self, 'pkgconfig') Dependency.__init__(self, 'pkgconfig', kwargs)
self.is_libtool = False self.is_libtool = False
self.required = kwargs.get('required', True) self.required = kwargs.get('required', True)
self.static = kwargs.get('static', False) self.static = kwargs.get('static', False)
@ -254,6 +267,9 @@ class PkgConfigDependency(Dependency):
def get_link_args(self): def get_link_args(self):
return self.libs return self.libs
def get_methods(self):
return ['pkgconfig']
def check_pkgconfig(self): def check_pkgconfig(self):
evar = 'PKG_CONFIG' evar = 'PKG_CONFIG'
if evar in os.environ: if evar in os.environ:
@ -322,7 +338,7 @@ class WxDependency(Dependency):
wx_found = None wx_found = None
def __init__(self, environment, kwargs): def __init__(self, environment, kwargs):
Dependency.__init__(self, 'wx') Dependency.__init__(self, 'wx', kwargs)
self.is_found = False self.is_found = False
self.modversion = 'none' self.modversion = 'none'
if WxDependency.wx_found is None: if WxDependency.wx_found is None:
@ -542,7 +558,7 @@ class ExternalLibrary(Dependency):
# TODO: Add `lang` to the parent Dependency object so that dependencies can # TODO: Add `lang` to the parent Dependency object so that dependencies can
# be expressed for languages other than C-like # be expressed for languages other than C-like
def __init__(self, name, link_args=None, language=None, silent=False): def __init__(self, name, link_args=None, language=None, silent=False):
super().__init__('external') super().__init__('external', {})
self.name = name self.name = name
self.is_found = False self.is_found = False
self.link_args = [] self.link_args = []
@ -582,7 +598,7 @@ class BoostDependency(Dependency):
name2lib = {'test': 'unit_test_framework'} name2lib = {'test': 'unit_test_framework'}
def __init__(self, environment, kwargs): def __init__(self, environment, kwargs):
Dependency.__init__(self, 'boost') Dependency.__init__(self, 'boost', kwargs)
self.name = 'boost' self.name = 'boost'
self.environment = environment self.environment = environment
self.libdir = '' self.libdir = ''
@ -805,7 +821,7 @@ class BoostDependency(Dependency):
class GTestDependency(Dependency): class GTestDependency(Dependency):
def __init__(self, environment, kwargs): def __init__(self, environment, kwargs):
Dependency.__init__(self, 'gtest') Dependency.__init__(self, 'gtest', kwargs)
self.main = kwargs.get('main', False) self.main = kwargs.get('main', False)
self.name = 'gtest' self.name = 'gtest'
self.libname = 'libgtest.so' self.libname = 'libgtest.so'
@ -882,7 +898,7 @@ class GTestDependency(Dependency):
class GMockDependency(Dependency): class GMockDependency(Dependency):
def __init__(self, environment, kwargs): def __init__(self, environment, kwargs):
Dependency.__init__(self, 'gmock') Dependency.__init__(self, 'gmock', kwargs)
# GMock may be a library or just source. # GMock may be a library or just source.
# Work with both. # Work with both.
self.name = 'gmock' self.name = 'gmock'
@ -937,7 +953,7 @@ class GMockDependency(Dependency):
class QtBaseDependency(Dependency): class QtBaseDependency(Dependency):
def __init__(self, name, env, kwargs): def __init__(self, name, env, kwargs):
Dependency.__init__(self, name) Dependency.__init__(self, name, kwargs)
self.name = name self.name = name
self.qtname = name.capitalize() self.qtname = name.capitalize()
self.qtver = name[-1] self.qtver = name[-1]
@ -964,17 +980,23 @@ class QtBaseDependency(Dependency):
type_text = 'cross' if env.is_cross_build() else 'native' type_text = 'cross' if env.is_cross_build() else 'native'
found_msg = '{} {} {{}} dependency (modules: {}) found:' \ found_msg = '{} {} {{}} dependency (modules: {}) found:' \
''.format(self.qtname, type_text, ', '.join(mods)) ''.format(self.qtname, type_text, ', '.join(mods))
from_text = '`pkg-config`' from_text = 'pkg-config'
# Keep track of the detection methods used, for logging purposes.
methods = []
# Prefer pkg-config, then fallback to `qmake -query` # Prefer pkg-config, then fallback to `qmake -query`
if 'pkgconfig' in self.methods:
self._pkgconfig_detect(mods, env, kwargs) self._pkgconfig_detect(mods, env, kwargs)
if not self.is_found: methods.append('pkgconfig')
if not self.is_found and 'qmake' in self.methods:
from_text = self._qmake_detect(mods, env, kwargs) from_text = self._qmake_detect(mods, env, kwargs)
methods.append('qmake-' + self.name)
methods.append('qmake')
if not self.is_found: if not self.is_found:
# Reset compile args and link args # Reset compile args and link args
self.cargs = [] self.cargs = []
self.largs = [] self.largs = []
from_text = '(checked pkg-config, qmake-{}, and qmake)' \ from_text = '(checked {})'.format(mlog.format_list(methods))
''.format(self.name)
self.version = 'none' self.version = 'none'
if self.required: if self.required:
err_msg = '{} {} dependency not found {}' \ err_msg = '{} {} dependency not found {}' \
@ -1053,6 +1075,7 @@ class QtBaseDependency(Dependency):
return return
self.version = re.search(self.qtver + '(\.\d+)+', stdo).group(0) self.version = re.search(self.qtver + '(\.\d+)+', stdo).group(0)
# Query library path, header path, and binary path # Query library path, header path, and binary path
mlog.log("Found qmake:", mlog.bold(self.qmake.get_name()), '(%s)' % self.version)
stdo = Popen_safe(self.qmake.get_command() + ['-query'])[1] stdo = Popen_safe(self.qmake.get_command() + ['-query'])[1]
qvars = {} qvars = {}
for line in stdo.split('\n'): for line in stdo.split('\n'):
@ -1092,7 +1115,7 @@ class QtBaseDependency(Dependency):
libdir = qvars['QT_INSTALL_LIBS'] libdir = qvars['QT_INSTALL_LIBS']
for m in modules: for m in modules:
fname = 'Qt' + m fname = 'Qt' + m
fwdep = ExtraFrameworkDependency(fname, kwargs.get('required', True), libdir) fwdep = ExtraFrameworkDependency(fname, kwargs.get('required', True), libdir, kwargs)
self.cargs.append('-F' + libdir) self.cargs.append('-F' + libdir)
if fwdep.found(): if fwdep.found():
self.is_found = True self.is_found = True
@ -1113,6 +1136,9 @@ class QtBaseDependency(Dependency):
def get_link_args(self): def get_link_args(self):
return self.largs return self.largs
def get_methods(self):
return ['pkgconfig', 'qmake']
def found(self): def found(self):
return self.is_found return self.is_found
@ -1150,7 +1176,7 @@ class Qt4Dependency(QtBaseDependency):
class GnuStepDependency(Dependency): class GnuStepDependency(Dependency):
def __init__(self, environment, kwargs): def __init__(self, environment, kwargs):
Dependency.__init__(self, 'gnustep') Dependency.__init__(self, 'gnustep', kwargs)
self.required = kwargs.get('required', True) self.required = kwargs.get('required', True)
self.modules = kwargs.get('modules', []) self.modules = kwargs.get('modules', [])
self.detect() self.detect()
@ -1248,7 +1274,7 @@ why. As a hack filter out everything that is not a flag."""
class AppleFrameworks(Dependency): class AppleFrameworks(Dependency):
def __init__(self, environment, kwargs): def __init__(self, environment, kwargs):
Dependency.__init__(self, 'appleframeworks') Dependency.__init__(self, 'appleframeworks', kwargs)
modules = kwargs.get('modules', []) modules = kwargs.get('modules', [])
if isinstance(modules, str): if isinstance(modules, str):
modules = [modules] modules = [modules]
@ -1271,10 +1297,11 @@ class AppleFrameworks(Dependency):
class GLDependency(Dependency): class GLDependency(Dependency):
def __init__(self, environment, kwargs): def __init__(self, environment, kwargs):
Dependency.__init__(self, 'gl') Dependency.__init__(self, 'gl', kwargs)
self.is_found = False self.is_found = False
self.cargs = [] self.cargs = []
self.linkargs = [] self.linkargs = []
if 'pkgconfig' in self.methods:
try: try:
pcdep = PkgConfigDependency('gl', environment, kwargs) pcdep = PkgConfigDependency('gl', environment, kwargs)
if pcdep.found(): if pcdep.found():
@ -1286,6 +1313,7 @@ class GLDependency(Dependency):
return return
except Exception: except Exception:
pass pass
if 'system' in self.methods:
if mesonlib.is_osx(): if mesonlib.is_osx():
self.is_found = True self.is_found = True
self.linkargs = ['-framework', 'OpenGL'] self.linkargs = ['-framework', 'OpenGL']
@ -1303,14 +1331,21 @@ class GLDependency(Dependency):
def get_version(self): def get_version(self):
return self.version return self.version
def get_methods(self):
if mesonlib.is_osx() or mesonlib.is_windows():
return ['pkgconfig', 'system']
else:
return ['pkgconfig']
# There are three different ways of depending on SDL2: # There are three different ways of depending on SDL2:
# sdl2-config, pkg-config and OSX framework # sdl2-config, pkg-config and OSX framework
class SDL2Dependency(Dependency): class SDL2Dependency(Dependency):
def __init__(self, environment, kwargs): def __init__(self, environment, kwargs):
Dependency.__init__(self, 'sdl2') Dependency.__init__(self, 'sdl2', kwargs)
self.is_found = False self.is_found = False
self.cargs = [] self.cargs = []
self.linkargs = [] self.linkargs = []
if 'pkgconfig' in self.methods:
try: try:
pcdep = PkgConfigDependency('sdl2', environment, kwargs) pcdep = PkgConfigDependency('sdl2', environment, kwargs)
if pcdep.found(): if pcdep.found():
@ -1323,6 +1358,7 @@ class SDL2Dependency(Dependency):
except Exception as e: except Exception as e:
mlog.debug('SDL 2 not found via pkgconfig. Trying next, error was:', str(e)) mlog.debug('SDL 2 not found via pkgconfig. Trying next, error was:', str(e))
pass pass
if 'sdlconfig' in self.methods:
sdlconf = shutil.which('sdl2-config') sdlconf = shutil.which('sdl2-config')
if sdlconf: if sdlconf:
stdo = Popen_safe(['sdl2-config', '--cflags'])[1] stdo = Popen_safe(['sdl2-config', '--cflags'])[1]
@ -1336,8 +1372,9 @@ class SDL2Dependency(Dependency):
self.version, '(%s)' % sdlconf) self.version, '(%s)' % sdlconf)
return return
mlog.debug('Could not find sdl2-config binary, trying next.') mlog.debug('Could not find sdl2-config binary, trying next.')
if 'extraframework' in self.methods:
if mesonlib.is_osx(): if mesonlib.is_osx():
fwdep = ExtraFrameworkDependency('sdl2', kwargs.get('required', True)) fwdep = ExtraFrameworkDependency('sdl2', kwargs.get('required', True), None, kwargs)
if fwdep.found(): if fwdep.found():
self.is_found = True self.is_found = True
self.cargs = fwdep.get_compile_args() self.cargs = fwdep.get_compile_args()
@ -1358,9 +1395,15 @@ class SDL2Dependency(Dependency):
def get_version(self): def get_version(self):
return self.version return self.version
def get_methods(self):
if mesonlib.is_osx():
return ['pkgconfig', 'sdlconfig', 'extraframework']
else:
return ['pkgconfig', 'sdlconfig']
class ExtraFrameworkDependency(Dependency): class ExtraFrameworkDependency(Dependency):
def __init__(self, name, required, path=None): def __init__(self, name, required, path, kwargs):
Dependency.__init__(self, 'extraframeworks') Dependency.__init__(self, 'extraframeworks', kwargs)
self.name = None self.name = None
self.detect(name, path) self.detect(name, path)
if self.found(): if self.found():
@ -1404,7 +1447,7 @@ class ExtraFrameworkDependency(Dependency):
class ThreadDependency(Dependency): class ThreadDependency(Dependency):
def __init__(self, environment, kwargs): def __init__(self, environment, kwargs):
super().__init__('threads') super().__init__('threads', {})
self.name = 'threads' self.name = 'threads'
self.is_found = True self.is_found = True
mlog.log('Dependency', mlog.bold(self.name), 'found:', mlog.green('YES')) mlog.log('Dependency', mlog.bold(self.name), 'found:', mlog.green('YES'))
@ -1417,11 +1460,12 @@ class ThreadDependency(Dependency):
class Python3Dependency(Dependency): class Python3Dependency(Dependency):
def __init__(self, environment, kwargs): def __init__(self, environment, kwargs):
super().__init__('python3') super().__init__('python3', kwargs)
self.name = 'python3' self.name = 'python3'
self.is_found = False self.is_found = False
# We can only be sure that it is Python 3 at this point # We can only be sure that it is Python 3 at this point
self.version = '3' self.version = '3'
if 'pkgconfig' in self.methods:
try: try:
pkgdep = PkgConfigDependency('python3', environment, kwargs) pkgdep = PkgConfigDependency('python3', environment, kwargs)
if pkgdep.found(): if pkgdep.found():
@ -1433,12 +1477,12 @@ class Python3Dependency(Dependency):
except Exception: except Exception:
pass pass
if not self.is_found: if not self.is_found:
if mesonlib.is_windows(): if mesonlib.is_windows() and 'sysconfig' in self.methods:
self._find_libpy3_windows(environment) self._find_libpy3_windows(environment)
elif mesonlib.is_osx(): elif mesonlib.is_osx() and 'extraframework' in self.methods:
# In OSX the Python 3 framework does not have a version # In OSX the Python 3 framework does not have a version
# number in its name. # number in its name.
fw = ExtraFrameworkDependency('python', False) fw = ExtraFrameworkDependency('python', False, None, kwargs)
if fw.found(): if fw.found():
self.cargs = fw.get_compile_args() self.cargs = fw.get_compile_args()
self.libs = fw.get_link_args() self.libs = fw.get_link_args()
@ -1490,6 +1534,14 @@ class Python3Dependency(Dependency):
def get_link_args(self): def get_link_args(self):
return self.libs return self.libs
def get_methods(self):
if mesonlib.is_windows():
return ['pkgconfig', 'sysconfig']
elif mesonlib.is_osx():
return ['pkgconfig', 'extraframework']
else:
return ['pkgconfig']
def get_version(self): def get_version(self):
return self.version return self.version
@ -1537,7 +1589,7 @@ def find_external_dependency(name, environment, kwargs):
except Exception as e: except Exception as e:
pkg_exc = e pkg_exc = e
if mesonlib.is_osx(): if mesonlib.is_osx():
fwdep = ExtraFrameworkDependency(name, required) fwdep = ExtraFrameworkDependency(name, required, None, kwargs)
if required and not fwdep.found(): if required and not fwdep.found():
m = 'Dependency {!r} not found, tried Extra Frameworks ' \ m = 'Dependency {!r} not found, tried Extra Frameworks ' \
'and Pkg-Config:\n\n' + str(pkg_exc) 'and Pkg-Config:\n\n' + str(pkg_exc)

@ -99,3 +99,16 @@ def log(*args, **kwargs):
def warning(*args, **kwargs): def warning(*args, **kwargs):
log(yellow('WARNING:'), *args, **kwargs) log(yellow('WARNING:'), *args, **kwargs)
# Format a list for logging purposes as a string. It separates
# all but the last item with commas, and the last with 'and'.
def format_list(list):
l = len(list)
if l > 2:
return ' and '.join([', '.join(list[:-1]), list[-1]])
elif l == 2:
return ' and '.join(list)
elif l == 1:
return list[0]
else:
return ''

@ -24,14 +24,14 @@ from . import ModuleReturnValue
class Qt4Module(ExtensionModule): class Qt4Module(ExtensionModule):
tools_detected = False tools_detected = False
def _detect_tools(self, env): def _detect_tools(self, env, method):
if self.tools_detected: if self.tools_detected:
return return
mlog.log('Detecting Qt4 tools') mlog.log('Detecting Qt4 tools')
# FIXME: We currently require Qt4 to exist while importing the module. # FIXME: We currently require Qt4 to exist while importing the module.
# We should make it gracefully degrade and not create any targets if # We should make it gracefully degrade and not create any targets if
# the import is marked as 'optional' (not implemented yet) # the import is marked as 'optional' (not implemented yet)
kwargs = {'required': 'true', 'modules': 'Core', 'silent': 'true'} kwargs = {'required': 'true', 'modules': 'Core', 'silent': 'true', 'method': method}
qt4 = Qt4Dependency(env, kwargs) qt4 = Qt4Dependency(env, kwargs)
# Get all tools and then make sure that they are the right version # Get all tools and then make sure that they are the right version
self.moc, self.uic, self.rcc = qt4.compilers_detect() self.moc, self.uic, self.rcc = qt4.compilers_detect()
@ -113,7 +113,8 @@ class Qt4Module(ExtensionModule):
if not isinstance(sources, list): if not isinstance(sources, list):
sources = [sources] sources = [sources]
sources += args[1:] sources += args[1:]
self._detect_tools(state.environment) method = kwargs.get('method', 'auto')
self._detect_tools(state.environment, method)
err_msg = "{0} sources specified and couldn't find {1}, " \ err_msg = "{0} sources specified and couldn't find {1}, " \
"please check your qt4 installation" "please check your qt4 installation"
if len(moc_headers) + len(moc_sources) > 0 and not self.moc.found(): if len(moc_headers) + len(moc_sources) > 0 and not self.moc.found():

@ -24,14 +24,14 @@ from . import ModuleReturnValue
class Qt5Module(ExtensionModule): class Qt5Module(ExtensionModule):
tools_detected = False tools_detected = False
def _detect_tools(self, env): def _detect_tools(self, env, method):
if self.tools_detected: if self.tools_detected:
return return
mlog.log('Detecting Qt5 tools') mlog.log('Detecting Qt5 tools')
# FIXME: We currently require Qt5 to exist while importing the module. # FIXME: We currently require Qt5 to exist while importing the module.
# We should make it gracefully degrade and not create any targets if # We should make it gracefully degrade and not create any targets if
# the import is marked as 'optional' (not implemented yet) # the import is marked as 'optional' (not implemented yet)
kwargs = {'required': 'true', 'modules': 'Core', 'silent': 'true'} kwargs = {'required': 'true', 'modules': 'Core', 'silent': 'true', 'method': method}
qt5 = Qt5Dependency(env, kwargs) qt5 = Qt5Dependency(env, kwargs)
# Get all tools and then make sure that they are the right version # Get all tools and then make sure that they are the right version
self.moc, self.uic, self.rcc = qt5.compilers_detect() self.moc, self.uic, self.rcc = qt5.compilers_detect()
@ -119,7 +119,8 @@ class Qt5Module(ExtensionModule):
if not isinstance(sources, list): if not isinstance(sources, list):
sources = [sources] sources = [sources]
sources += args[1:] sources += args[1:]
self._detect_tools(state.environment) method = kwargs.get('method', 'auto')
self._detect_tools(state.environment, method)
err_msg = "{0} sources specified and couldn't find {1}, " \ err_msg = "{0} sources specified and couldn't find {1}, " \
"please check your qt5 installation" "please check your qt5 installation"
if len(moc_headers) + len(moc_sources) > 0 and not self.moc.found(): if len(moc_headers) + len(moc_sources) > 0 and not self.moc.found():

@ -1121,7 +1121,7 @@ class LinuxlikeTests(BasePlatformTests):
if qt4 != 0 or qt5 != 0: if qt4 != 0 or qt5 != 0:
raise unittest.SkipTest('Qt not found with pkg-config') raise unittest.SkipTest('Qt not found with pkg-config')
testdir = os.path.join(self.framework_test_dir, '4 qt') testdir = os.path.join(self.framework_test_dir, '4 qt')
self.init(testdir) self.init(testdir, ['-Dmethod=pkgconfig'])
# Confirm that the dependency was found with qmake # Confirm that the dependency was found with qmake
msg = 'Qt4 native `pkg-config` dependency (modules: Core, Gui) found: YES\n' msg = 'Qt4 native `pkg-config` dependency (modules: Core, Gui) found: YES\n'
msg2 = 'Qt5 native `pkg-config` dependency (modules: Core, Gui) found: YES\n' msg2 = 'Qt5 native `pkg-config` dependency (modules: Core, Gui) found: YES\n'
@ -1144,10 +1144,8 @@ class LinuxlikeTests(BasePlatformTests):
if 'Qt version 5' not in output and 'qt5' not in output: if 'Qt version 5' not in output and 'qt5' not in output:
raise unittest.SkipTest('Qmake found, but it is not for Qt 5.') raise unittest.SkipTest('Qmake found, but it is not for Qt 5.')
# Disable pkg-config codepath and force searching with qmake/qmake-qt5 # Disable pkg-config codepath and force searching with qmake/qmake-qt5
os.environ['PKG_CONFIG_LIBDIR'] = self.builddir
os.environ['PKG_CONFIG_PATH'] = self.builddir
testdir = os.path.join(self.framework_test_dir, '4 qt') testdir = os.path.join(self.framework_test_dir, '4 qt')
self.init(testdir) self.init(testdir, ['-Dmethod=qmake'])
# Confirm that the dependency was found with qmake # Confirm that the dependency was found with qmake
msg = 'Qt5 native `qmake-qt5` dependency (modules: Core) found: YES\n' msg = 'Qt5 native `qmake-qt5` dependency (modules: Core) found: YES\n'
msg2 = 'Qt5 native `qmake` dependency (modules: Core) found: YES\n' msg2 = 'Qt5 native `qmake` dependency (modules: Core) found: YES\n'

@ -9,17 +9,17 @@ foreach qt : ['qt4', 'qt5']
qt_modules += qt5_modules qt_modules += qt5_modules
endif endif
# Test that invalid modules are indeed not found # Test that invalid modules are indeed not found
fakeqtdep = dependency(qt, modules : ['DefinitelyNotFound'], required : false) fakeqtdep = dependency(qt, modules : ['DefinitelyNotFound'], required : false, method : get_option('method'))
if fakeqtdep.found() if fakeqtdep.found()
error('Invalid qt dep incorrectly found!') error('Invalid qt dep incorrectly found!')
endif endif
# Test that partially-invalid modules are indeed not found # Test that partially-invalid modules are indeed not found
fakeqtdep = dependency(qt, modules : ['Core', 'DefinitelyNotFound'], required : false) fakeqtdep = dependency(qt, modules : ['Core', 'DefinitelyNotFound'], required : false, method : get_option('method'))
if fakeqtdep.found() if fakeqtdep.found()
error('Invalid qt dep incorrectly found!') error('Invalid qt dep incorrectly found!')
endif endif
# If qt4 modules are found, test that. qt5 is required. # If qt4 modules are found, test that. qt5 is required.
qtdep = dependency(qt, modules : qt_modules, required : qt == 'qt5') qtdep = dependency(qt, modules : qt_modules, required : qt == 'qt5', method : get_option('method'))
if qtdep.found() if qtdep.found()
qtmodule = import(qt) qtmodule = import(qt)
@ -30,10 +30,11 @@ foreach qt : ['qt4', 'qt5']
moc_headers : ['mainWindow.h'], # These need to be fed through the moc tool before use. moc_headers : ['mainWindow.h'], # These need to be fed through the moc tool before use.
ui_files : 'mainWindow.ui', # XML files that need to be compiled with the uic tol. ui_files : 'mainWindow.ui', # XML files that need to be compiled with the uic tol.
qresources : ['stuff.qrc', 'stuff2.qrc'], # Resource file for rcc compiler. qresources : ['stuff.qrc', 'stuff2.qrc'], # Resource file for rcc compiler.
method : get_option('method')
) )
# Test that setting a unique name with a positional argument works # Test that setting a unique name with a positional argument works
qtmodule.preprocess(qt + 'teststuff', qresources : ['stuff.qrc']) qtmodule.preprocess(qt + 'teststuff', qresources : ['stuff.qrc'], method : get_option('method'))
qexe = executable(qt + 'app', qexe = executable(qt + 'app',
sources : ['main.cpp', 'mainWindow.cpp', # Sources that don't need preprocessing. sources : ['main.cpp', 'mainWindow.cpp', # Sources that don't need preprocessing.
@ -43,7 +44,7 @@ foreach qt : ['qt4', 'qt5']
# We need a console test application because some test environments # We need a console test application because some test environments
# do not have an X server. # do not have an X server.
qtcore = dependency(qt, modules : 'Core') qtcore = dependency(qt, modules : 'Core', method : get_option('method'))
qtcoreapp = executable(qt + 'core', 'q5core.cpp', qtcoreapp = executable(qt + 'core', 'q5core.cpp',
dependencies : qtcore) dependencies : qtcore)
@ -55,7 +56,8 @@ foreach qt : ['qt4', 'qt5']
# files from sources. # files from sources.
manpreprocessed = qtmodule.preprocess( manpreprocessed = qtmodule.preprocess(
moc_sources : 'manualinclude.cpp', moc_sources : 'manualinclude.cpp',
moc_headers : 'manualinclude.h') moc_headers : 'manualinclude.h',
method : get_option('method'))
qtmaninclude = executable(qt + 'maninclude', qtmaninclude = executable(qt + 'maninclude',
sources : ['manualinclude.cpp', manpreprocessed], sources : ['manualinclude.cpp', manpreprocessed],

@ -0,0 +1 @@
option('method', type : 'string', value : 'auto', description : 'The method to use to find Qt')
Loading…
Cancel
Save