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