From 6784d8a10f5cfd6592ca320169734273932c6819 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20B=C3=A1lint=20Misius?= Date: Wed, 7 May 2025 18:32:41 +0200 Subject: [PATCH] Share object files between powder/render/font I'm not sure why we weren't using static_libraries to begin with; most likely because the object files (as opposed to the sources) were not possible to share due to different sets of macros being defined in cpp_args, see 3a591b853945 to 4f0c365e05a2. --- meson.build | 67 ++++++++++++++++++++++---------- src/common/clipboard/Local.cpp | 36 +++++++++++++++++ src/common/clipboard/Null.cpp | 24 ------------ src/common/clipboard/meson.build | 2 +- src/graphics/meson.build | 6 +-- src/gui/meson.build | 3 -- src/meson.build | 4 -- src/resampler/meson.build | 4 +- src/simulation/meson.build | 3 -- 9 files changed, 87 insertions(+), 62 deletions(-) create mode 100644 src/common/clipboard/Local.cpp diff --git a/meson.build b/meson.build index 3578460ec..91154e553 100644 --- a/meson.build +++ b/meson.build @@ -459,9 +459,7 @@ foreach embedded_file : embedded_files endforeach powder_files += powder_external_files -powder_files += data_files -render_files += data_files -font_files += data_files +common_files += data_files if host_platform == 'emscripten' project_link_args += [ @@ -487,17 +485,49 @@ endif clang_tidy_sources = [] +sta_libs = {} +foreach sta_info : [ + [ 'common', common_files, [ + host_platform == 'android' ? sdl2_dep : [], + png_dep, + zlib_dep, + bzip2_dep, + ] ], + [ 'gui', gui_files, [ + sdl2_dep, + ] ], + [ 'simulation', simulation_files, [ + json_dep, + ] ], +] + sta_name = sta_info[0] + sta_srcs = sta_info[1] + sta_deps = sta_info[2] + sta_libs += { sta_name: declare_dependency( + include_directories: project_inc, + link_with: static_library( + sta_name, + sources: sta_srcs, + include_directories: project_inc, + cpp_args: project_cpp_args, + override_options: target_options, + pic: host_platform == 'android', + dependencies: sta_deps, + ), + dependencies: sta_deps, + ) } + clang_tidy_sources += sta_srcs +endforeach + if get_option('build_powder') powder_deps += project_deps + [ threads_dep, - zlib_dep, - png_dep, - sdl2_dep, lua_dep, curl_dep, fftw_dep, - bzip2_dep, - json_dep, + sta_libs['common'], + sta_libs['gui'], + sta_libs['simulation'], ] if host_platform == 'android' powder_sha = shared_library( @@ -530,15 +560,13 @@ if get_option('build_powder') endif if get_option('build_render') - if host_platform == 'emscripten' - error('render does not target emscripten') + if host_platform in [ 'android', 'emscripten' ] + error('render does not target @0@'.format(host_platform)) endif render_deps = project_deps + [ threads_dep, - zlib_dep, - bzip2_dep, - json_dep, - png_dep, + sta_libs['common'], + sta_libs['simulation'], ] render_link_args = project_link_args if host_platform == 'linux' and is_static @@ -559,16 +587,13 @@ if get_option('build_render') endif if get_option('build_font') - if host_platform == 'emscripten' - error('font does not target emscripten') + if host_platform in [ 'android', 'emscripten' ] + error('font does not target @0@'.format(host_platform)) endif font_deps = project_deps + [ threads_dep, - zlib_dep, - png_dep, - sdl2_dep, - bzip2_dep, - json_dep, + sta_libs['common'], + sta_libs['gui'], ] executable( 'font', diff --git a/src/common/clipboard/Local.cpp b/src/common/clipboard/Local.cpp new file mode 100644 index 000000000..88d42eeae --- /dev/null +++ b/src/common/clipboard/Local.cpp @@ -0,0 +1,36 @@ +#include "Clipboard.h" +#include "client/GameSave.h" + +namespace Clipboard +{ + void SetClipboardData(std::unique_ptr data) + { + } + + const GameSave *GetClipboardData() + { + return nullptr; + } + + void Init() + { + } + + bool GetEnabled() + { + return false; + } + + void SetEnabled(bool) + { + } + + void RecreateWindow() + { + } + + std::optional Explanation() + { + return std::nullopt; + } +} diff --git a/src/common/clipboard/Null.cpp b/src/common/clipboard/Null.cpp index 88d42eeae..1e8b8cc92 100644 --- a/src/common/clipboard/Null.cpp +++ b/src/common/clipboard/Null.cpp @@ -1,36 +1,12 @@ #include "Clipboard.h" -#include "client/GameSave.h" namespace Clipboard { - void SetClipboardData(std::unique_ptr data) - { - } - - const GameSave *GetClipboardData() - { - return nullptr; - } - void Init() { } - bool GetEnabled() - { - return false; - } - - void SetEnabled(bool) - { - } - void RecreateWindow() { } - - std::optional Explanation() - { - return std::nullopt; - } } diff --git a/src/common/clipboard/meson.build b/src/common/clipboard/meson.build index d7e3871bf..495f841af 100644 --- a/src/common/clipboard/meson.build +++ b/src/common/clipboard/meson.build @@ -33,7 +33,7 @@ if platform_clipboard endif powder_files += files('Dynamic.cpp') else - powder_files += files('Null.cpp') + powder_files += files('Local.cpp') endif render_files += files('Null.cpp') font_files += files('Null.cpp') diff --git a/src/graphics/meson.build b/src/graphics/meson.build index e32568d9e..dd4eabc75 100644 --- a/src/graphics/meson.build +++ b/src/graphics/meson.build @@ -8,6 +8,6 @@ powder_graphics_files = files( 'Renderer.cpp', ) -powder_files += graphics_files + powder_graphics_files -render_files += graphics_files + powder_graphics_files -font_files += graphics_files +common_files += graphics_files +powder_files += powder_graphics_files +render_files += powder_graphics_files diff --git a/src/gui/meson.build b/src/gui/meson.build index 226aea1da..80fc3763b 100644 --- a/src/gui/meson.build +++ b/src/gui/meson.build @@ -21,6 +21,3 @@ subdir('save') subdir('search') subdir('tags') subdir('update') - -powder_files += gui_files -font_files += gui_files diff --git a/src/meson.build b/src/meson.build index a7a4de038..471e3ed96 100644 --- a/src/meson.build +++ b/src/meson.build @@ -203,10 +203,6 @@ subdir('resampler') subdir('simulation') subdir('tasks') -powder_files += common_files -render_files += common_files -font_files += common_files - simulation_elem_defs = [] foreach elem_name_id : simulation_elem_ids simulation_elem_defs += 'ELEMENT_DEFINE(' + elem_name_id[0] + ', ' + elem_name_id[1].to_string() + ');' diff --git a/src/resampler/meson.build b/src/resampler/meson.build index 16b1eb1e1..acf0774e3 100644 --- a/src/resampler/meson.build +++ b/src/resampler/meson.build @@ -2,6 +2,4 @@ resampler_files = files( 'resampler.cpp', ) -powder_files += resampler_files -render_files += resampler_files -font_files += resampler_files +common_files += resampler_files diff --git a/src/simulation/meson.build b/src/simulation/meson.build index 6ab3d72aa..6e393aa48 100644 --- a/src/simulation/meson.build +++ b/src/simulation/meson.build @@ -16,9 +16,6 @@ subdir('elements') subdir('simtools') subdir('gravity') -powder_files += simulation_files -render_files += simulation_files - powder_files += files( 'AccessPropertyParse.cpp', 'Editing.cpp',