From 2107be2a7803fb25421fb886df66006b93448667 Mon Sep 17 00:00:00 2001 From: Jussi Pakkanen Date: Fri, 30 Jan 2015 19:35:58 +0200 Subject: [PATCH] Add thread flags to compilers and use them on dependencies that require threads. Fixes #31. --- compilers.py | 13 +++++++++++++ dependencies.py | 11 +++++++++-- ninjabackend.py | 7 +++++++ test cases/frameworks/1 boost/linkexe.cc | 6 +++++- 4 files changed, 34 insertions(+), 3 deletions(-) diff --git a/compilers.py b/compilers.py index 7100113bb..75618830b 100644 --- a/compilers.py +++ b/compilers.py @@ -395,6 +395,12 @@ void bar() { ''' return self.compiles(templ % (prefix, typename, membername)) + def thread_flags(self): + return ['-pthread'] + + def thread_link_flags(self): + return ['-pthread'] + class CPPCompiler(CCompiler): def __init__(self, exelist, version, is_cross, exe_wrap): CCompiler.__init__(self, exelist, version, is_cross, exe_wrap) @@ -943,6 +949,13 @@ class VisualStudioCCompiler(CCompiler): def build_rpath_args(self, build_dir, rpath_paths, install_rpath): return [] + # FIXME, no idea what these should be. + def thread_flags(self): + return [] + + def thread_link_flags(self): + return [] + class VisualStudioCPPCompiler(VisualStudioCCompiler): def __init__(self, exelist, version, is_cross, exe_wrap): VisualStudioCCompiler.__init__(self, exelist, version, is_cross, exe_wrap) diff --git a/dependencies.py b/dependencies.py index 4720a73e4..2e48ac673 100644 --- a/dependencies.py +++ b/dependencies.py @@ -66,6 +66,9 @@ class Dependency(): def get_exe_args(self): return [] + def need_threads(self): + return False + class PkgConfigDependency(Dependency): pkgconfig_found = None @@ -395,6 +398,9 @@ class BoostDependency(Dependency): def get_sources(self): return [] + def need_threads(self): + return 'thread' in self.requested_modules + class GTestDependency(Dependency): def __init__(self, kwargs): Dependency.__init__(self) @@ -436,8 +442,6 @@ class GTestDependency(Dependency): else: mlog.log('Dependency GTest found:', mlog.red('NO')) self.is_found = False - if self.is_found: - self.link_args.append('-lpthread') return self.is_found def get_compile_args(self): @@ -454,6 +458,9 @@ class GTestDependency(Dependency): def get_sources(self): return self.sources + def need_threads(self): + return True + class GMockDependency(Dependency): def __init__(self, kwargs): Dependency.__init__(self) diff --git a/ninjabackend.py b/ninjabackend.py index df51b2801..ad4321769 100644 --- a/ninjabackend.py +++ b/ninjabackend.py @@ -1100,6 +1100,10 @@ rule FORTRAN_DEP_HACK compiler = self.get_compiler_for_source(src) commands = self.generate_basic_compiler_args(target, compiler) commands += compiler.get_include_args(self.get_target_private_dir(target)) + for d in target.external_deps: + if d.need_threads(): + commands += compiler.thread_flags() + break if isinstance(src, RawFilename): rel_src = src.fname elif is_generated: @@ -1284,6 +1288,9 @@ rule FORTRAN_DEP_HACK else: dependencies = target.get_dependencies() commands += self.build_target_link_arguments(linker, dependencies) + for d in target.external_deps: + if d.need_threads(): + commands += linker.thread_link_flags() commands += target.link_args # External deps must be last because target link libraries may depend on them. if not(isinstance(target, build.StaticLibrary)): diff --git a/test cases/frameworks/1 boost/linkexe.cc b/test cases/frameworks/1 boost/linkexe.cc index e9f4047a1..240c7c1ec 100644 --- a/test cases/frameworks/1 boost/linkexe.cc +++ b/test cases/frameworks/1 boost/linkexe.cc @@ -1,7 +1,11 @@ #include +boost::recursive_mutex m; + struct callable { - void operator()() {}; + void operator()() { + boost::recursive_mutex::scoped_lock l(m); + }; }; int main(int argc, char **argv) {