diff --git a/mesonbuild/compilers/c.py b/mesonbuild/compilers/c.py index abe3efc6907f..5e6d09ce7a40 100644 --- a/mesonbuild/compilers/c.py +++ b/mesonbuild/compilers/c.py @@ -478,7 +478,10 @@ def get_options(self) -> MutableKeyedOptionDictType: def get_option_link_args(self, target: 'BuildTarget', env: 'Environment', subproject=None) -> T.List[str]: key = self.form_compileropt_key('winlibs') - libs = env.coredata.get_option_for_target(target, key).copy() + if target is not None: + libs = env.coredata.get_option_for_target(target, key).copy() + else: + libs = env.coredata.get_option_for_subproject(key, subproject).copy() assert isinstance(libs, list) for l in libs: assert isinstance(l, str) @@ -514,8 +517,12 @@ def get_options(self) -> 'MutableKeyedOptionDictType': def get_option_compile_args(self, target: 'BuildTarget', env: 'Environment', subproject=None) -> T.List[str]: args = [] - key = self.form_compileropt_key('std') - std = env.coredata.get_option_for_target(target, key) + stdkey = self.form_compileropt_key('std') + if target is not None: + std = env.coredata.get_option_for_target(target, stdkey) + else: + std = env.coredata.get_option_for_subproject(stdkey, subproject) + # As of MVSC 16.8, /std:c11 and /std:c17 are the only valid C standard options. if std in {'c11'}: args.append('/std:c11') diff --git a/mesonbuild/compilers/cpp.py b/mesonbuild/compilers/cpp.py index 1f28b3aa0562..aa88b5e191bf 100644 --- a/mesonbuild/compilers/cpp.py +++ b/mesonbuild/compilers/cpp.py @@ -796,16 +796,18 @@ def _get_options_impl(self, opts: 'MutableKeyedOptionDictType', cpp_stds: T.List def get_option_compile_args(self, target: 'BuildTarget', env: 'Environment', subproject=None) -> T.List[str]: args: T.List[str] = [] - key = self.form_compileropt_key('std') + stdkey = self.form_compileropt_key('std') + ehkey = self.form_compileropt_key('eh') + rttikey = self.form_compileropt_key('rtti') if target is not None: - std = env.coredata.get_option_for_target(target, key) - eh = env.coredata.get_option_for_target(target, key.evolve('eh')) - rtti = env.coredata.get_option_for_target(target, key.evolve('rtti')) + std = env.coredata.get_option_for_target(target, stdkey) + eh = env.coredata.get_option_for_target(target, ehkey) + rtti = env.coredata.get_option_for_target(target, rttikey) else: - std = env.coredata.get_option_for_subproject(key, subprojct) - eh = env.coredata.get_option_for_target(key.evolve('eh'), subproject) - rtti = env.coredata.get_option_for_target(key.evolve('rtti'), subproject) + std = env.coredata.get_option_for_subproject(stdkey, subproject) + eh = env.coredata.get_option_for_subproject(ehkey, subproject) + rtti = env.coredata.get_option_for_subproject(rttikey, subproject) if eh == 'default': args.append('/EHsc') @@ -844,8 +846,11 @@ def get_option_compile_args(self, target: 'BuildTarget', env: 'Environment', sub # which means setting the C++ standard version to C++14, in compilers that support it # (i.e., after VS2015U3) # if one is using anything before that point, one cannot set the standard. - key = self.form_compileropt_key('std') - std = env.coredata.get_option_for_target(target, key) + stdkey = self.form_compileropt_key('std') + if target is not None: + std = env.coredata.get_option_for_target(target, stdkey) + else: + std = env.coredata.get_option_for_subproject(stdkey, subproject) if std in {'vc++11', 'c++11'}: mlog.warning(self.id, 'does not support C++11;', 'attempting best effort; setting the standard to C++14', @@ -884,8 +889,11 @@ def get_options(self) -> 'MutableKeyedOptionDictType': return self._get_options_impl(super().get_options(), cpp_stds) def get_option_compile_args(self, target: 'BuildTarget', env: 'Environment', subproject=None) -> T.List[str]: - key = self.form_compileropt_key('std') - std = env.coredata.get_option_for_target(target, key) + stdkey = self.form_compileropt_key('std') + if target is not None: + std = env.coredata.get_option_for_target(target, stdkey) + else: + std = env.coredata.get_option_for_subproject(stdkey, subproject) if std != 'none' and version_compare(self.version, '<19.00.24210'): mlog.warning('This version of MSVC does not support cpp_std arguments', fatal=False) diff --git a/test cases/common/40 options/meson.build b/test cases/common/40 options/meson.build index b9021cee7c62..ed7668fde36b 100644 --- a/test cases/common/40 options/meson.build +++ b/test cases/common/40 options/meson.build @@ -18,7 +18,7 @@ if get_option('array_opt') != ['one', 'two'] endif # If the default changes, update test cases/unit/13 reconfigure -if get_option('b_lto') != false +if get_option('b_pch') != true error('Incorrect value in base option.') endif