aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/markdown/snippets/objcversion.md6
-rw-r--r--mesonbuild/compilers/objc.py20
-rw-r--r--mesonbuild/compilers/objcpp.py21
-rwxr-xr-xrun_unittests.py15
-rw-r--r--test cases/objc/1 simple/meson.build2
-rw-r--r--test cases/objcpp/1 simple/meson.build2
6 files changed, 62 insertions, 4 deletions
diff --git a/docs/markdown/snippets/objcversion.md b/docs/markdown/snippets/objcversion.md
new file mode 100644
index 0000000..9825c80
--- /dev/null
+++ b/docs/markdown/snippets/objcversion.md
@@ -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.
diff --git a/mesonbuild/compilers/objc.py b/mesonbuild/compilers/objc.py
index 32f17ff..ec8d290 100644
--- a/mesonbuild/compilers/objc.py
+++ b/mesonbuild/compilers/objc.py
@@ -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):
diff --git a/mesonbuild/compilers/objcpp.py b/mesonbuild/compilers/objcpp.py
index 003da54..ad909f1 100644
--- a/mesonbuild/compilers/objcpp.py
+++ b/mesonbuild/compilers/objcpp.py
@@ -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):
diff --git a/run_unittests.py b/run_unittests.py
index 89b00f6..256a408 100755
--- a/run_unittests.py
+++ b/run_unittests.py
@@ -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):
diff --git a/test cases/objc/1 simple/meson.build b/test cases/objc/1 simple/meson.build
index b004e6b..f9d5c14 100644
--- a/test cases/objc/1 simple/meson.build
+++ b/test cases/objc/1 simple/meson.build
@@ -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)
diff --git a/test cases/objcpp/1 simple/meson.build b/test cases/objcpp/1 simple/meson.build
index 7d91884..c9a5c84 100644
--- a/test cases/objcpp/1 simple/meson.build
+++ b/test cases/objcpp/1 simple/meson.build
@@ -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)