objcpp.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 .cpp import CPPCompiler
  14. from .compilers import ClangCompiler, GnuCompiler
  15. class ObjCPPCompiler(CPPCompiler):
  16. def __init__(self, exelist, version, is_cross, exe_wrap):
  17. self.language = 'objcpp'
  18. CPPCompiler.__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, 'sanitycheckobjcpp.mm')
  24. binary_name = os.path.join(work_dir, 'sanitycheckobjcpp')
  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. 'class MyClass;'
  31. 'int main(int argc, char **argv) { return 0; }\n')
  32. pc = subprocess.Popen(self.exelist + extra_flags + [source_name, '-o', binary_name])
  33. pc.wait()
  34. if pc.returncode != 0:
  35. raise EnvironmentException('ObjC++ compiler %s can not compile programs.' % self.name_string())
  36. if self.is_cross:
  37. # Can't check if the binaries run so we have to assume they do
  38. return
  39. pe = subprocess.Popen(binary_name)
  40. pe.wait()
  41. if pe.returncode != 0:
  42. raise EnvironmentException('Executables created by ObjC++ compiler %s are not runnable.' % self.name_string())
  43. class GnuObjCPPCompiler(GnuCompiler, ObjCPPCompiler):
  44. def __init__(self, exelist, version, gcc_type, is_cross, exe_wrapper=None, defines=None):
  45. ObjCPPCompiler.__init__(self, exelist, version, is_cross, exe_wrapper)
  46. GnuCompiler.__init__(self, gcc_type, defines)
  47. default_warn_args = ['-Wall', '-Winvalid-pch', '-Wnon-virtual-dtor']
  48. self.warn_args = {'1': default_warn_args,
  49. '2': default_warn_args + ['-Wextra'],
  50. '3': default_warn_args + ['-Wextra', '-Wpedantic']}
  51. class ClangObjCPPCompiler(ClangCompiler, GnuObjCPPCompiler):
  52. def __init__(self, exelist, version, cltype, is_cross, exe_wrapper=None):
  53. GnuObjCPPCompiler.__init__(self, exelist, version, cltype, is_cross, exe_wrapper)
  54. ClangCompiler.__init__(self, cltype)
  55. self.base_options = ['b_pch', 'b_lto', 'b_pgo', 'b_sanitize', 'b_coverage']