objc.py 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. # Copyright 2012-2017 The Meson development team
  2. # Licensed under the Apache License, Version 2.0 (the "License");
  3. # you may not use this file except in compliance with the License.
  4. # You may obtain a copy of the License at
  5. # http://www.apache.org/licenses/LICENSE-2.0
  6. # Unless required by applicable law or agreed to in writing, software
  7. # distributed under the License is distributed on an "AS IS" BASIS,
  8. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. # See the License for the specific language governing permissions and
  10. # limitations under the License.
  11. import os.path, subprocess
  12. from ..mesonlib import EnvironmentException
  13. from .c import CCompiler
  14. from .compilers import ClangCompiler, GnuCompiler
  15. class ObjCCompiler(CCompiler):
  16. def __init__(self, exelist, version, is_cross, exe_wrap):
  17. self.language = 'objc'
  18. CCompiler.__init__(self, exelist, version, is_cross, exe_wrap)
  19. def get_display_language(self):
  20. return 'Objective-C'
  21. def sanity_check(self, work_dir, environment):
  22. # TODO try to use sanity_check_impl instead of duplicated code
  23. source_name = os.path.join(work_dir, 'sanitycheckobjc.m')
  24. binary_name = os.path.join(work_dir, 'sanitycheckobjc')
  25. extra_flags = self.get_cross_extra_flags(environment, link=False)
  26. if self.is_cross:
  27. extra_flags += self.get_compile_only_args()
  28. with open(source_name, 'w') as ofile:
  29. ofile.write('#import<stdio.h>\n'
  30. 'int main(int argc, char **argv) { return 0; }\n')
  31. pc = subprocess.Popen(self.exelist + extra_flags + [source_name, '-o', binary_name])
  32. pc.wait()
  33. if pc.returncode != 0:
  34. raise EnvironmentException('ObjC compiler %s can not compile programs.' % self.name_string())
  35. if self.is_cross:
  36. # Can't check if the binaries run so we have to assume they do
  37. return
  38. pe = subprocess.Popen(binary_name)
  39. pe.wait()
  40. if pe.returncode != 0:
  41. raise EnvironmentException('Executables created by ObjC compiler %s are not runnable.' % self.name_string())
  42. class GnuObjCCompiler(GnuCompiler, ObjCCompiler):
  43. def __init__(self, exelist, version, gcc_type, is_cross, exe_wrapper=None, defines=None):
  44. ObjCCompiler.__init__(self, exelist, version, is_cross, exe_wrapper)
  45. GnuCompiler.__init__(self, gcc_type, defines)
  46. default_warn_args = ['-Wall', '-Winvalid-pch']
  47. self.warn_args = {'1': default_warn_args,
  48. '2': default_warn_args + ['-Wextra'],
  49. '3': default_warn_args + ['-Wextra', '-Wpedantic']}
  50. class ClangObjCCompiler(ClangCompiler, GnuObjCCompiler):
  51. def __init__(self, exelist, version, cltype, is_cross, exe_wrapper=None):
  52. GnuObjCCompiler.__init__(self, exelist, version, cltype, is_cross, exe_wrapper)
  53. ClangCompiler.__init__(self, cltype)
  54. self.base_options = ['b_pch', 'b_lto', 'b_pgo', 'b_sanitize', 'b_coverage']