1# SPDX-License-Identifier: Apache-2.0
2
3project('phosphor-debug-collector',
4        'cpp',
5        meson_version: '>= 0.57.0',
6        default_options: [
7                          'cpp_std=c++20',
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')
30
31phosphor_dbus_interfaces_dep = dependency('phosphor-dbus-interfaces')
32phosphor_logging_dep = dependency('phosphor-logging')
33
34fmt_dep = dependency('fmt', required: false)
35if not fmt_dep.found()
36  fmt_proj = import('cmake').subproject(
37    'fmt',
38    cmake_options: [
39      '-DCMAKE_POSITION_INDEPENDENT_CODE=ON',
40      '-DMASTER_PROJECT=OFF'
41    ],
42    required: false)
43  assert(fmt_proj.found(), 'fmtlib is required')
44  fmt_dep = fmt_proj.dependency('fmt')
45endif
46
47# Get Cereal dependency.
48cereal_dep = dependency('cereal', required: false)
49has_cereal = cpp.has_header_symbol(
50    'cereal/cereal.hpp',
51    'cereal::specialize',
52    dependencies: cereal_dep,
53    required: false)
54if not has_cereal
55    cereal_opts = import('cmake').subproject_options()
56    cereal_opts.add_cmake_defines({'BUILD_TESTS': 'OFF'})
57    cereal_proj = import('cmake').subproject(
58        'cereal',
59        options: cereal_opts,
60        required: false)
61    assert(cereal_proj.found(), 'cereal is required')
62    cereal_dep = cereal_proj.dependency('cereal')
63endif
64
65# Disable FORTIFY_SOURCE when compiling with no optimization
66if(get_option('optimization') == '0')
67  add_project_arguments('-U_FORTIFY_SOURCE',language:['cpp','c'])
68  message('Disabling FORTIFY_SOURCE as optimization is set to 0')
69endif
70
71# Configuration header file(config.h) generation
72
73conf_data = configuration_data()
74
75conf_data.set_quoted('DUMP_BUSNAME', get_option('DUMP_BUSNAME'),
76                      description : 'The Dbus busname to own'
77                    )
78conf_data.set_quoted('DUMP_OBJPATH', get_option('DUMP_OBJPATH'),
79                      description : 'The Dump manager Dbus root'
80                    )
81conf_data.set_quoted('BMC_DUMP_OBJPATH', get_option('BMC_DUMP_OBJPATH'),
82                      description : 'The BMC Dump manager Dbus path'
83                    )
84conf_data.set_quoted('CORE_FILE_DIR', get_option('CORE_FILE_DIR'),
85                      description : 'Directory where core dumps are placed'
86                    )
87conf_data.set_quoted('OBJ_INTERNAL', get_option('OBJ_INTERNAL'),
88                      description : 'Internal Dump manager Dbus object path'
89                    )
90conf_data.set_quoted('BMC_DUMP_OBJ_ENTRY', get_option('BMC_DUMP_OBJ_ENTRY'),
91                      description : 'The BMC dump entry DBus object path'
92                    )
93conf_data.set_quoted('BMC_DUMP_PATH', get_option('BMC_DUMP_PATH'),
94                     description : 'Directory where bmc dumps are placed')
95conf_data.set_quoted('SYSTEMD_PSTORE_PATH', get_option('SYSTEMD_PSTORE_PATH'),
96                     description : 'Path to the systemd pstore directory')
97conf_data.set('BMC_DUMP_MAX_SIZE', get_option('BMC_DUMP_MAX_SIZE'),
98               description : 'Maximum size of one bmc dump in kilo bytes'
99             )
100conf_data.set('BMC_DUMP_MIN_SPACE_REQD', get_option('BMC_DUMP_MIN_SPACE_REQD'),
101               description : 'Minimum space required for one bmc dump in kilo bytes'
102             )
103conf_data.set('BMC_DUMP_TOTAL_SIZE', get_option('BMC_DUMP_TOTAL_SIZE'),
104               description : 'Total size of the dump in kilo bytes'
105             )
106conf_data.set_quoted('OBJ_LOGGING', '/xyz/openbmc_project/logging',
107                      description : 'The log manager DBus object path'
108                    )
109conf_data.set_quoted('ELOG_ID_PERSIST_PATH', get_option('ELOG_ID_PERSIST_PATH'),
110                      description : 'Path of file for storing elog id\'s, which have associated dumps'
111                    )
112conf_data.set('CLASS_VERSION', get_option('CLASS_VERSION'),
113               description : 'Class version to register with Cereal'
114             )
115conf_data.set('ERROR_MAP_YAML', get_option('ERROR_MAP_YAML'),
116               description : 'YAML filepath containing error object paths'
117             )
118conf_data.set('JFFS_CORE_FILE_WORKAROUND', get_option('jffs-workaround').enabled(),
119               description : 'Turn on jffs workaround for core file'
120             )
121conf_data.set_quoted('FAULTLOG_DUMP_OBJ_ENTRY', get_option('FAULTLOG_DUMP_OBJ_ENTRY'),
122                      description : 'The Fault Log dump entry DBus object path'
123                    )
124conf_data.set_quoted('FAULTLOG_DUMP_OBJPATH', get_option('FAULTLOG_DUMP_OBJPATH'),
125                      description : 'The Fault Log Dump manager Dbus path'
126                    )
127conf_data.set_quoted('FAULTLOG_DUMP_PATH', get_option('FAULTLOG_DUMP_PATH'),
128                      description : 'Directory where fault logs are placed'
129                    )
130conf_data.set('BMC_DUMP_ROTATE_CONFIG', get_option('dump_rotate_config').enabled(),
131               description : 'Turn on rotate config for bmc dump'
132             )
133
134configure_file(configuration : conf_data,
135               output : 'config.h'
136              )
137
138subdir('xyz/openbmc_project/Dump/Internal/Create')
139
140python = find_program('python3')
141errors_map_gen_file_loc = meson.project_source_root()
142errors_map_gen_file_loc += '/errors_map_gen.py'
143
144errors_map_hpp = custom_target(
145                    'errors_map.hpp',
146                    command : [
147                        python,
148                        errors_map_gen_file_loc,
149                        '-i',
150                        get_option('ERROR_MAP_YAML')
151                    ],
152                    depend_files : [ 'errors_map.mako.hpp',
153                                     'errors_map_gen.py',
154                                     get_option('ERROR_MAP_YAML')
155                                   ],
156                    output : 'errors_map.hpp'
157                 )
158
159phosphor_dump_manager_sources = [
160        'dump_entry.cpp',
161        'dump_manager.cpp',
162        'dump_manager_bmc.cpp',
163        'dump_manager_main.cpp',
164        'dump_serialize.cpp',
165        'elog_watch.cpp',
166        errors_map_hpp,
167        server_hpp,
168        server_cpp,
169        'watch.cpp',
170        'bmc_dump_entry.cpp',
171        'dump_utils.cpp',
172        'dump_offload.cpp',
173        'dump_manager_faultlog.cpp',
174        'faultlog_dump_entry.cpp',
175    ]
176
177phosphor_dump_manager_dependency = [
178        phosphor_dbus_interfaces_dep,
179        sdbusplus_dep,
180        phosphor_logging_dep,
181        fmt_dep,
182        cereal_dep,
183    ]
184
185phosphor_dump_manager_install = true
186
187phosphor_dump_manager_incdir = []
188
189# To get host transport based interface to take respective host
190# dump actions. It will contain required sources and dependency
191# list for phosphor_dump_manager.
192subdir('host-transport-extensions')
193
194#pick any architecture specific dumps
195subdir('dump-extensions')
196
197phosphor_dump_monitor_sources = [
198        'core_manager.cpp',
199        'core_manager_main.cpp',
200        'watch.cpp'
201    ]
202
203phosphor_dump_monitor_dependency = [
204        phosphor_dbus_interfaces_dep,
205        phosphor_logging_dep,
206        fmt_dep
207    ]
208
209phosphor_dump_monitor_install = true
210
211phosphor_dump_monitor_incdir = []
212
213phosphor_ramoops_monitor_sources = [
214        'ramoops_manager.cpp',
215        'ramoops_manager_main.cpp',
216        'watch.cpp'
217    ]
218
219phosphor_ramoops_monitor_dependency = [
220        phosphor_dbus_interfaces_dep,
221        phosphor_logging_dep,
222        fmt_dep
223    ]
224
225phosphor_ramoops_monitor_install = true
226
227phosphor_ramoops_monitor_incdir = []
228
229executables = [[ 'phosphor-dump-manager',
230                  phosphor_dump_manager_sources,
231                  phosphor_dump_manager_dependency,
232                  phosphor_dump_manager_install,
233                  phosphor_dump_manager_incdir
234               ],
235               [ 'phosphor-dump-monitor',
236                  phosphor_dump_monitor_sources,
237                  phosphor_dump_monitor_dependency,
238                  phosphor_dump_monitor_install,
239                  phosphor_dump_monitor_incdir
240               ],
241               [ 'phosphor-ramoops-monitor',
242                  phosphor_ramoops_monitor_sources,
243                  phosphor_ramoops_monitor_dependency,
244                  phosphor_ramoops_monitor_install,
245                  phosphor_ramoops_monitor_incdir
246               ]
247              ]
248
249foreach executable : executables
250    binary = executable(
251                        executable[0],
252                        executable[1],
253                        dependencies: executable[2],
254                        install : executable[3],
255                        include_directories : executable[4]
256                       )
257endforeach
258
259unit_subs = configuration_data()
260unit_subs.set('bindir', join_paths(get_option('prefix'), get_option('bindir')))
261systemd_system_unit_dir = dependency('systemd').get_pkgconfig_variable(
262    'systemdsystemunitdir',
263    define_variable: ['prefix', get_option('prefix')])
264foreach u : unit_files
265    configure_file(
266        configuration: unit_subs,
267        input: u.get('input'),
268        install: true,
269        install_dir: systemd_system_unit_dir,
270        output: u.get('output')
271    )
272endforeach
273
274if get_option('tests').enabled()
275  subdir('test')
276endif
277