Make objective C use C standard version. Closes #5495.

pull/8760/head
Jussi Pakkanen 4 years ago
parent 8f12102549
commit c54dd63547
  1. 6
      docs/markdown/snippets/objcversion.md
  2. 20
      mesonbuild/compilers/objc.py
  3. 21
      mesonbuild/compilers/objcpp.py
  4. 15
      run_unittests.py
  5. 2
      test cases/objc/1 simple/meson.build
  6. 2
      test cases/objcpp/1 simple/meson.build

@ -0,0 +1,6 @@
## Objective C/C++ standard versions
Objective C and C++ compilations will from now on use the language
versions set in `c_std` and `cpp_std`, respectively. It is not
possible to set the language version separately for Objective C and
plain C.

@ -14,7 +14,8 @@
import typing as T
from ..mesonlib import MachineChoice
from .. import coredata
from ..mesonlib import MachineChoice, OptionKey
from .compilers import Compiler
from .mixins.clike import CLikeCompiler
@ -84,6 +85,23 @@ class ClangObjCCompiler(ClangCompiler, ObjCCompiler):
'2': default_warn_args + ['-Wextra'],
'3': default_warn_args + ['-Wextra', '-Wpedantic']}
def get_options(self) -> 'coredata.KeyedOptionDictType':
opts = super().get_options()
opts.update({
OptionKey('std', machine=self.for_machine, lang='c'): coredata.UserComboOption(
'C language standard to use',
['none', 'c89', 'c99', 'c11', 'c17'],
'none',
)
})
return opts
def get_option_compile_args(self, options: 'coredata.KeyedOptionDictType') -> T.List[str]:
args = []
std = options[OptionKey('std', machine=self.for_machine, lang='c')]
if std.value != 'none':
args.append('-std=' + std.value)
return args
class AppleClangObjCCompiler(ClangObjCCompiler):

@ -14,7 +14,8 @@
import typing as T
from ..mesonlib import MachineChoice
from .. import coredata
from ..mesonlib import MachineChoice, OptionKey
from .mixins.clike import CLikeCompiler
from .compilers import Compiler
@ -85,6 +86,24 @@ class ClangObjCPPCompiler(ClangCompiler, ObjCPPCompiler):
'3': default_warn_args + ['-Wextra', '-Wpedantic']}
def get_options(self) -> 'coredata.KeyedOptionDictType':
opts = super().get_options()
opts.update({
OptionKey('std', machine=self.for_machine, lang='cpp'): coredata.UserComboOption(
'C++ language standard to use',
['none', 'c++98', 'c++11', 'c++14', 'c++17'],
'none',
)
})
return opts
def get_option_compile_args(self, options: 'coredata.KeyedOptionDictType') -> T.List[str]:
args = []
std = options[OptionKey('std', machine=self.for_machine, lang='cpp')]
if std.value != 'none':
args.append('-std=' + std.value)
return args
class AppleClangObjCPPCompiler(ClangObjCPPCompiler):

@ -1723,6 +1723,9 @@ class BasePlatformTests(unittest.TestCase):
self.unit_test_dir = os.path.join(src_root, 'test cases/unit')
self.rewrite_test_dir = os.path.join(src_root, 'test cases/rewrite')
self.linuxlike_test_dir = os.path.join(src_root, 'test cases/linuxlike')
self.objc_test_dir = os.path.join(src_root, 'test cases/objc')
self.objcpp_test_dir = os.path.join(src_root, 'test cases/objcpp')
# Misc stuff
self.orig_env = os.environ.copy()
if self.backend is Backend.ninja:
@ -6450,6 +6453,18 @@ class DarwinTests(BasePlatformTests):
env = {'CFLAGS': '-L/tmp -L /var/tmp -headerpad_max_install_names -Wl,-export_dynamic -framework Foundation'}
self.init(testdir, override_envvars=env)
def test_objc_versions(self):
# Objective-C always uses the C standard version.
# Objecttive-C++ always uses the C++ standard version.
# This is what most people seem to want and in addition
# it is the only setup supported by Xcode.
testdir = os.path.join(self.objc_test_dir, '1 simple')
self.init(testdir)
self.assertIn('-std=c99', self.get_compdb()[0]['command'])
self.wipe()
testdir = os.path.join(self.objcpp_test_dir, '1 simple')
self.init(testdir)
self.assertIn('-std=c++14', self.get_compdb()[0]['command'])
@unittest.skipUnless(not is_windows(), "requires something Unix-like")
class LinuxlikeTests(BasePlatformTests):

@ -1,4 +1,4 @@
project('objective c', 'objc')
project('objective c', 'objc', default_options: ['c_std=c99'])
exe = executable('prog', 'prog.m')
test('objctest', exe)

@ -1,4 +1,4 @@
project('Objective C++', 'objcpp')
project('Objective C++', 'objcpp', default_options: 'cpp_std=c++14')
exe = executable('objcppprog', 'prog.mm')
test('objcpp', exe)

Loading…
Cancel
Save