add has_type method
Signed-off-by: Igor Gnatenko <i.gnatenko.brain@gmail.com>
This commit is contained in:
parent
0ba1d545af
commit
46804d4fe6
|
@ -401,6 +401,14 @@ void bar() {
|
|||
'''
|
||||
return self.compiles(templ % (prefix, typename, membername))
|
||||
|
||||
def has_type(self, typename, prefix):
|
||||
templ = '''%s
|
||||
void bar() {
|
||||
sizeof(%s);
|
||||
};
|
||||
'''
|
||||
return self.compiles(templ % (prefix, typename))
|
||||
|
||||
def thread_flags(self):
|
||||
return ['-pthread']
|
||||
|
||||
|
|
|
@ -502,6 +502,7 @@ class CompilerHolder(InterpreterObject):
|
|||
'run' : self.run_method,
|
||||
'has_function' : self.has_function_method,
|
||||
'has_member' : self.has_member_method,
|
||||
'has_type' : self.has_type_method,
|
||||
'alignment' : self.alignment_method,
|
||||
'version' : self.version_method,
|
||||
'cmd_array' : self.cmd_array_method,
|
||||
|
@ -578,6 +579,22 @@ class CompilerHolder(InterpreterObject):
|
|||
mlog.log('Checking for function "', mlog.bold(funcname), '": ', hadtxt, sep='')
|
||||
return had
|
||||
|
||||
def has_type_method(self, args, kwargs):
|
||||
if len(args) != 1:
|
||||
raise InterpreterException('Has_type takes exactly one argument.')
|
||||
check_stringlist(args)
|
||||
typename = args[0]
|
||||
prefix = kwargs.get('prefix', '')
|
||||
if not isinstance(prefix, str):
|
||||
raise InterpreterException('Prefix argument of has_type must be a string.')
|
||||
had = self.compiler.has_type(typename, prefix)
|
||||
if had:
|
||||
hadtxt = mlog.green('YES')
|
||||
else:
|
||||
hadtxt = mlog.red('NO')
|
||||
mlog.log('Checking for type "', mlog.bold(typename), '": ', hadtxt, sep='')
|
||||
return had
|
||||
|
||||
def sizeof_method(self, args, kwargs):
|
||||
if len(args) != 1:
|
||||
raise InterpreterException('Sizeof takes exactly one argument.')
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
project('has type', 'c')
|
||||
|
||||
cc = meson.get_compiler('c')
|
||||
|
||||
if not cc.has_type('time_t', prefix : '#include<time.h>')
|
||||
error('Did not detect type that exists.')
|
||||
endif
|
||||
|
||||
if cc.has_type('no_time_t', prefix : '#include<time.h>')
|
||||
error('Not existing type found.')
|
||||
endif
|
Loading…
Reference in New Issue