Can set global flags.

pull/15/head
Jussi Pakkanen 12 years ago
parent 2af66e5478
commit b97f43b9b7
  1. 4
      build.py
  2. 5
      environment.py
  3. 14
      interpreter.py
  4. 1
      shellgenerator.py
  5. 11
      test cases/23 global arg/builder.txt
  6. 7
      test cases/23 global arg/prog.c
  7. 5
      test cases/23 global arg/prog.cc

@ -24,6 +24,7 @@ class Build:
self.project = None
self.targets = {}
self.compilers = []
self.global_args = {}
self.tests = []
self.headers = []
self.man = []
@ -51,3 +52,6 @@ class Build:
def get_configure_files(self):
return self.configure_files
def get_global_flags(self, compiler):
return self.global_args.get(compiler.get_language(), [])

@ -30,6 +30,10 @@ class CCompiler():
self.exelist = exelist
else:
raise TypeError('Unknown argument to CCompiler')
self.language = 'c'
def get_language(self):
return self.language
def get_exelist(self):
return self.exelist
@ -82,6 +86,7 @@ class CCompiler():
class CXXCompiler(CCompiler):
def __init__(self, exelist):
CCompiler.__init__(self, exelist)
self.language = 'c++'
def can_compile(self, filename):
suffix = filename.split('.')[-1]

@ -262,6 +262,7 @@ class Interpreter():
'data' : self.func_data,
'configure_file' : self.func_configure_file,
'include_directories' : self.func_include_directories,
'add_global_arguments' : self.func_add_global_arguments,
}
def get_variables(self):
@ -428,6 +429,19 @@ class Interpreter():
i = IncludeDirs(self.subdir, args)
return i
def func_add_global_arguments(self, node, args):
for a in args:
if not isinstance(a, str):
raise InvalidArguments('Line %d: Argument %s is not a string.' % (node.lineno(), str(a)))
if len(self.build.get_targets()) > 0:
raise InvalidCode('Line %d: global flags can not be set once any build target is defined.' % node.lineno())
lang = args[0].lower()
switches = args[1:]
if lang in self.build.global_args:
self.build.global_args[lang] += switches
else:
self.build.global_args[lang] = switches
def flatten(self, args):
result = []
for a in args:

@ -209,6 +209,7 @@ echo Run compile.sh before this or bad things will happen.
def generate_basic_compiler_arguments(self, target, compiler):
commands = []
commands += compiler.get_exelist()
commands += self.build.get_global_flags(compiler)
commands += compiler.get_debug_flags()
commands += compiler.get_std_warn_flags()
commands += compiler.get_compile_only_flags()

@ -0,0 +1,11 @@
project('global arg test', 'c++', 'c')
add_global_arguments('c', '-Werror', '-DMYTHING')
add_global_arguments('c++', '-Werror', '-std=c++11')
exe1 = executable('prog', 'prog.c')
exe2 = executable('prog2', 'prog.cc')
add_test('prog1', exe1)
add_test('prog2', exe2)

@ -0,0 +1,7 @@
#ifndef MYTHING
#error "Global argument not set"
#endif
int main(int argc, char **argv) {
return 0;
}

@ -0,0 +1,5 @@
#include<unordered_map>
int main(int argc, char **argv) {
return 0;
}
Loading…
Cancel
Save