xref: /openbmc/phosphor-logging/meson.build (revision 8bcadac7)
1project('phosphor-logging', 'cpp',
2    meson_version: '>= 0.57.0',
3    default_options: [
4      'buildtype=debugoptimized',
5      'cpp_std=c++20',
6      'warning_level=3',
7      'werror=true',
8      'tests=' + (meson.is_subproject() ? 'disabled' : 'auto'),
9    ],
10    version: '1.0.0',
11)
12
13cpp = meson.get_compiler('cpp')
14python_prog = find_program('python3')
15
16# Get sdbusplus dependency.
17sdbusplus_dep = dependency('sdbusplus', required: false)
18if sdbusplus_dep.found()
19    sdbusplusplus_prog = find_program('sdbus++')
20    sdbuspp_gen_meson_prog = find_program('sdbus++-gen-meson')
21else
22    sdbusplus_proj = subproject('sdbusplus', required: true)
23    sdbusplus_dep = sdbusplus_proj.get_variable('sdbusplus_dep')
24    sdbusplusplus_prog = sdbusplus_proj.get_variable('sdbusplusplus_prog')
25    sdbuspp_gen_meson_prog = sdbusplus_proj.get_variable(
26        'sdbuspp_gen_meson_prog'
27    )
28endif
29
30# Get PDI and sdeventplus dependency.
31pdi_vars = []
32if not get_option('openpower-pel-extension').disabled()
33    pdi_vars += [ 'data_org_open_power=true' ]
34endif
35pdi_dep = dependency(
36    'phosphor-dbus-interfaces',
37    fallback: ['phosphor-dbus-interfaces', 'phosphor_dbus_interfaces_dep'],
38    default_options: pdi_vars,
39)
40sdeventplus_dep = dependency(
41    'sdeventplus',
42    fallback: ['sdeventplus', 'sdeventplus_dep' ],
43)
44
45# Get Cereal dependency.
46cereal_dep = dependency('cereal', required: false)
47has_cereal = cpp.has_header_symbol(
48    'cereal/cereal.hpp',
49    'cereal::specialize',
50    dependencies: cereal_dep,
51    required: false)
52if not has_cereal
53    cereal_opts = import('cmake').subproject_options()
54    cereal_opts.add_cmake_defines({'BUILD_TESTS': 'OFF'})
55    cereal_proj = import('cmake').subproject(
56        'cereal',
57        options: cereal_opts,
58        required: false)
59    assert(cereal_proj.found(), 'cereal is required')
60    cereal_dep = cereal_proj.get_variable('cm_cereal_dep')
61endif
62
63# Find the installed YAML directory, either from a configure option or
64# by pulling it from the PDI dependency.
65yamldir = get_option('yamldir')
66if yamldir == ''
67    yamldir = pdi_dep.get_variable(pkgconfig: 'yamldir', internal: 'yamldir')
68endif
69
70# Create config.h with constants that use to come from autoconf.
71conf_data = configuration_data()
72conf_data.set('error_cap', get_option('error_cap'))
73conf_data.set('error_info_cap', get_option('error_info_cap'))
74conf_data.set('rsyslog_server_conf', get_option('rsyslog_server_conf'))
75
76configure_file(
77    input: 'config.h.meson',
78    output: 'config.h',
79    configuration: conf_data,
80)
81
82# Generate sdbus++ files.
83generated_sources = []
84generated_others = []
85subdir('gen')
86subdir('gen/xyz')
87
88# Generate callouts-gen.hpp.
89callouts_gen = custom_target('callouts-gen.hpp'.underscorify(),
90    input: [
91        'callouts/callouts.py',
92        'callouts/callouts-gen.mako.hpp',
93        get_option('callout_yaml'),
94    ],
95    output: 'callouts-gen.hpp',
96    command: [ python_prog, '@INPUT0@', '-i', '@INPUT2@', '-o', '@OUTPUT0@' ],
97)
98# Generate elog-lookup.cpp
99elog_lookup_gen = custom_target('elog-lookup.cpp'.underscorify(),
100    input: files(
101        'tools/elog-gen.py',
102        'tools/phosphor-logging/templates/elog-lookup-template.mako.cpp',
103    ),
104    output: 'elog-lookup.cpp',
105    command: [
106        python_prog, '@INPUT0@',
107        '-t', '',
108        '-m', '@INPUT1@',
109        '-y', yamldir,
110        '-u', meson.current_source_dir() / '../tools/',
111        '-o', '@OUTPUT0@',
112    ],
113)
114# Generate elog-process-metadata.cpp
115elog_process_gen = custom_target('elog-process-metadata.cpp'.underscorify(),
116    input: files(
117        'tools/elog-gen.py',
118        'tools/phosphor-logging/templates/elog-process-metadata.mako.cpp',
119    ),
120    output: 'elog-process-metadata.cpp',
121    command: [
122        python_prog, '@INPUT0@',
123        '-t', '',
124        '-m', '@INPUT1@',
125        '-y', yamldir,
126        '-u', meson.current_source_dir() / '../tools/',
127        '-o', '@OUTPUT0@',
128    ],
129)
130
131# Install elog-gen.py and its template for others to use
132install_data('tools/elog-gen.py',
133    install_dir : get_option('datadir') / 'phosphor-logging/elog/tools'
134)
135
136install_data('tools/phosphor-logging/templates/elog-gen-template.mako.hpp',
137    install_dir : get_option('datadir') /
138        'phosphor-logging/elog/tools/phosphor-logging/templates'
139)
140
141subdir('phosphor-logging')
142
143log_manager_ext_sources = []
144log_manager_ext_deps = []
145
146subdir('extensions')
147subdir('phosphor-rsyslog-config')
148
149# Build libphosphor-logging.
150libphosphor_logging = library(
151    'phosphor_logging',
152    files(
153        'elog.cpp',
154        'elog_meta.cpp',
155        'sdjournal.cpp',
156    ),
157    callouts_gen,
158    elog_errors_gen,
159    dependencies: [ sdbusplus_dep, pdi_dep, sdeventplus_dep ],
160    version: meson.project_version(),
161    install: true,
162)
163
164import('pkgconfig').generate(
165    libphosphor_logging,
166    name: meson.project_name(),
167    version: meson.project_version(),
168    requires: [
169        'libsystemd',
170        'phosphor-dbus-interfaces',
171        'sdbusplus',
172    ],
173    description: 'Phosphor logging utilities',
174)
175
176# Create dependency for use as subproject.
177phosphor_logging_dep = declare_dependency(
178    include_directories: include_directories('.'),
179    link_with: libphosphor_logging,
180    sources: [ callouts_gen, elog_errors_gen ],
181    dependencies: [ sdbusplus_dep, pdi_dep, sdeventplus_dep],
182)
183
184# Generate daemon.
185log_manager_sources = [
186    generated_sources,
187    elog_errors_gen,
188    elog_lookup_gen,
189    elog_process_gen,
190    files(
191        'elog_entry.cpp',
192        'elog_meta.cpp',
193        'elog_serialize.cpp',
194        'extensions.cpp',
195        'log_manager.cpp',
196        'sdjournal.cpp',
197        'util.cpp',
198    )
199]
200log_manager_deps = [
201    cereal_dep,
202    pdi_dep,
203    sdbusplus_dep,
204    sdeventplus_dep,
205]
206executable('phosphor-log-manager',
207    log_manager_sources,
208    log_manager_ext_sources,
209    'log_manager_main.cpp',
210    include_directories: include_directories('gen'),
211    link_with: libphosphor_logging,
212    dependencies: [
213        log_manager_deps,
214        log_manager_ext_deps,
215    ],
216    install: true,
217)
218# Generate test executables which run in obmc env (qemu, real hardware).
219executable('logging-test',
220    'logging_test.cpp',
221    link_with: libphosphor_logging,
222    dependencies: [
223        elog_errors_dep,
224        pdi_dep,
225        sdbusplus_dep,
226    ],
227    install: true,
228)
229executable('callout-test',
230    'callouts/callout_test.cpp',
231    link_with: libphosphor_logging,
232    dependencies: [
233        elog_errors_dep,
234        pdi_dep,
235        sdbusplus_dep,
236        sdeventplus_dep,
237    ],
238    install: true,
239)
240
241subdir('dist')
242
243if not get_option('tests').disabled()
244    subdir('test')
245endif
246