1# SPDX-License-Identifier: Apache-2.0
2
3project('phosphor-debug-collector',
4        'cpp',
5        meson_version: '>=1.1.1',
6        default_options: [
7                          'cpp_std=c++23',
8                          'warning_level=3',
9                          'werror=true',
10                          'buildtype=debugoptimized'
11                         ],
12        version: '1.0',
13        license: 'Apache-2.0'
14       )
15
16cpp = meson.get_compiler('cpp')
17
18# list of unit files, the path as input and service name
19# as output
20# eg: unit_file += {'input:'<path>, 'output':<service name>}
21unit_files = []
22
23# Checking dependency external library
24
25libsystemd = dependency('libsystemd', version : '>=221')
26
27sdbusplus_dep = dependency('sdbusplus')
28sdbusplusplus_prog = find_program('sdbus++')
29sdbuspp_gen_meson_prog = find_program('sdbus++-gen-meson')
30sdeventplus_dep = dependency('sdeventplus')
31
32phosphor_dbus_interfaces_dep = dependency('phosphor-dbus-interfaces')
33phosphor_logging_dep = dependency('phosphor-logging')
34
35# nlohmann-json dependency
36nlohmann_json_dep = dependency('nlohmann_json', include_type: 'system')
37
38# Get Cereal dependency.
39cereal_dep = dependency('cereal', required: false)
40has_cereal = cpp.has_header_symbol(
41    'cereal/cereal.hpp',
42    'cereal::specialize',
43    dependencies: cereal_dep,
44    required: false)
45if not has_cereal
46    cereal_opts = import('cmake').subproject_options()
47    cereal_opts.add_cmake_defines({'BUILD_TESTS': 'OFF', 'SKIP_PERFORMANCE_COMPARISON': 'ON'})
48    cereal_proj = import('cmake').subproject(
49        'cereal',
50        options: cereal_opts,
51        required: false)
52    assert(cereal_proj.found(), 'cereal is required')
53    cereal_dep = cereal_proj.dependency('cereal')
54endif
55
56# Disable FORTIFY_SOURCE when compiling with no optimization
57if(get_option('optimization') == '0')
58  add_project_arguments('-U_FORTIFY_SOURCE',language:['cpp','c'])
59  message('Disabling FORTIFY_SOURCE as optimization is set to 0')
60endif
61
62# Configuration header file(config.h) generation
63
64conf_data = configuration_data()
65
66conf_data.set_quoted('DUMP_BUSNAME', get_option('DUMP_BUSNAME'),
67                      description : 'The Dbus busname to own'
68                    )
69conf_data.set_quoted('DUMP_OBJPATH', get_option('DUMP_OBJPATH'),
70                      description : 'The Dump manager Dbus root'
71                    )
72conf_data.set_quoted('BMC_DUMP_OBJPATH', get_option('BMC_DUMP_OBJPATH'),
73                      description : 'The BMC Dump manager Dbus path'
74                    )
75conf_data.set_quoted('CORE_FILE_DIR', get_option('CORE_FILE_DIR'),
76                      description : 'Directory where core dumps are placed'
77                    )
78conf_data.set_quoted('BMC_DUMP_OBJ_ENTRY', get_option('BMC_DUMP_OBJ_ENTRY'),
79                      description : 'The BMC dump entry DBus object path'
80                    )
81conf_data.set_quoted('BMC_DUMP_PATH', get_option('BMC_DUMP_PATH'),
82                     description : 'Directory where bmc dumps are placed')
83conf_data.set_quoted('SYSTEMD_PSTORE_PATH', get_option('SYSTEMD_PSTORE_PATH'),
84                     description : 'Path to the systemd pstore directory')
85conf_data.set('BMC_DUMP_MAX_SIZE', get_option('BMC_DUMP_MAX_SIZE'),
86               description : 'Maximum size of one bmc dump in kilo bytes'
87             )
88conf_data.set('BMC_DUMP_MIN_SPACE_REQD', get_option('BMC_DUMP_MIN_SPACE_REQD'),
89               description : 'Minimum space required for one bmc dump in kilo bytes'
90             )
91conf_data.set('BMC_DUMP_TOTAL_SIZE', get_option('BMC_DUMP_TOTAL_SIZE'),
92               description : 'Total size of the dump in kilo bytes'
93             )
94conf_data.set_quoted('OBJ_LOGGING', '/xyz/openbmc_project/logging',
95                      description : 'The log manager DBus object path'
96                    )
97conf_data.set_quoted('ELOG_ID_PERSIST_PATH', get_option('ELOG_ID_PERSIST_PATH'),
98                      description : 'Path of file for storing elog id\'s, which have associated dumps'
99                    )
100conf_data.set('CLASS_VERSION', get_option('CLASS_VERSION'),
101               description : 'Class version to register with Cereal'
102             )
103conf_data.set('ERROR_MAP_YAML', get_option('ERROR_MAP_YAML'),
104               description : 'YAML filepath containing error object paths'
105             )
106conf_data.set('JFFS_CORE_FILE_WORKAROUND', get_option('jffs-workaround').allowed(),
107               description : 'Turn on jffs workaround for core file'
108             )
109conf_data.set_quoted('FAULTLOG_DUMP_OBJ_ENTRY', get_option('FAULTLOG_DUMP_OBJ_ENTRY'),
110                      description : 'The Fault Log dump entry DBus object path'
111                    )
112conf_data.set_quoted('FAULTLOG_DUMP_OBJPATH', get_option('FAULTLOG_DUMP_OBJPATH'),
113                      description : 'The Fault Log Dump manager Dbus path'
114                    )
115conf_data.set_quoted('FAULTLOG_DUMP_PATH', get_option('FAULTLOG_DUMP_PATH'),
116                      description : 'Directory where fault logs are placed'
117                    )
118conf_data.set('BMC_DUMP_ROTATE_CONFIG', get_option('dump_rotate_config').allowed(),
119               description : 'Turn on rotate config for bmc dump'
120             )
121
122configure_file(configuration : conf_data,
123               output : 'config.h'
124              )
125
126dump_types_yaml_files = []
127
128# Dump types YAML file
129dump_types_yaml_files += {'input': 'example_dump_types.yaml',
130         'output': 'dump_types.yaml'}
131
132# Copy and combine YAML files
133concatenate_command = 'cat '
134combined_yaml_file = 'combined_dump_types.yaml'
135
136foreach yaml_file : dump_types_yaml_files
137    configure_file(input : yaml_file.get('input'),
138                   output : yaml_file.get('output'),
139                   copy : true)
140    concatenate_command += meson.project_build_root() + '/' + yaml_file.get('output') + ' '
141endforeach
142
143concatenate_command += '> ' + meson.project_build_root() + '/' + combined_yaml_file
144run_command('sh', '-c', concatenate_command)
145
146python = find_program('python3')
147map_gen_file_loc = meson.project_source_root()
148map_gen_file_loc += '/map_gen.py'
149
150dump_types_hpp = custom_target(
151                    'dump_types.hpp',
152                    command : [
153                        python,
154                        map_gen_file_loc,
155                        '-i',
156                        meson.project_build_root() + '/' +  combined_yaml_file,
157                        '-j',
158                        get_option('ERROR_MAP_YAML'),
159                        '-t',
160                        'dump_types.mako.hpp',
161                        '-o',
162                        'dump_types.hpp'
163                    ],
164                    depend_files : [ 'dump_types.mako.hpp',
165                                     'map_gen.py',
166                                     meson.project_build_root() + '/' +  combined_yaml_file,
167                                     get_option('ERROR_MAP_YAML')
168                                   ],
169                    output : 'dump_types.hpp'
170                 )
171
172dump_types_cpp = custom_target(
173                    'dump_types.cpp',
174                    command : [
175                        python,
176                        map_gen_file_loc,
177                        '-i',
178                        meson.project_build_root() + '/' +  combined_yaml_file,
179                        '-j',
180                        get_option('ERROR_MAP_YAML'),
181                        '-t',
182                        'dump_types.mako.cpp',
183                        '-o',
184                        'dump_types.cpp'
185                    ],
186                    depend_files : [ 'dump_types.mako.cpp',
187                                     'map_gen.py',
188                                     meson.project_build_root() + '/' +  combined_yaml_file,
189                                     get_option('ERROR_MAP_YAML')
190                                   ],
191                    output : 'dump_types.cpp'
192                 )
193
194phosphor_dump_manager_sources = [
195        'dump_entry.cpp',
196        'dump_manager.cpp',
197        'dump_manager_bmc.cpp',
198        'dump_manager_main.cpp',
199        'dump_serialize.cpp',
200        'elog_watch.cpp',
201        dump_types_hpp,
202        dump_types_cpp,
203        'watch.cpp',
204        'bmc_dump_entry.cpp',
205        'dump_utils.cpp',
206        'dump_offload.cpp',
207        'dump_manager_faultlog.cpp',
208        'faultlog_dump_entry.cpp'
209    ]
210
211phosphor_dump_manager_dependency = [
212        phosphor_dbus_interfaces_dep,
213        sdbusplus_dep,
214        sdeventplus_dep,
215        phosphor_logging_dep,
216        cereal_dep,
217        nlohmann_json_dep,
218    ]
219
220phosphor_dump_manager_install = true
221
222phosphor_dump_manager_incdir = []
223
224# To get host transport based interface to take respective host
225# dump actions. It will contain required sources and dependency
226# list for phosphor_dump_manager.
227subdir('host-transport-extensions')
228
229#pick any architecture specific dumps
230subdir('dump-extensions')
231
232phosphor_dump_monitor_sources = [
233        dump_types_hpp,
234        'core_manager.cpp',
235        'core_manager_main.cpp',
236        'watch.cpp'
237    ]
238
239phosphor_dump_monitor_dependency = [
240        phosphor_dbus_interfaces_dep,
241        phosphor_logging_dep,
242        sdeventplus_dep,
243    ]
244
245phosphor_dump_monitor_install = true
246
247phosphor_dump_monitor_incdir = []
248
249phosphor_ramoops_monitor_sources = [
250        dump_types_hpp,
251        'ramoops_manager.cpp',
252        'ramoops_manager_main.cpp',
253        'watch.cpp'
254    ]
255
256phosphor_ramoops_monitor_dependency = [
257        phosphor_dbus_interfaces_dep,
258        phosphor_logging_dep,
259        sdeventplus_dep,
260    ]
261
262phosphor_ramoops_monitor_install = true
263
264phosphor_ramoops_monitor_incdir = []
265
266executables = [[ 'phosphor-dump-manager',
267                  phosphor_dump_manager_sources,
268                  phosphor_dump_manager_dependency,
269                  phosphor_dump_manager_install,
270                  phosphor_dump_manager_incdir
271               ],
272               [ 'phosphor-dump-monitor',
273                  phosphor_dump_monitor_sources,
274                  phosphor_dump_monitor_dependency,
275                  phosphor_dump_monitor_install,
276                  phosphor_dump_monitor_incdir
277               ],
278               [ 'phosphor-ramoops-monitor',
279                  phosphor_ramoops_monitor_sources,
280                  phosphor_ramoops_monitor_dependency,
281                  phosphor_ramoops_monitor_install,
282                  phosphor_ramoops_monitor_incdir
283               ]
284              ]
285
286foreach executable : executables
287    binary = executable(
288                        executable[0],
289                        executable[1],
290                        dependencies: executable[2],
291                        install : executable[3],
292                        include_directories : executable[4]
293                       )
294endforeach
295
296unit_subs = configuration_data()
297unit_subs.set('bindir', join_paths(get_option('prefix'), get_option('bindir')))
298systemd_system_unit_dir = dependency('systemd').get_variable(
299    'systemdsystemunitdir',
300    pkgconfig_define: ['prefix', get_option('prefix')])
301foreach u : unit_files
302    configure_file(
303        configuration: unit_subs,
304        input: u.get('input'),
305        install: true,
306        install_dir: systemd_system_unit_dir,
307        output: u.get('output')
308    )
309endforeach
310
311if get_option('tests').allowed()
312  subdir('test')
313endif
314