xref: /openbmc/telemetry/meson.build (revision a8182beb)
1project(
2    'Telemetry',
3    'cpp',
4    meson_version: '>=0.57.0',
5    default_options: [
6        'buildtype=debugoptimized',
7        'cpp_std=c++20',
8        # TODO: Without RTTI telemetry does not build using Boost 1.74.0
9        # https://github.com/chriskohlhoff/asio/issues/533
10        #'cpp_rtti=false',
11        'warning_level=3',
12        'werror=true',
13        'b_lto=true',
14    ],
15    license: 'Apache-2.0',
16)
17
18summary({'Fast build with link-time optimizer disabled':
19            not get_option('b_lto')}, section: 'General')
20
21cpp = meson.get_compiler('cpp')
22add_project_arguments(
23    cpp.get_supported_arguments([
24        '-DBOOST_ASIO_DISABLE_THREADS',
25        '-DBOOST_ALL_NO_LIB',
26        '-DBOOST_SYSTEM_NO_DEPRECATED',
27        '-DBOOST_ASIO_NO_DEPRECATED',
28        '-DBOOST_NO_RTTI',
29        '-DBOOST_NO_TYPEID',
30        # TODO: Removed below arg after upgrade to Boost 1.75
31        '-DBOOST_ALLOW_DEPRECATED_HEADERS',
32        '-Wno-unused-parameter',
33    ]),
34    language: 'cpp'
35)
36
37boost = dependency(
38    'boost',
39    version: '>=1.74.0',
40    required: false,
41    modules: ['coroutine'])
42assert(boost.found(),
43       'Missing Boost 1.74.0 or higher, as WA you can set BOOST_ROOT ' +
44       'environemt to point at boost build. To build a boost you can use ' +
45       'script ./scripts/boost_build_1.74.0.sh')
46
47phosphor_logging = dependency('phosphor-logging')
48sdbusplus = dependency('sdbusplus')
49systemd = dependency('systemd')
50
51if cpp.has_header('nlohmann/json.hpp')
52    nlohmann_json = declare_dependency()
53else
54    nlohmann_json = dependency('nlohmann_json')
55endif
56
57add_project_arguments(
58    '-DTELEMETRY_MAX_REPORTS=' + get_option('max-reports').to_string(),
59    '-DTELEMETRY_MAX_READING_PARAMS=' +
60        get_option('max-reading-parameters').to_string(),
61    '-DTELEMETRY_MIN_INTERVAL=' + get_option('min-interval').to_string(),
62    '-DTELEMETRY_MAX_TRIGGERS=' + get_option('max-triggers').to_string(),
63    '-DTELEMETRY_MAX_DBUS_PATH_LENGTH=' +
64        get_option('max-dbus-path-length').to_string(),
65    '-DTELEMETRY_MAX_APPEND_LIMIT=' +
66        get_option('max-append-limit').to_string(),
67    '-DTELEMETRY_MAX_ID_NAME_LENGTH=' + get_option('max-id-name-length').to_string(),
68    '-DTELEMETRY_MAX_PREFIX_LENGTH=' + get_option('max-prefix-length').to_string(),
69    language: 'cpp'
70)
71
72executable(
73    'telemetry',
74    [
75        'src/discrete_threshold.cpp',
76        'src/main.cpp',
77        'src/metric.cpp',
78        'src/metrics/collection_data.cpp',
79        'src/metrics/collection_function.cpp',
80        'src/numeric_threshold.cpp',
81        'src/on_change_threshold.cpp',
82        'src/persistent_json_storage.cpp',
83        'src/report.cpp',
84        'src/report_factory.cpp',
85        'src/report_manager.cpp',
86        'src/sensor.cpp',
87        'src/sensor_cache.cpp',
88        'src/trigger.cpp',
89        'src/trigger_actions.cpp',
90        'src/trigger_factory.cpp',
91        'src/trigger_manager.cpp',
92        'src/types/readings.cpp',
93        'src/types/report_types.cpp',
94        'src/utils/conversion_trigger.cpp',
95        'src/utils/dbus_path_utils.cpp',
96        'src/utils/make_id_name.cpp',
97        'src/utils/messanger_service.cpp',
98    ],
99    dependencies: [
100        boost,
101        nlohmann_json,
102        sdbusplus,
103        phosphor_logging,
104    ],
105    include_directories: 'src',
106    install: true,
107    install_dir: get_option('prefix') / get_option('bindir'),
108    pie: true,
109)
110
111service_wants = ''
112if get_option('service-wants').length() > 0
113    service_wants = '\nWants=' + ' '.join(get_option('service-wants'))
114endif
115
116service_requires = ''
117if get_option('service-requires').length() > 0
118    service_requires = '\nRequires=' + ' '.join(get_option('service-requires'))
119endif
120
121service_before = ''
122if get_option('service-before').length() > 0
123    service_before = '\nBefore=' + ' '.join(get_option('service-before'))
124endif
125
126service_after = ''
127if get_option('service-after').length() > 0
128    service_after = ' ' + ' '.join(get_option('service-after'))
129endif
130
131configure_file(
132    input: 'xyz.openbmc_project.Telemetry.service.in',
133    output: 'xyz.openbmc_project.Telemetry.service',
134    configuration: {
135        'bindir': get_option('prefix') / get_option('bindir'),
136        'wants': service_wants,
137        'requires': service_requires,
138        'before': service_before,
139        'after': service_after
140    },
141    install: true,
142    install_dir: systemd.get_variable(pkgconfig: 'systemdsystemunitdir'),
143)
144
145if get_option('buildtest')
146    subdir('tests')
147endif
148