1project('phosphor-dbus-interfaces', 'cpp',
2    meson_version: '>= 0.58.0',
3    default_options: [
4        'buildtype=debugoptimized',
5        'cpp_std=c++20',
6        'warning_level=3',
7        'werror=true',
8        'generate_md=' + (meson.is_subproject() ? 'false' : 'true'),
9    ],
10    version: '1.0.0',
11)
12
13# Get sdbusplus dependency.
14sdbusplus_dep = dependency('sdbusplus', required: false)
15if sdbusplus_dep.found() and sdbusplus_dep.type_name() != 'internal'
16    sdbusplusplus_prog = find_program('sdbus++', native: true)
17    sdbuspp_gen_meson_prog = find_program('sdbus++-gen-meson', native: true)
18else
19    sdbusplus_proj = subproject('sdbusplus', required: true)
20    sdbusplus_dep = sdbusplus_proj.get_variable('sdbusplus_dep')
21    sdbusplusplus_prog = sdbusplus_proj.get_variable('sdbusplusplus_prog')
22    sdbuspp_gen_meson_prog = sdbusplus_proj.get_variable(
23        'sdbuspp_gen_meson_prog'
24    )
25endif
26
27# Parse options to determine appropriate subdirectories to support.
28selected_subdirs = []
29if get_option('data_com_ibm')
30    selected_subdirs += 'com/ibm'
31endif
32if get_option('data_com_intel')
33    selected_subdirs += 'com/intel'
34endif
35if get_option('data_com_google')
36    selected_subdirs += 'com/google'
37endif
38if get_option('data_org_freedesktop')
39    selected_subdirs += 'org/freedesktop'
40endif
41if get_option('data_org_open_power')
42    selected_subdirs += 'org/open_power'
43endif
44if get_option('data_xyz_openbmc_project')
45    selected_subdirs += 'xyz/openbmc_project'
46endif
47
48# Install the selected YAML files.
49inst_yaml_dir = get_option('datadir') / 'phosphor-dbus-yaml/yaml'
50foreach d : selected_subdirs
51    install_subdir(
52        'yaml' / d,
53        install_dir: inst_yaml_dir / d,
54        strip_directory: true,
55    )
56endforeach
57
58# If libphosphor_dbus was not enabled, exit out from here.  We installed
59# the YAML which is all we are asked to do.
60if not get_option('libphosphor_dbus')
61    subdir_done()
62endif
63
64generated_sources = []
65generated_others = []
66yaml_sources = []
67
68# Source the generated meson files.
69subdir('gen')
70foreach d : selected_subdirs
71  subdir('gen' / d)
72endforeach
73custom_target(
74    'md',
75    command: 'true',
76    output: 'md',
77    capture: true,
78    depends: generated_others,
79    build_by_default: get_option('generate_md'))
80
81generated_files_headers = []
82generated_files_cpp = []
83foreach s : generated_sources
84    foreach f : s.to_list()
85        p = f.full_path()
86        if p.endswith('.hpp')
87            generated_files_headers += f
88        elif p.endswith('.cpp')
89            generated_files_cpp += f
90        else
91            error('Unknown filetype: ' + p)
92        endif
93    endforeach
94endforeach
95
96generated_root = meson.current_build_dir() / 'gen/'
97exclude_cpp = []
98foreach f : generated_files_cpp
99    exclude_cpp += f.full_path().replace(generated_root, '').strip('/')
100endforeach
101
102# Install the generated header files.
103exclude = exclude_cpp
104foreach o : generated_others
105    foreach f : o.to_list()
106        exclude += f.full_path().replace(generated_root, '').strip('/')
107    endforeach
108endforeach
109install_subdir(
110    generated_root,
111    exclude_files: exclude,
112    install_dir: get_option('includedir'),
113    strip_directory: true,
114)
115
116# Install the generated markdown files.
117exclude = exclude_cpp
118foreach f : generated_files_headers
119    exclude += f.full_path().replace(generated_root, '').strip('/')
120endforeach
121install_subdir(
122    generated_root,
123    exclude_files: exclude,
124    install_dir: get_option('datadir') / 'doc' / meson.project_name(),
125    strip_directory: true,
126)
127
128# Define and build libphosphor_dbus.so from the C++ files.
129libphosphor_dbus = library(
130    'phosphor_dbus',
131    generated_sources,
132    implicit_include_directories: false,
133    include_directories: include_directories('gen'),
134    dependencies: sdbusplus_dep,
135    version: meson.project_version(),
136    install: true,
137)
138
139import('pkgconfig').generate(
140    libphosphor_dbus,
141    name: meson.project_name(),
142    version: meson.project_version(),
143    description: 'Generated sdbusplus bindings for phosphor-dbus-interfaces',
144    variables: ['yamldir=' + '${pc_sysrootdir}${prefix}' / inst_yaml_dir],
145)
146
147phosphor_dbus_interfaces_dep = declare_dependency(
148    sources: generated_files_headers,
149    include_directories: include_directories('gen'),
150    link_with: libphosphor_dbus,
151    dependencies: sdbusplus_dep,
152    variables: ['yamldir=' + meson.project_source_root() / 'yaml'],
153)
154