xref: /openbmc/phosphor-objmgr/meson.build (revision 9d2c63445cae145ae0cb7baab3f6b65d5040dfe5)
1project(
2    'phosphor-objmgr',
3    'c',
4    'cpp',
5    default_options: [
6        'buildtype=debugoptimized',
7        'cpp_std=c++23',
8        'warning_level=3',
9        'werror=true',
10    ],
11    license: 'Apache-2.0',
12    meson_version: '>=1.1.1',
13    version: '1.0',
14)
15
16cxx = meson.get_compiler('cpp')
17
18boost_flags = []
19if (cxx.get_id() == 'clang')
20    if (cxx.version().version_compare('<18.0'))
21        error('This project requires clang-18 or higher')
22    endif
23    add_project_arguments(
24# https://github.com/llvm/llvm-project/issues/101614
25        '-fno-builtin-std-forward_like',
26        language: 'cpp',
27    )
28    boost_flags += ['-Wno-strict-prototypes']
29endif
30
31if (cxx.get_id() == 'gcc')
32    if (cxx.version().version_compare('<13.0'))
33        error('This project requires gcc-13 or higher')
34    endif
35
36    add_project_arguments(
37        '-Wformat=2',
38        '-Wcast-align',
39        '-Wconversion',
40        '-Woverloaded-virtual',
41        '-Wsign-conversion',
42        '-Wunused',
43        '-Wduplicated-cond',
44        '-Wduplicated-branches',
45        '-Wlogical-op',
46        '-Wunused-parameter',
47        '-Wdouble-promotion',
48        '-Wshadow',
49        language: 'cpp',
50    )
51endif
52
53# Enable debugging for debug builds
54if get_option('buildtype').startswith('debug')
55    add_project_arguments('-DMAPPER_ENABLE_DEBUG', language: 'cpp')
56endif
57
58# Boost configuration
59add_project_arguments(
60    ['-DBOOST_ASIO_DISABLE_THREADS', '-DBOOST_ASIO_NO_DEPRECATED'],
61    language: 'cpp',
62)
63
64cli11 = dependency('CLI11', required: false, include_type: 'system')
65if not cli11.found()
66    cli11_proj = subproject('CLI11', required: true)
67    cli11 = cli11_proj.get_variable('CLI11_dep')
68    cli11 = cli11.as_system('system')
69endif
70
71phosphor_logging = dependency('phosphor-logging')
72phosphor_dbus_interfaces = dependency('phosphor-dbus-interfaces')
73sdbusplus = dependency('sdbusplus')
74boost = dependency(
75    'boost',
76    version: '>=1.87.0',
77    required: false,
78    include_type: 'system',
79)
80if not boost.found()
81    cmake = import('cmake')
82    opt = cmake.subproject_options()
83    boost_libs = ['asio', 'callable_traits']
84    opt.add_cmake_defines(
85        {
86            'CMAKE_CXX_FLAGS': ' '.join(boost_flags),
87            'CMAKE_C_FLAGS': ' '.join(boost_flags),
88            'BOOST_INCLUDE_LIBRARIES': ';'.join(boost_libs),
89        },
90    )
91
92    boost_deps = []
93    boost_proj = cmake.subproject('boost', required: true, options: opt)
94    foreach boost_lib : boost_libs
95        boost_lib_instance = boost_proj.dependency('boost_' + boost_lib).as_system()
96        boost_deps += [boost_lib_instance]
97    endforeach
98    boost = declare_dependency(dependencies: boost_deps)
99endif
100
101if get_option('tests').allowed()
102    gtest = dependency(
103        'gtest_main',
104        main: true,
105        version: '>=1.15.2',
106        required: true,
107    )
108    gmock = dependency('gmock', required: true)
109    subdir('src/test')
110    subdir('libmapper/test')
111endif
112
113install_headers('libmapper/mapper.h')
114
115libmapper = library(
116    'mapper',
117    'libmapper/mapper.c',
118    dependencies: [dependency('libsystemd')],
119    gnu_symbol_visibility: 'hidden',
120    version: meson.project_version(),
121    install: true,
122)
123
124mapper_dep = declare_dependency(
125    link_with: libmapper,
126    include_directories: include_directories('libmapper'),
127    dependencies: [dependency('libsystemd')],
128)
129
130import('pkgconfig').generate(
131    name: 'libmapper',
132    description: 'OpenBMC service discovery utility library',
133    version: meson.project_version(),
134    libraries: libmapper,
135)
136
137executable(
138    'mapper',
139    'libmapper/app.c',
140    link_with: libmapper,
141    dependencies: [dependency('libsystemd')],
142    install: true,
143)
144
145mapperx = executable(
146    'mapperx',
147    [
148        'src/main.cpp',
149        'src/processing.cpp',
150        'src/associations.cpp',
151        'src/handler.cpp',
152    ],
153    dependencies: [
154        boost,
155        dependency('libsystemd'),
156        phosphor_dbus_interfaces,
157        sdbusplus,
158        dependency('threads'),
159        dependency('tinyxml2', default_options: ['tests=false']),
160    ],
161    implicit_include_directories: false,
162    install: true,
163    install_dir: join_paths(
164        get_option('prefix'),
165        get_option('libexecdir'),
166        meson.project_name(),
167    ),
168)
169meson.override_find_program('mapperx', mapperx)
170
171systemd_system_unit_dir = dependency('systemd').get_variable(
172    'systemd_system_unit_dir',
173)
174
175conf = configuration_data()
176conf.set('BINDIR', join_paths(get_option('prefix'), get_option('bindir')))
177conf.set(
178    'LIBEXECDIR',
179    join_paths(get_option('prefix'), get_option('libexecdir')),
180)
181
182unit_files = [
183    'xyz.openbmc_project.ObjectMapper.service',
184    'mapper-subtree-remove@.service',
185    'mapper-wait@.service',
186]
187
188foreach u : unit_files
189    configure_file(
190        configuration: conf,
191        input: join_paths('src/systemd', u) + '.in',
192        install: true,
193        install_dir: systemd_system_unit_dir,
194        output: u,
195    )
196endforeach
197
198dbus_system_bus_services_dir = dependency('dbus-1').get_variable(
199    'system_bus_services_dir',
200    pkgconfig_define: ['prefix', get_option('prefix')],
201)
202
203install_data(
204    'src/dbus/xyz.openbmc_project.ObjectMapper.service',
205    install_dir: dbus_system_bus_services_dir,
206)
207
208install_data(
209    'src/dbus/xyz.openbmc_project.ObjectMapper.conf',
210    install_dir: get_option('datadir') / 'dbus-1' / 'system.d',
211)
212
213if not get_option('unit-failure-monitor').disabled()
214    executable(
215        'phosphor-unit-failure-monitor',
216        ['fail-monitor/main.cpp', 'fail-monitor/monitor.cpp'],
217        dependencies: [cli11, phosphor_logging, sdbusplus],
218        implicit_include_directories: false,
219        install: true,
220    )
221endif
222