meson: add common libs for target and target_system

Following what we did for hw/, we need target specific common libraries
for target. We need 2 different libraries:
- code common to a base architecture
- system code common to a base architecture

For user code, it can stay compiled per target for now.

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
Message-id: 20250512180502.2395029-4-pierrick.bouvier@linaro.org
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
Pierrick Bouvier 2025-05-12 11:04:17 -07:00 committed by Peter Maydell
parent af3ca6e7f0
commit b2bb3f3576

View file

@ -3709,6 +3709,8 @@ target_arch = {}
target_system_arch = {} target_system_arch = {}
target_user_arch = {} target_user_arch = {}
hw_common_arch = {} hw_common_arch = {}
target_common_arch = {}
target_common_system_arch = {}
# NOTE: the trace/ subdirectory needs the qapi_trace_events variable # NOTE: the trace/ subdirectory needs the qapi_trace_events variable
# that is filled in by qapi/. # that is filled in by qapi/.
@ -4107,29 +4109,59 @@ common_all = static_library('common',
# construct common libraries per base architecture # construct common libraries per base architecture
hw_common_arch_libs = {} hw_common_arch_libs = {}
target_common_arch_libs = {}
target_common_system_arch_libs = {}
foreach target : target_dirs foreach target : target_dirs
config_target = config_target_mak[target] config_target = config_target_mak[target]
target_base_arch = config_target['TARGET_BASE_ARCH'] target_base_arch = config_target['TARGET_BASE_ARCH']
target_inc = [include_directories('target' / target_base_arch)]
inc = [common_user_inc + target_inc]
# check if already generated # prevent common code to access cpu compile time definition,
if target_base_arch in hw_common_arch_libs # but still allow access to cpu.h
continue target_c_args = ['-DCPU_DEFS_H']
endif target_system_c_args = target_c_args + ['-DCOMPILING_SYSTEM_VS_USER', '-DCONFIG_SOFTMMU']
if target_base_arch in hw_common_arch if target_base_arch in hw_common_arch
target_inc = [include_directories('target' / target_base_arch)] if target_base_arch not in hw_common_arch_libs
src = hw_common_arch[target_base_arch] src = hw_common_arch[target_base_arch]
lib = static_library( lib = static_library(
'hw_' + target_base_arch, 'hw_' + target_base_arch,
build_by_default: false, build_by_default: false,
sources: src.all_sources() + genh, sources: src.all_sources() + genh,
include_directories: common_user_inc + target_inc, include_directories: inc,
implicit_include_directories: false, c_args: target_system_c_args,
# prevent common code to access cpu compile time dependencies: src.all_dependencies())
# definition, but still allow access to cpu.h hw_common_arch_libs += {target_base_arch: lib}
c_args: ['-DCPU_DEFS_H', '-DCOMPILING_SYSTEM_VS_USER', '-DCONFIG_SOFTMMU'], endif
dependencies: src.all_dependencies()) endif
hw_common_arch_libs += {target_base_arch: lib}
if target_base_arch in target_common_arch
if target_base_arch not in target_common_arch_libs
src = target_common_arch[target_base_arch]
lib = static_library(
'target_' + target_base_arch,
build_by_default: false,
sources: src.all_sources() + genh,
include_directories: inc,
c_args: target_c_args,
dependencies: src.all_dependencies())
target_common_arch_libs += {target_base_arch: lib}
endif
endif
if target_base_arch in target_common_system_arch
if target_base_arch not in target_common_system_arch_libs
src = target_common_system_arch[target_base_arch]
lib = static_library(
'target_system_' + target_base_arch,
build_by_default: false,
sources: src.all_sources() + genh,
include_directories: inc,
c_args: target_system_c_args,
dependencies: src.all_dependencies())
target_common_system_arch_libs += {target_base_arch: lib}
endif
endif endif
endforeach endforeach
@ -4300,12 +4332,24 @@ foreach target : target_dirs
target_common = common_ss.apply(config_target, strict: false) target_common = common_ss.apply(config_target, strict: false)
objects = [common_all.extract_objects(target_common.sources())] objects = [common_all.extract_objects(target_common.sources())]
arch_deps += target_common.dependencies() arch_deps += target_common.dependencies()
if target_base_arch in target_common_arch_libs
src = target_common_arch[target_base_arch].apply(config_target, strict: false)
lib = target_common_arch_libs[target_base_arch]
objects += lib.extract_objects(src.sources())
arch_deps += src.dependencies()
endif
if target_type == 'system' and target_base_arch in hw_common_arch_libs if target_type == 'system' and target_base_arch in hw_common_arch_libs
src = hw_common_arch[target_base_arch].apply(config_target, strict: false) src = hw_common_arch[target_base_arch].apply(config_target, strict: false)
lib = hw_common_arch_libs[target_base_arch] lib = hw_common_arch_libs[target_base_arch]
objects += lib.extract_objects(src.sources()) objects += lib.extract_objects(src.sources())
arch_deps += src.dependencies() arch_deps += src.dependencies()
endif endif
if target_type == 'system' and target_base_arch in target_common_system_arch_libs
src = target_common_system_arch[target_base_arch].apply(config_target, strict: false)
lib = target_common_system_arch_libs[target_base_arch]
objects += lib.extract_objects(src.sources())
arch_deps += src.dependencies()
endif
target_specific = specific_ss.apply(config_target, strict: false) target_specific = specific_ss.apply(config_target, strict: false)
arch_srcs += target_specific.sources() arch_srcs += target_specific.sources()