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