Add thread flags to compilers and use them on dependencies that require threads. Fixes #31.

pull/34/head
Jussi Pakkanen 10 years ago
parent 4293a2ac65
commit 2107be2a78
  1. 13
      compilers.py
  2. 11
      dependencies.py
  3. 7
      ninjabackend.py
  4. 6
      test cases/frameworks/1 boost/linkexe.cc

@ -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)

@ -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)

@ -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)):

@ -1,7 +1,11 @@
#include<boost/thread.hpp>
boost::recursive_mutex m;
struct callable {
void operator()() {};
void operator()() {
boost::recursive_mutex::scoped_lock l(m);
};
};
int main(int argc, char **argv) {

Loading…
Cancel
Save