xref: /openbmc/phosphor-power/meson.build (revision 8b38b177315d40f1f9bc1e4d0784d45ea17cbd5c)
1project(
2    'phosphor-power',
3    'cpp',
4    default_options: [
5        'warning_level=3',
6        'werror=true',
7        'cpp_std=c++23',
8        'buildtype=debugoptimized',
9        'prefix=/usr',
10    ],
11    license: 'Apache-2.0',
12    version: '1.0',
13    meson_version: '>=1.1.1',
14)
15
16cxx = meson.get_compiler('cpp')
17
18# Check if the compiler is Clang
19if meson.get_compiler('cpp').get_id() == 'clang'
20    add_global_arguments('-Wno-defaulted-function-deleted', language: 'cpp')
21endif
22
23add_project_arguments(
24    cxx.get_supported_arguments(
25        [
26            '-DBOOST_ALL_NO_LIB',
27            '-DBOOST_ASIO_DISABLE_THREADS',
28            '-DBOOST_ASIO_NO_DEPRECATED',
29        ],
30    ),
31    language: 'cpp',
32)
33
34build_tests = get_option('tests')
35
36if get_option('oe-sdk').allowed()
37    # Setup OE SYSROOT
38    OECORE_TARGET_SYSROOT = run_command(
39        'sh',
40        '-c',
41        'echo $OECORE_TARGET_SYSROOT',
42    ).stdout().strip()
43    if OECORE_TARGET_SYSROOT == ''
44        error('Unable to get $OECORE_TARGET_SYSROOT, check your environment.')
45    endif
46    message('OE_SYSROOT: ' + OECORE_TARGET_SYSROOT)
47    rpath = ':'.join(
48        [OECORE_TARGET_SYSROOT + '/lib', OECORE_TARGET_SYSROOT + '/usr/lib'],
49    )
50    ld_so = run_command(
51        'sh',
52        '-c',
53        'find ' + OECORE_TARGET_SYSROOT + '/lib/ld-*.so | sort -r -n | head -n1',
54    ).stdout().strip()
55    dynamic_linker = ['-Wl,-dynamic-linker,' + ld_so]
56else
57    dynamic_linker = []
58endif
59
60
61gmock = dependency('gmock', disabler: true, required: false)
62gtest = dependency('gtest', main: true, disabler: true, required: false)
63if (not gtest.found() or not gmock.found()) and build_tests.allowed()
64    gtest_opts = import('cmake').subproject_options()
65    gtest_opts.add_cmake_defines({'BUILD_SHARED_LIBS': 'ON'})
66    gtest_proj = import('cmake').subproject(
67        'googletest',
68        options: gtest_opts,
69        required: false,
70    )
71    if gtest_proj.found()
72        gtest = declare_dependency(
73            dependencies: [
74                dependency('threads'),
75                gtest_proj.dependency('gtest'),
76                gtest_proj.dependency('gtest_main'),
77            ],
78        )
79        gmock = gtest_proj.dependency('gmock')
80    else
81        assert(false, 'Googletest is required if tests are enabled')
82    endif
83endif
84
85
86
87phosphor_dbus_interfaces = dependency('phosphor-dbus-interfaces')
88phosphor_logging = dependency('phosphor-logging')
89prog_python = import('python').find_installation('python3')
90sdbusplus = dependency('sdbusplus')
91sdbuspp = find_program('sdbus++')
92sdeventplus = dependency('sdeventplus')
93pthread = dependency('threads')
94stdplus = dependency('stdplus')
95boost = dependency('boost')
96libgpiodcxx = dependency(
97    'libgpiodcxx',
98    default_options: ['bindings=cxx'],
99    version: '<1.7.0',
100)
101
102nlohmann_json_dep = dependency('nlohmann_json', include_type: 'system')
103
104if cxx.has_header('CLI/CLI.hpp')
105    cli11_dep = declare_dependency()
106else
107    cli11_dep = dependency('CLI11')
108endif
109
110systemd = dependency('systemd')
111libsystemd_dep = dependency('libsystemd')
112servicedir = systemd.get_variable('systemd_system_unit_dir')
113
114services = [
115    ['supply-monitor', 'power-supply-monitor@.service'],
116    ['sequencer-monitor', 'pseq-monitor-pgood.service'],
117    ['sequencer-monitor', 'pseq-monitor.service'],
118    ['supply-monitor-ng', 'phosphor-psu-monitor.service'],
119    ['regulators', 'phosphor-regulators.service'],
120    ['regulators', 'phosphor-regulators-config.service'],
121    ['regulators', 'phosphor-regulators-monitor-enable.service'],
122    ['regulators', 'phosphor-regulators-monitor-disable.service'],
123    ['power-control', 'phosphor-power-control.service'],
124]
125
126fs = import('fs')
127foreach service : services
128    if get_option(service[0])
129        fs.copyfile(
130            'services/' + service[1],
131            install: true,
132            install_dir: servicedir,
133        )
134    endif
135endforeach
136
137# Get the power sequencer class name
138sequencer = get_option('power_sequencer')
139if sequencer == 'ucd90160'
140    sequencer_class = 'UCD90160'
141elif sequencer == 'mihawk-cpld'
142    sequencer_class = 'MihawkCPLD'
143else
144    # power sequencer is incorrect
145    error('power sequencer is incorrect')
146endif
147
148conf = configuration_data()
149conf.set_quoted(
150    'INPUT_HISTORY_BUSNAME_ROOT',
151    get_option('input-history-busname-root'),
152)
153conf.set_quoted(
154    'INPUT_HISTORY_SENSOR_ROOT',
155    get_option('input-history-sensor-root'),
156)
157conf.set_quoted('INPUT_HISTORY_SYNC_GPIO', get_option('input-history-sync-gpio'))
158conf.set_quoted('PSU_JSON_PATH', '/usr/share/phosphor-power/psu.json')
159conf.set('SEQUENCER', sequencer_class)
160conf.set10('DEVICE_ACCESS', get_option('device-access'))
161conf.set10('IBM_VPD', get_option('ibm-vpd'))
162conf.set('PGOOD_TIMEOUT', get_option('pgood-timeout-value'))
163
164configure_file(output: 'config.h', configuration: conf)
165
166# Ensure the generated header here winds up in the correct path in the build
167# tree such that it actually get used and doesn't get found in the sysroot
168# somewhere.  Meson doesn't allow path elements (rightfully so) when specifying
169# the output filename of a target definition so the target must be defined in
170# the directory where the artifacts need to be placed.  Do that now, because
171# the generated source (cpp) is needed to define the library target.
172subdir('org/open_power/Witherspoon/Fault')
173
174libpower = static_library(
175    'power',
176    error_cpp,
177    error_hpp,
178    'compatible_system_types_finder.cpp',
179    'dbus_interfaces_finder.cpp',
180    'gpio.cpp',
181    'pmbus.cpp',
182    'temporary_file.cpp',
183    'temporary_subdirectory.cpp',
184    'utility.cpp',
185    dependencies: [
186        nlohmann_json_dep,
187        phosphor_dbus_interfaces,
188        phosphor_logging,
189        sdbusplus,
190        sdeventplus,
191    ],
192)
193
194libpower_inc = include_directories('.')
195
196# Build the tools/i2c sub-directory first.  Other sub-directories depend on
197# Meson variables defined there.
198subdir('tools/i2c')
199
200if get_option('regulators')
201    subdir('phosphor-regulators')
202endif
203if get_option('sequencer-monitor')
204    subdir('power-sequencer')
205endif
206if get_option('power-control')
207    subdir('phosphor-power-sequencer')
208endif
209if get_option('supply-monitor')
210    subdir('power-supply')
211endif
212if get_option('supply-monitor-ng')
213    subdir('phosphor-power-supply')
214endif
215if get_option('utils')
216    subdir('tools/power-utils')
217endif
218if get_option('tests').allowed()
219    subdir('test')
220endif
221if get_option('cold-redundancy')
222    subdir('cold-redundancy')
223endif
224