gtestdependency: find libraries using the compiler

Use the compiler object to find gtest libraries. Fixes following
cases:
- cross compiling looked in host library paths
- static libgtest was not supported

Change-Id: If42cdf873db38676b99adca60752f652aff097a2
pull/1779/merge
Lars Persson 8 years ago committed by Jussi Pakkanen
parent 18b11489cf
commit a1a4f66e6d
  1. 13
      mesonbuild/dependencies/base.py
  2. 26
      mesonbuild/dependencies/dev.py

@ -639,3 +639,16 @@ def find_external_dependency(name, environment, kwargs):
raise pkg_exc
mlog.log('Dependency', mlog.bold(name), 'found:', mlog.red('NO'))
return pkgdep
def dependency_get_compiler(language, environment, kwargs):
if 'native' in kwargs and environment.is_cross_build():
want_cross = not kwargs['native']
else:
want_cross = environment.is_cross_build()
if want_cross:
compilers = environment.coredata.cross_compilers
else:
compilers = environment.coredata.compilers
return compilers.get(language, None)

@ -22,38 +22,34 @@ import shutil
from .. import mlog
from .. import mesonlib
from ..mesonlib import version_compare, Popen_safe
from .base import Dependency, DependencyException, PkgConfigDependency
from .base import Dependency, DependencyException, PkgConfigDependency, dependency_get_compiler
class GTestDependency(Dependency):
def __init__(self, environment, kwargs):
Dependency.__init__(self, 'gtest', kwargs)
self.env = environment
self.main = kwargs.get('main', False)
self.name = 'gtest'
self.libname = 'libgtest.so'
self.libmain_name = 'libgtest_main.so'
self.include_dir = '/usr/include'
self.src_dirs = ['/usr/src/gtest/src', '/usr/src/googletest/googletest/src']
self.cpp_compiler = dependency_get_compiler('cpp', environment, kwargs)
if self.cpp_compiler is None:
raise DependencyException('Tried to use gtest but a C++ compiler is not defined.')
self.detect()
def found(self):
return self.is_found
def detect(self):
trial_dirs = mesonlib.get_library_dirs()
glib_found = False
gmain_found = False
for d in trial_dirs:
if os.path.isfile(os.path.join(d, self.libname)):
glib_found = True
if os.path.isfile(os.path.join(d, self.libmain_name)):
gmain_found = True
if glib_found and gmain_found:
gtest_detect = self.cpp_compiler.find_library("gtest", self.env, [])
gtest_main_detect = self.cpp_compiler.find_library("gtest_main", self.env, [])
if gtest_detect and gtest_main_detect:
self.is_found = True
self.compile_args = []
self.link_args = ['-lgtest']
self.link_args = gtest_detect
if self.main:
self.link_args.append('-lgtest_main')
self.link_args += gtest_main_detect
self.sources = []
mlog.log('Dependency GTest found:', mlog.green('YES'), '(prebuilt)')
elif self.detect_srcdir():

Loading…
Cancel
Save