diff --git a/mesonbuild/backend/backends.py b/mesonbuild/backend/backends.py index 04255dce6..119c1c2b9 100644 --- a/mesonbuild/backend/backends.py +++ b/mesonbuild/backend/backends.py @@ -643,8 +643,6 @@ class Backend: commands += dep.get_exe_args(compiler) # For 'automagic' deps: Boost and GTest. Also dependency('threads'). # pkg-config puts the thread flags itself via `Cflags:` - if dep.need_threads(): - commands += compiler.thread_flags(self.environment) # Fortran requires extra include directives. if compiler.language == 'fortran': for lt in target.link_targets: diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py index 64ea5a65c..a3b9ce8b2 100644 --- a/mesonbuild/backend/ninjabackend.py +++ b/mesonbuild/backend/ninjabackend.py @@ -2511,7 +2511,6 @@ rule FORTRAN_DEP_HACK%s if not isinstance(target, build.StaticLibrary): # For 'automagic' deps: Boost and GTest. Also dependency('threads'). # pkg-config puts the thread flags itself via `Cflags:` - need_threads = False commands += target.link_args # External deps must be last because target link libraries may depend on them. @@ -2519,14 +2518,10 @@ rule FORTRAN_DEP_HACK%s # Extend without reordering or de-dup to preserve `-L -l` sets # https://github.com/mesonbuild/meson/issues/1718 commands.extend_preserving_lflags(dep.get_link_args()) - need_threads |= dep.need_threads() for d in target.get_dependencies(): if isinstance(d, build.StaticLibrary): for dep in d.get_external_deps(): - need_threads |= dep.need_threads() commands.extend_preserving_lflags(dep.get_link_args()) - if need_threads: - commands += linker.thread_link_flags(self.environment) # Add link args specific to this BuildTarget type that must not be overridden by dependencies commands += self.get_target_type_link_args_post_dependencies(target, linker) diff --git a/mesonbuild/build.py b/mesonbuild/build.py index bcd1754e6..020c47b58 100644 --- a/mesonbuild/build.py +++ b/mesonbuild/build.py @@ -1035,6 +1035,7 @@ This will become a hard error in a future Meson release.''') if dep not in self.external_deps: self.external_deps.append(dep) self.process_sourcelist(dep.get_sources()) + self.add_deps(dep.ext_deps) elif isinstance(dep, BuildTarget): raise InvalidArguments('''Tried to use a build target as a dependency. You probably should put it in link_with instead.''') diff --git a/mesonbuild/compilers/c.py b/mesonbuild/compilers/c.py index bcf8243b9..0a6e3b3a6 100644 --- a/mesonbuild/compilers/c.py +++ b/mesonbuild/compilers/c.py @@ -433,13 +433,9 @@ class CCompiler(Compiler): for d in dependencies: # Add compile flags needed by dependencies args += d.get_compile_args() - if d.need_threads(): - args += self.thread_flags(env) if mode == 'link': # Add link flags needed to find dependencies args += d.get_link_args() - if d.need_threads(): - args += self.thread_link_flags(env) args += self._get_basic_compiler_args(env, mode) diff --git a/mesonbuild/dependencies/base.py b/mesonbuild/dependencies/base.py index f74eabb2e..6063fd377 100644 --- a/mesonbuild/dependencies/base.py +++ b/mesonbuild/dependencies/base.py @@ -115,6 +115,7 @@ class Dependency: self.raw_link_args = None self.sources = [] self.methods = self._process_method_kw(kwargs) + self.ext_deps = [] # type: List[Dependency] def __repr__(self): s = '<{0} {1}: {2}>' @@ -152,9 +153,6 @@ class Dependency: def get_exe_args(self, compiler): return [] - def need_threads(self): - return False - def get_pkgconfig_variable(self, variable_name, kwargs): raise DependencyException('{!r} is not a pkgconfig dependency'.format(self.name)) diff --git a/mesonbuild/dependencies/boost.py b/mesonbuild/dependencies/boost.py index 6a8050ddb..62a652a70 100644 --- a/mesonbuild/dependencies/boost.py +++ b/mesonbuild/dependencies/boost.py @@ -22,6 +22,7 @@ from .. import mesonlib from ..environment import detect_cpu_family from .base import (DependencyException, ExternalDependency) +from .misc import ThreadDependency # On windows 3 directory layouts are supported: # * The default layout (versioned) installed: @@ -103,6 +104,8 @@ class BoostDependency(ExternalDependency): self.is_multithreading = threading == "multi" self.requested_modules = self.get_requested(kwargs) + if 'thread' in self.requested_modules: + self.ext_deps.append(ThreadDependency(environment, kwargs)) self.boost_root = None self.boost_roots = [] @@ -488,9 +491,6 @@ class BoostDependency(ExternalDependency): def get_sources(self): return [] - def need_threads(self): - return 'thread' in self.requested_modules - # Generated with boost_names.py BOOST_LIBS = [ diff --git a/mesonbuild/dependencies/dev.py b/mesonbuild/dependencies/dev.py index 57a6a965e..c911cfa56 100644 --- a/mesonbuild/dependencies/dev.py +++ b/mesonbuild/dependencies/dev.py @@ -26,6 +26,7 @@ from .base import ( DependencyException, DependencyMethods, ExternalDependency, PkgConfigDependency, strip_system_libdirs, ConfigToolDependency, ) +from .misc import ThreadDependency def get_shared_library_suffix(environment, native): @@ -45,6 +46,7 @@ class GTestDependency(ExternalDependency): self.main = kwargs.get('main', False) self.src_dirs = ['/usr/src/gtest/src', '/usr/src/googletest/googletest/src'] self.detect() + self.ext_deps.append(ThreadDependency(environment, kwargs)) def detect(self): gtest_detect = self.clib_compiler.find_library("gtest", self.env, []) @@ -83,9 +85,6 @@ class GTestDependency(ExternalDependency): return True return False - def need_threads(self): - return True - def log_info(self): if self.prebuilt: return 'prebuilt' @@ -118,6 +117,7 @@ class GMockDependency(ExternalDependency): def __init__(self, environment, kwargs): super().__init__('gmock', environment, 'cpp', kwargs) self.main = kwargs.get('main', False) + self.ext_deps.append(ThreadDependency(environment, kwargs)) # If we are getting main() from GMock, we definitely # want to avoid linking in main() from GTest @@ -132,10 +132,7 @@ class GMockDependency(ExternalDependency): if not gtest_dep.is_found: self.is_found = False return - - self.compile_args = gtest_dep.compile_args - self.link_args = gtest_dep.link_args - self.sources = gtest_dep.sources + self.ext_deps.append(gtest_dep) # GMock may be a library or just source. # Work with both. @@ -167,9 +164,6 @@ class GMockDependency(ExternalDependency): self.is_found = False - def need_threads(self): - return True - def log_info(self): if self.prebuilt: return 'prebuilt' @@ -262,6 +256,7 @@ class LLVMDependency(ConfigToolDependency): self._set_old_link_args() self.link_args = strip_system_libdirs(environment, self.link_args) self.link_args = self.__fix_bogus_link_args(self.link_args) + self.ext_deps.append(ThreadDependency(environment, kwargs)) @staticmethod def __fix_bogus_link_args(args): @@ -399,9 +394,6 @@ class LLVMDependency(ConfigToolDependency): self.module_details.append(mod + status) - def need_threads(self): - return True - def log_details(self): if self.module_details: return 'modules: ' + ', '.join(self.module_details) diff --git a/mesonbuild/dependencies/misc.py b/mesonbuild/dependencies/misc.py index f4694ca6b..219b3d6ec 100644 --- a/mesonbuild/dependencies/misc.py +++ b/mesonbuild/dependencies/misc.py @@ -388,9 +388,8 @@ class ThreadDependency(ExternalDependency): super().__init__('threads', environment, None, kwargs) self.name = 'threads' self.is_found = True - - def need_threads(self): - return True + self.compile_args = self.clib_compiler.thread_flags(environment) + self.link_args = self.clib_compiler.thread_link_flags(environment) class Python3Dependency(ExternalDependency):