build: use generated meson.build files
Make changes to the root meson.build to utilize the generated
meson.build files found in the `gen` sub-directory. Update the
README to indicate how these can be regenerated.
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: Ibe45637faf572e0a5a88719adf5f41f877895927
diff --git a/README.md b/README.md
index 3344887..7b38083 100644
--- a/README.md
+++ b/README.md
@@ -7,10 +7,10 @@
This project can be built with `meson`. The typical `meson` workflow is:
`meson builddir && ninja -C builddir`.
-Due to the limited code generation methods available in meson today, changes
-to YAML files are not tracked by `meson` and do not automatically cause a new
-recompile. Subsequent runs when making YAML changes will require running
-`ninja reconfigure` in order to regenerate the code files from the YAML.
+The meson files used to handle the YAML files are automatically generated
+and found under the `gen` subdirectory. When adding or removing YAML files,
+this must be regenerated. This can be done with the helper script found
+in the `gen` subdirectory: `cd gen && ./regenerate-meson`.
## Configuration
diff --git a/meson.build b/meson.build
index d2bb5cd..249be71 100644
--- a/meson.build
+++ b/meson.build
@@ -18,12 +18,14 @@
sdbusplus_dep = dependency('sdbusplus', required: false)
if sdbusplus_dep.found()
sdbusplusplus_prog = find_program('sdbus++')
- sdbusgen_prog = find_program('sdbus++-gendir')
+ sdbuspp_gen_meson_prog = find_program('sdbus++-gen-meson')
else
sdbusplus_proj = subproject('sdbusplus', required: true)
sdbusplus_dep = sdbusplus_proj.get_variable('sdbusplus_dep')
sdbusplusplus_prog = sdbusplus_proj.get_variable('sdbusplusplus_prog')
- sdbusgen_prog = sdbusplus_proj.get_variable('sdbusgen_prog')
+ sdbuspp_gen_meson_prog = sdbusplus_proj.get_variable(
+ 'sdbuspp_gen_meson_prog'
+ )
endif
realpath_prog = find_program('realpath')
@@ -55,44 +57,44 @@
subdir_done()
endif
-# Generate all the sdbus++ files from the selected subdirectories.
-generated_root = meson.current_build_dir() / 'gen-out'
-generated_files = run_command(
- sdbusgen_prog,
- '--list-all',
- '--tool', sdbusplusplus_prog,
- '--output', generated_root,
- selected_subdirs,
- check: true,
-).stdout().strip().split('\n')
+generated_root = meson.current_build_dir() / 'gen'
+generated_sources = []
+generated_others = []
+yaml_sources = []
+
+# Source the generated meson files.
+subdir('gen')
+foreach d : selected_subdirs
+ subdir('gen' / d)
+endforeach
# Parse through the list from sdbus++-gendir and put into sets.
generated_headers = []
generated_cpp = []
-generated_cpp_fullpath = []
-generated_others = []
+generated_others_files = []
-foreach f : generated_files
- rel_path = run_command(
- realpath_prog,
- '--relative-to', generated_root,
- f,
- ).stdout().strip().split('\n')[-1]
+foreach g : generated_sources generated_others
+ foreach f : g.to_list()
+ rel_path = run_command(
+ realpath_prog,
+ '--relative-to', generated_root,
+ f.full_path(),
+ ).stdout().strip().split('\n')[-1]
- if f.endswith('.hpp')
- generated_headers += rel_path
- elif f.endswith('.cpp')
- generated_cpp += rel_path
- generated_cpp_fullpath += f
- else
- generated_others += rel_path
- endif
+ if rel_path.endswith('.hpp')
+ generated_headers += rel_path
+ elif rel_path.endswith('.cpp')
+ generated_cpp += rel_path
+ else
+ generated_others_files += rel_path
+ endif
+ endforeach
endforeach
# Install the generated header files.
install_subdir(
generated_root,
- exclude_files: [ generated_cpp, generated_others ],
+ exclude_files: [ generated_cpp, generated_others_files ],
install_dir: get_option('includedir'),
strip_directory: true,
)
@@ -108,8 +110,8 @@
# Define and build libphosphor_dbus.so from the C++ files.
libphosphor_dbus = library(
'phosphor_dbus',
- files(generated_cpp_fullpath),
- include_directories: include_directories('gen-out'),
+ generated_sources,
+ include_directories: include_directories('gen'),
dependencies: sdbusplus_dep,
version: meson.project_version(),
install: true,