sdbus++-gen-meson: leverage `install_dir` for custom targets
Meson has had a `install_dir` directive on `custom_target` which
allows specifying per-output where the file should be installed.
Leveraging this greatly simplifies the meson in consumers (such as
phosphor-dbus-interfaces) and makes the install less error-prone.
The previous method for installing was to use a `install_subdir`
call with large exclude lists (so that markdown did not end up in
the include tree). The result of this was that many empty directories
were created in the include, markdown, and registry install paths.
Using this method reduces by 25% the meson content in
phosphor-dbus-interfaces.
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: I2b03116f517caa75de902ac7e44e6923d6652cad
diff --git a/test/gen/meson.build b/test/gen/meson.build
index 8d7d4de..ef27aee 100644
--- a/test/gen/meson.build
+++ b/test/gen/meson.build
@@ -13,3 +13,23 @@
)
endif
+inst_markdown_dir = get_option('datadir') / 'doc' / meson.project_name()
+inst_registry_dir = get_option('datadir') / 'redfish-registry' / meson.project_name()
+
+generated_sources = []
+generated_markdown = []
+generated_registry = []
+
+foreach d : yaml_selected_subdirs
+ subdir(d)
+endforeach
+
+generated_headers = []
+foreach s : generated_sources
+ foreach f : s.to_list()
+ if f.full_path().endswith('.hpp')
+ generated_headers += f
+ endif
+ endforeach
+endforeach
+
diff --git a/test/gen/server/Test/meson.build b/test/gen/server/Test/meson.build
index 459f0a8..53b0820 100644
--- a/test/gen/server/Test/meson.build
+++ b/test/gen/server/Test/meson.build
@@ -1,8 +1,19 @@
# Generated file; do not modify.
+
+sdbusplus_current_path = 'server/Test'
+
generated_sources += custom_target(
'server/Test__cpp'.underscorify(),
- input: [ '../../../yaml/server/Test.interface.yaml', ],
- output: [ 'common.hpp', 'server.cpp', 'server.hpp', 'aserver.hpp', 'client.hpp', ],
+ input: [
+ '../../../yaml/server/Test.interface.yaml',
+ ],
+ output: [
+ 'common.hpp',
+ 'server.hpp',
+ 'server.cpp',
+ 'aserver.hpp',
+ 'client.hpp',
+ ],
depend_files: sdbusplusplus_depfiles,
command: [
sdbuspp_gen_meson_prog, '--command', 'cpp',
@@ -11,5 +22,14 @@
'--directory', meson.current_source_dir() / '../../../yaml',
'server/Test',
],
+ install: should_generate_cpp,
+ install_dir: [
+ get_option('includedir') / sdbusplus_current_path,
+ get_option('includedir') / sdbusplus_current_path,
+ false,
+ get_option('includedir') / sdbusplus_current_path,
+ get_option('includedir') / sdbusplus_current_path,
+ ],
+ build_by_default: should_generate_cpp,
)
diff --git a/test/gen/server/meson.build b/test/gen/server/meson.build
index 6ab2512..20a77bf 100644
--- a/test/gen/server/meson.build
+++ b/test/gen/server/meson.build
@@ -1,6 +1,9 @@
# Generated file; do not modify.
subdir('Test')
-generated_others += custom_target(
+
+sdbusplus_current_path = 'server'
+
+generated_markdown += custom_target(
'server/Test__markdown'.underscorify(),
input: [ '../../yaml/server/Test.interface.yaml', ],
output: [ 'Test.md' ],
@@ -12,5 +15,8 @@
'--directory', meson.current_source_dir() / '../../yaml',
'server/Test',
],
+ install: should_generate_markdown,
+ install_dir: [inst_markdown_dir / sdbusplus_current_path],
+ build_by_default: should_generate_markdown,
)
diff --git a/test/meson.build b/test/meson.build
index c0b7a0a..2329e31 100644
--- a/test/meson.build
+++ b/test/meson.build
@@ -87,10 +87,8 @@
),
)
-generated_sources = []
-generated_others = []
+yaml_selected_subdirs = ['server']
subdir('gen')
-subdir('gen/server')
server_test_pre = declare_dependency(
include_directories: include_directories('gen'),
@@ -102,17 +100,8 @@
implicit_include_directories: false,
dependencies: server_test_pre)
-generated_sources_header = []
-foreach s : generated_sources
- foreach f : s.to_list()
- if f.full_path().endswith('.hpp')
- generated_sources_header += f
- endif
- endforeach
-endforeach
-
server_test_dep = declare_dependency(
- sources: generated_sources_header,
+ sources: generated_headers,
link_with: server_test_lib,
dependencies: server_test_pre)