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