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