@ -19,7 +19,8 @@ from itertools import chain
from pathlib import PurePath
from collections import OrderedDict
from . mesonlib import (
MesonException , default_libdir , default_libexecdir , default_prefix
MesonException , MachineChoice , PerMachine ,
default_libdir , default_libexecdir , default_prefix
)
from . wrap import WrapMode
import ast
@ -261,9 +262,9 @@ class CoreData:
self . init_builtins ( )
self . backend_options = { }
self . user_options = { }
self . compiler_options = { }
self . compiler_options = PerMachine ( { } , { } , { } )
self . base_options = { }
self . external_preprocess_args = { } # CPPFLAGS only
self . external_preprocess_args = PerMachine ( { } , { } , { } ) # CPPFLAGS only
self . cross_file = self . __load_cross_file ( options . cross_file )
self . compilers = OrderedDict ( )
self . cross_compilers = OrderedDict ( )
@ -457,16 +458,18 @@ class CoreData:
mode = ' custom '
self . builtins [ ' buildtype ' ] . set_value ( mode )
def get_all_compiler_options ( self ) :
# TODO think about cross and command-line interface. (Only .build is mentioned here.)
yield self . compiler_options . build
def _get_all_nonbuiltin_options ( self ) :
yield self . backend_options
yield self . user_options
yield self . compiler_options
yield from self . get_all_ compiler_options( )
yield self . base_options
def get_all_options ( self ) :
return chain (
iter ( [ self . builtins ] ) ,
self . _get_all_nonbuiltin_options ( ) )
return chain ( [ self . builtins ] , self . _get_all_nonbuiltin_options ( ) )
def validate_option_value ( self , option_name , override_value ) :
for opts in self . get_all_options ( ) :
@ -475,14 +478,14 @@ class CoreData:
return opt . validate_value ( override_value )
raise MesonException ( ' Tried to validate unknown option %s . ' % option_name )
def get_external_args ( self , lang ) :
return self . compiler_options [ lang + ' _args ' ] . value
def get_external_args ( self , for_machine : MachineChoice , lang ) :
return self . compiler_options [ for_machine ] [ lang + ' _args ' ] . value
def get_external_link_args ( self , lang ) :
return self . compiler_options [ lang + ' _link_args ' ] . value
def get_external_link_args ( self , for_machine : MachineChoice , lang ) :
return self . compiler_options [ for_machine ] [ lang + ' _link_args ' ] . value
def get_external_preprocess_args ( self , lang ) :
return self . external_preprocess_args [ lang ]
def get_external_preprocess_args ( self , for_machine : MachineChoice , lang ) :
return self . external_preprocess_args [ for_machine ] [ lang ]
def merge_user_options ( self , options ) :
for ( name , value ) in options . items ( ) :
@ -493,7 +496,7 @@ class CoreData:
if type ( oldval ) != type ( value ) :
self . user_options [ name ] = value
def set_options ( self , options , subproject = ' ' ) :
def set_options ( self , options , subproject = ' ' , warn_unknown = True ) :
# Set prefix first because it's needed to sanitize other options
prefix = self . builtins [ ' prefix ' ] . value
if ' prefix ' in options :
@ -517,8 +520,7 @@ class CoreData:
break
else :
unknown_options . append ( k )
if unknown_options :
if unknown_options and warn_unknown :
unknown_options = ' , ' . join ( sorted ( unknown_options ) )
sub = ' In subproject {} : ' . format ( subproject ) if subproject else ' '
mlog . warning ( ' {} Unknown options: " {} " ' . format ( sub , unknown_options ) )
@ -553,36 +555,54 @@ class CoreData:
self . set_options ( options , subproject )
def process_new_compilers ( self , lang : str , comp , cross_comp , cmd_line_options ) :
def process_new_compilers ( self , lang : str , comp , cross_comp , env ) :
from . import compilers
self . compilers [ lang ] = comp
# Native compiler always exist so always add its options.
new_options = comp . get_options ( )
if cross_comp is not None :
self . cross_compilers [ lang ] = cross_comp
new_options . update ( cross_comp . get_options ( ) )
# Native compiler always exist so always add its options.
new_options_for_build = comp . get_options ( )
preproc_flags_for_build = comp . get_preproc_flags ( )
if cross_comp is not None :
new_options_for_host = cross_comp . get_options ( )
preproc_flags_for_host = cross_comp . get_preproc_flags ( )
else :
new_options_for_host = comp . get_options ( )
preproc_flags_for_host = comp . get_preproc_flags ( )
opts_machines_list = [
( new_options_for_build , preproc_flags_for_build , MachineChoice . BUILD ) ,
( new_options_for_host , preproc_flags_for_host , MachineChoice . HOST ) ,
]
optprefix = lang + ' _ '
for k , o in new_options . items ( ) :
if not k . startswith ( optprefix ) :
raise MesonException ( ' Internal error, %s has incorrect prefix. ' % k )
if k in cmd_line_options :
o . set_value ( cmd_line_options [ k ] )
self . compiler_options . setdefault ( k , o )
# Unlike compiler and linker flags, preprocessor flags are not in
# compiler_options because they are not visible to user.
preproc_flags = comp . get_preproc_flags ( )
preproc_flags = shlex . split ( preproc_flags )
self . external_preprocess_args . setdefault ( lang , preproc_flags )
for new_options , preproc_flags , for_machine in opts_machines_list :
for k , o in new_options . items ( ) :
if not k . startswith ( optprefix ) :
raise MesonException ( ' Internal error, %s has incorrect prefix. ' % k )
if k in env . properties [ for_machine ] :
# Get from configuration files.
o . set_value ( env . properties [ for_machine ] [ k ] )
if ( env . machines . matches_build_machine ( for_machine ) and
k in env . cmd_line_options ) :
# TODO think about cross and command-line interface.
o . set_value ( env . cmd_line_options [ k ] )
self . compiler_options [ for_machine ] . setdefault ( k , o )
# Unlike compiler and linker flags, preprocessor flags are not in
# compiler_options because they are not visible to user.
preproc_flags = shlex . split ( preproc_flags )
self . external_preprocess_args [ for_machine ] . setdefault ( lang , preproc_flags )
enabled_opts = [ ]
for optname in comp . base_options :
if optname in self . base_options :
continue
oobj = compilers . base_options [ optname ]
if optname in cmd_line_options :
oobj . set_value ( cmd_line_options [ optname ] )
if optname in env . cmd_line_options :
oobj . set_value ( env . cmd_line_options [ optname ] )
enabled_opts . append ( optname )
self . base_options [ optname ] = oobj
self . emit_base_options_warnings ( enabled_opts )