Skip to content

Commit

Permalink
Fix Objective C/C++.
Browse files Browse the repository at this point in the history
  • Loading branch information
jpakkane committed Aug 21, 2024
1 parent 9734ea3 commit 1b276ab
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 10 deletions.
3 changes: 1 addition & 2 deletions mesonbuild/backend/ninjabackend.py
Original file line number Diff line number Diff line change
Expand Up @@ -2800,11 +2800,10 @@ def get_link_debugfile_args(self, linker: T.Union[Compiler, StaticLinker], targe
return []

def generate_llvm_ir_compile(self, target, src: FileOrString):
base_proxy = target.get_options()
compiler = get_compiler_for_source(target.compilers.values(), src)
commands = compiler.compiler_args()
# Compiler args for compiling this target
commands += compilers.get_base_compile_args(base_proxy, compiler, self.environment)
commands += compilers.get_base_compile_args(target, compiler, self.environment)
if isinstance(src, File):
if src.is_built:
src_filename = os.path.join(src.subdir, src.fname)
Expand Down
3 changes: 2 additions & 1 deletion mesonbuild/compilers/c.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import typing as T

from .. import options
from ..options import OptionKey
from .. import mlog
from ..mesonlib import MesonException, version_compare
from .c_function_attributes import C_FUNC_ATTRIBUTES
Expand Down Expand Up @@ -322,7 +323,7 @@ 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')
key = OptionKey('c_std', machine=self.for_machine)
if target:
std = env.coredata.get_option_for_target(target, key)
else:
Expand Down
2 changes: 1 addition & 1 deletion mesonbuild/compilers/compilers.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ def get_base_link_args(target: 'BuildTarget',
bitcode = option_enabled(linker.base_options, target, env, 'b_bitcode')
# Shared modules cannot be built with bitcode_bundle because
# -bitcode_bundle is incompatible with -undefined and -bundle
if bitcode and not is_shared_module:
if bitcode and not target.typename == 'shared module':
args.extend(linker.bitcode_args())
elif as_needed:
# -Wl,-dead_strip_dylibs is incompatible with bitcode
Expand Down
2 changes: 1 addition & 1 deletion mesonbuild/compilers/cpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ def get_option_compile_args(self, target: 'BuildTarget', env: 'Environment', sub
if std != 'none':
args.append(self._find_best_cpp_std(std))

non_msvc_eh_options(env.determine_option_value(key.evolve('eh'), target, subproject), args)
non_msvc_eh_options(eh, args)

if debugstl:
args.append('-D_GLIBCXX_DEBUG=1')
Expand Down
8 changes: 6 additions & 2 deletions mesonbuild/compilers/objc.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,13 @@ def get_options(self) -> 'coredata.MutableKeyedOptionDictType':
'none'),
)

def get_option_compile_args(self, options: 'coredata.KeyedOptionDictType') -> T.List[str]:
def get_option_compile_args(self, target: 'BuildTarget', env: 'Environment', subproject=None) -> T.List[str]:
args = []
std = options.get_value(OptionKey('c_std', machine=self.for_machine))
key = OptionKey('c_std', machine=self.for_machine)
if target:
std = env.coredata.get_option_for_target(target, key)
else:
std = env.coredata.get_option_for_subproject(key, subproject)
if std != 'none':
args.append('-std=' + std)
return args
Expand Down
8 changes: 6 additions & 2 deletions mesonbuild/compilers/objcpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,13 @@ def get_options(self) -> coredata.MutableKeyedOptionDictType:
'none'),
)

def get_option_compile_args(self, options: 'coredata.KeyedOptionDictType') -> T.List[str]:
def get_option_compile_args(self, target: 'BuildTarget', env: 'Environment', subproject=None) -> T.List[str]:
args = []
std = options.get_value(OptionKey('cpp_std', machine=self.for_machine))
key = OptionKey('cpp_std', machine=self.for_machine)
if target:
std = env.coredata.get_option_for_target(target, key)
else:
std = env.coredata.get_option_for_subproject(key, subproject)
if std != 'none':
args.append('-std=' + std)
return args
Expand Down
9 changes: 8 additions & 1 deletion mesonbuild/coredata.py
Original file line number Diff line number Diff line change
Expand Up @@ -728,8 +728,15 @@ def add_compiler_options(self, c_options: MutableKeyedOptionDictType, lang: str,
# FIXME, add augment
#self.optstore[k] = o # override compiler option on reconfigure
pass

comp_key = OptionKey(f'{k.name}', None, for_machine)
self.optstore.add_compiler_option(lang, comp_key, o)
if lang == 'objc' and k.name == 'c_std':
# For objective C, always fall back to c_std.
self.optstore.add_compiler_option('c', comp_key, o)
elif lang == 'objcpp' and k.name == 'cpp_std':
self.optstore.add_compiler_option('cpp', comp_key, o)
else:
self.optstore.add_compiler_option(lang, comp_key, o)

# if subproject:
# sk = k.evolve(subproject=subproject)
Expand Down

0 comments on commit 1b276ab

Please sign in to comment.