xref: /openbmc/phosphor-objmgr/meson.build (revision fb853663)
1project(
2    'phosphor-objmgr',
3    'c', 'cpp',
4    default_options: [
5        'buildtype=debugoptimized',
6        'cpp_std=c++23',
7        'warning_level=3',
8        'werror=true',
9    ],
10    license: 'Apache-2.0',
11    meson_version: '>=1.1.1',
12    version: '1.0',
13)
14
15cxx = meson.get_compiler('cpp')
16
17if cxx.has_header('CLI/CLI.hpp')
18    cli11_dep = declare_dependency()
19else
20    cli11_dep = dependency('cli11')
21endif
22phosphor_logging = dependency('phosphor-logging')
23phosphor_dbus_interfaces = dependency('phosphor-dbus-interfaces')
24sdbusplus = dependency('sdbusplus')
25boost = dependency('boost', version : '>=1.79.0', required: false, include_type: 'system')
26if not boost.found()
27  subproject('boost', required: false)
28  boost_inc = include_directories('subprojects/boost_1_79_0/', is_system:true)
29  boost  = declare_dependency(include_directories : boost_inc)
30  boost = boost.as_system('system')
31endif
32
33if get_option('buildtype').startswith('debug')
34    add_project_arguments('-DMAPPER_ENABLE_DEBUG', language : 'cpp')
35endif
36
37if get_option('tests').allowed()
38    gtest = dependency('gtest', main: true, disabler: true, required: false)
39    gmock = dependency('gmock', disabler: true, required: false)
40    if not gtest.found() or not gmock.found()
41        gtest_proj = import('cmake').subproject('googletest', required: false)
42        if gtest_proj.found()
43            gtest = declare_dependency(
44                dependencies: [
45                    dependency('threads'),
46                    gtest_proj.dependency('gtest'),
47                    gtest_proj.dependency('gtest_main'),
48                ]
49            )
50            gmock = gtest_proj.dependency('gmock')
51        else
52            assert(
53                not get_option('tests').allowed(),
54                'Googletest is required if tests are enabled'
55            )
56        endif
57    endif
58    subdir('src/test')
59    subdir('libmapper/test')
60endif
61
62install_headers('libmapper/mapper.h')
63
64libmapper = library(
65    'mapper',
66    'libmapper/mapper.c',
67    dependencies: [ dependency('libsystemd') ],
68    gnu_symbol_visibility: 'hidden',
69    version: meson.project_version(),
70    install: true)
71
72mapper_dep = declare_dependency(
73    link_with: libmapper,
74    include_directories: include_directories('libmapper'),
75    dependencies: [ dependency('libsystemd') ],
76)
77
78import('pkgconfig').generate(
79    name: 'libmapper',
80    description: 'OpenBMC service discovery utility library',
81    version: meson.project_version(),
82    libraries: libmapper)
83
84executable(
85    'mapper',
86    'libmapper/app.c',
87    link_with: libmapper,
88    dependencies: [ dependency('libsystemd') ],
89    install: true)
90
91mapperx = executable(
92    'mapperx',
93    [
94        'src/main.cpp',
95        'src/processing.cpp',
96        'src/associations.cpp',
97        'src/handler.cpp',
98    ],
99    dependencies: [
100        boost,
101        dependency('libsystemd'),
102        phosphor_dbus_interfaces,
103        phosphor_logging,
104        sdbusplus,
105        dependency('systemd'),
106        dependency('threads'),
107        dependency('tinyxml2', default_options: ['tests=false']),
108    ],
109    install: true,
110    install_dir: join_paths(
111        get_option('prefix'), get_option('libexecdir'), meson.project_name())
112)
113meson.override_find_program('mapperx', mapperx)
114
115systemd_system_unit_dir = dependency('systemd').get_variable(
116    'systemdsystemunitdir'
117)
118
119conf = configuration_data()
120conf.set('BINDIR', join_paths(get_option('prefix'), get_option('bindir')))
121conf.set('LIBEXECDIR', join_paths(
122    get_option('prefix'), get_option('libexecdir')))
123
124unit_files = [
125    'xyz.openbmc_project.ObjectMapper.service',
126    'mapper-subtree-remove@.service',
127    'mapper-wait@.service'
128]
129
130foreach u : unit_files
131    configure_file(
132        configuration: conf,
133        input : join_paths('src/systemd', u) + '.in',
134        install : true,
135        install_dir: systemd_system_unit_dir,
136        output : u
137    )
138endforeach
139
140dbus_system_bus_services_dir = dependency('dbus-1').get_variable(
141    'system_bus_services_dir',
142    pkgconfig_define: ['prefix', get_option('prefix')]
143)
144
145install_data(
146    'src/dbus/xyz.openbmc_project.ObjectMapper.service',
147    install_dir: dbus_system_bus_services_dir)
148
149install_data(
150    'src/dbus/xyz.openbmc_project.ObjectMapper.conf',
151    install_dir: get_option('datadir') / 'dbus-1' / 'system.d')
152
153if not get_option('unit-failure-monitor').disabled()
154    executable(
155        'phosphor-unit-failure-monitor',
156        [
157            'fail-monitor/main.cpp',
158            'fail-monitor/monitor.cpp',
159        ],
160        dependencies: [
161            cli11_dep,
162            phosphor_logging,
163        ],
164        install: true
165    )
166endif
167