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# Get Cereal dependency.
36cereal_dep = dependency('cereal', required: false)
37has_cereal = cpp.has_header_symbol(
38    'cereal/cereal.hpp',
39    'cereal::specialize',
40    dependencies: cereal_dep,
41    required: false)
42if not has_cereal
43    cereal_opts = import('cmake').subproject_options()
44    cereal_opts.add_cmake_defines({'BUILD_TESTS': 'OFF'})
45    cereal_proj = import('cmake').subproject(
46        'cereal',
47        options: cereal_opts,
48        required: false)
49    assert(cereal_proj.found(), 'cereal is required')
50    cereal_dep = cereal_proj.dependency('cereal')
51endif
52
53# Disable FORTIFY_SOURCE when compiling with no optimization
54if(get_option('optimization') == '0')
55  add_project_arguments('-U_FORTIFY_SOURCE',language:['cpp','c'])
56  message('Disabling FORTIFY_SOURCE as optimization is set to 0')
57endif
58
59# Configuration header file(config.h) generation
60
61conf_data = configuration_data()
62
63conf_data.set_quoted('DUMP_BUSNAME', get_option('DUMP_BUSNAME'),
64                      description : 'The Dbus busname to own'
65                    )
66conf_data.set_quoted('DUMP_OBJPATH', get_option('DUMP_OBJPATH'),
67                      description : 'The Dump manager Dbus root'
68                    )
69conf_data.set_quoted('BMC_DUMP_OBJPATH', get_option('BMC_DUMP_OBJPATH'),
70                      description : 'The BMC Dump manager Dbus path'
71                    )
72conf_data.set_quoted('CORE_FILE_DIR', get_option('CORE_FILE_DIR'),
73                      description : 'Directory where core dumps are placed'
74                    )
75conf_data.set_quoted('OBJ_INTERNAL', get_option('OBJ_INTERNAL'),
76                      description : 'Internal Dump manager Dbus object path'
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').enabled(),
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').enabled(),
119               description : 'Turn on rotate config for bmc dump'
120             )
121
122configure_file(configuration : conf_data,
123               output : 'config.h'
124              )
125subdir('xyz/openbmc_project/Dump/Internal/Create')
126
127dump_types_yaml_files = []
128
129# Dump types YAML file
130dump_types_yaml_files += {'input': 'example_dump_types.yaml',
131         'output': 'dump_types.yaml'}
132
133# Copy and combine YAML files
134concatenate_command = 'cat '
135combined_yaml_file = 'combined_dump_types.yaml'
136
137foreach yaml_file : dump_types_yaml_files
138    configure_file(input : yaml_file.get('input'),
139                   output : yaml_file.get('output'),
140                   copy : true)
141    concatenate_command += meson.build_root() + '/' + yaml_file.get('output') + ' '
142endforeach
143
144concatenate_command += '> ' + meson.build_root() + '/' + combined_yaml_file
145run_command('sh', '-c', concatenate_command)
146
147python = find_program('python3')
148map_gen_file_loc = meson.project_source_root()
149map_gen_file_loc += '/map_gen.py'
150
151dump_types_hpp = custom_target(
152                    'dump_types.hpp',
153                    command : [
154                        python,
155                        map_gen_file_loc,
156                        '-i',
157                        meson.build_root() + '/' +  combined_yaml_file,
158                        '-j',
159                        get_option('ERROR_MAP_YAML'),
160                        '-t',
161                        'dump_types.mako.hpp',
162                        '-o',
163                        'dump_types.hpp'
164                    ],
165                    depend_files : [ 'dump_types.mako.hpp',
166                                     'map_gen.py',
167                                     meson.build_root() + '/' +  combined_yaml_file,
168                                     get_option('ERROR_MAP_YAML')
169                                   ],
170                    output : 'dump_types.hpp'
171                 )
172
173dump_types_cpp = custom_target(
174                    'dump_types.cpp',
175                    command : [
176                        python,
177                        map_gen_file_loc,
178                        '-i',
179                        meson.build_root() + '/' +  combined_yaml_file,
180                        '-j',
181                        get_option('ERROR_MAP_YAML'),
182                        '-t',
183                        'dump_types.mako.cpp',
184                        '-o',
185                        'dump_types.cpp'
186                    ],
187                    depend_files : [ 'dump_types.mako.cpp',
188                                     'map_gen.py',
189                                     meson.build_root() + '/' +  combined_yaml_file,
190                                     get_option('ERROR_MAP_YAML')
191                                   ],
192                    output : 'dump_types.cpp'
193                 )
194
195phosphor_dump_manager_sources = [
196        'dump_entry.cpp',
197        'dump_manager.cpp',
198        'dump_manager_bmc.cpp',
199        'dump_manager_main.cpp',
200        'dump_serialize.cpp',
201        'elog_watch.cpp',
202        common_hpp,
203        server_hpp,
204        server_cpp,
205        dump_types_hpp,
206        dump_types_cpp,
207        'watch.cpp',
208        'bmc_dump_entry.cpp',
209        'dump_utils.cpp',
210        'dump_offload.cpp',
211        'dump_manager_faultlog.cpp',
212        'faultlog_dump_entry.cpp'
213    ]
214
215phosphor_dump_manager_dependency = [
216        phosphor_dbus_interfaces_dep,
217        sdbusplus_dep,
218        sdeventplus_dep,
219        phosphor_logging_dep,
220        cereal_dep,
221    ]
222
223phosphor_dump_manager_install = true
224
225phosphor_dump_manager_incdir = []
226
227# To get host transport based interface to take respective host
228# dump actions. It will contain required sources and dependency
229# list for phosphor_dump_manager.
230subdir('host-transport-extensions')
231
232#pick any architecture specific dumps
233subdir('dump-extensions')
234
235phosphor_dump_monitor_sources = [
236        dump_types_hpp,
237        'core_manager.cpp',
238        'core_manager_main.cpp',
239        'watch.cpp'
240    ]
241
242phosphor_dump_monitor_dependency = [
243        phosphor_dbus_interfaces_dep,
244        phosphor_logging_dep
245    ]
246
247phosphor_dump_monitor_install = true
248
249phosphor_dump_monitor_incdir = []
250
251phosphor_ramoops_monitor_sources = [
252        dump_types_hpp,
253        'ramoops_manager.cpp',
254        'ramoops_manager_main.cpp',
255        'watch.cpp'
256    ]
257
258phosphor_ramoops_monitor_dependency = [
259        phosphor_dbus_interfaces_dep,
260        phosphor_logging_dep
261    ]
262
263phosphor_ramoops_monitor_install = true
264
265phosphor_ramoops_monitor_incdir = []
266
267executables = [[ 'phosphor-dump-manager',
268                  phosphor_dump_manager_sources,
269                  phosphor_dump_manager_dependency,
270                  phosphor_dump_manager_install,
271                  phosphor_dump_manager_incdir
272               ],
273               [ 'phosphor-dump-monitor',
274                  phosphor_dump_monitor_sources,
275                  phosphor_dump_monitor_dependency,
276                  phosphor_dump_monitor_install,
277                  phosphor_dump_monitor_incdir
278               ],
279               [ 'phosphor-ramoops-monitor',
280                  phosphor_ramoops_monitor_sources,
281                  phosphor_ramoops_monitor_dependency,
282                  phosphor_ramoops_monitor_install,
283                  phosphor_ramoops_monitor_incdir
284               ]
285              ]
286
287foreach executable : executables
288    binary = executable(
289                        executable[0],
290                        executable[1],
291                        dependencies: executable[2],
292                        install : executable[3],
293                        include_directories : executable[4]
294                       )
295endforeach
296
297unit_subs = configuration_data()
298unit_subs.set('bindir', join_paths(get_option('prefix'), get_option('bindir')))
299systemd_system_unit_dir = dependency('systemd').get_variable(
300    'systemdsystemunitdir',
301    pkgconfig_define: ['prefix', get_option('prefix')])
302foreach u : unit_files
303    configure_file(
304        configuration: unit_subs,
305        input: u.get('input'),
306        install: true,
307        install_dir: systemd_system_unit_dir,
308        output: u.get('output')
309    )
310endforeach
311
312if get_option('tests').enabled()
313  subdir('test')
314endif
315