George Liu | bddcf85 | 2021-09-08 08:46:22 +0800 | [diff] [blame] | 1 | project( |
| 2 | 'openpower-occ-control', 'cpp', |
| 3 | version : '1.0.0', |
| 4 | meson_version: '>=0.57.0', |
| 5 | default_options: [ |
| 6 | 'warning_level=3', |
| 7 | 'werror=true', |
| 8 | 'cpp_std=c++20', |
| 9 | 'buildtype=debugoptimized' |
| 10 | ] |
| 11 | ) |
| 12 | |
| 13 | conf_data = configuration_data() |
| 14 | conf_data.set_quoted('OCC_CONTROL_BUSNAME', 'org.open_power.OCC.Control') |
| 15 | conf_data.set_quoted('OCC_CONTROL_ROOT', '/org/open_power/control') |
| 16 | conf_data.set_quoted('OCC_SENSORS_ROOT', '/xyz/openbmc_project/sensors') |
| 17 | conf_data.set_quoted('CPU_NAME', 'cpu') |
| 18 | conf_data.set_quoted('OCC_NAME', 'occ') |
| 19 | conf_data.set_quoted('OCC_MASTER_NAME', 'occ-hwmon.1') |
| 20 | conf_data.set_quoted('OCC_DEV_PATH', '/dev/occ') |
| 21 | conf_data.set_quoted('CPU_SUBPATH', '/xyz/openbmc_project/inventory/system/chassis/motherboard') |
| 22 | |
| 23 | conf_data.set('MAX_CPUS', get_option('max-cpus')) |
| 24 | conf_data.set('OCC_CPU_TEMP_SENSOR_TYPE', 0xC0) |
| 25 | conf_data.set('OCC_DIMM_TEMP_SENSOR_TYPE', 0xD0) |
| 26 | conf_data.set('PS_DERATING_FACTOR', 90) |
| 27 | |
| 28 | if get_option('i2c-occ').enabled() |
| 29 | conf_data.set_quoted('OCC_HWMON_PATH', '/sys/bus/i2c/drivers/occ-hwmon/') |
| 30 | conf_data.set_quoted('DEV_PATH', '/sys/bus/i2c/devices') |
| 31 | conf_data.set_quoted('I2C_OCC_DEVICE_NAME', 'p8-occ-hwmon') |
| 32 | else |
| 33 | conf_data.set_quoted('OCC_HWMON_PATH', '/sys/bus/platform/drivers/occ-hwmon/') |
| 34 | conf_data.set_quoted('DEV_PATH', '/sys/bus/platform/devices/') |
| 35 | endif |
| 36 | |
| 37 | if get_option('install-error-yaml').disabled() |
| 38 | conf_data.set('I2C_OCC', get_option('i2c-occ').enabled()) |
| 39 | conf_data.set('READ_OCC_SENSORS', get_option('read-occ-sensors').enabled()) |
| 40 | conf_data.set('PLDM', get_option('with-host-communication-protocol')=='pldm') |
| 41 | conf_data.set('POWER10', get_option('power10-support').enabled()) |
| 42 | endif |
| 43 | |
| 44 | configure_file(output: 'config.h', |
| 45 | configuration: conf_data |
| 46 | ) |
| 47 | |
| 48 | sdbusplusplus_prog = find_program('sdbus++') |
| 49 | sdbuspp_gen_meson_prog = find_program('sdbus++-gen-meson') |
| 50 | python_prog = find_program('python3', required: true) |
| 51 | realpath_prog = find_program('realpath') |
| 52 | |
| 53 | selected_subdirs = [] |
| 54 | selected_subdirs += 'org/open_power/OCC' |
| 55 | |
| 56 | generated_root = meson.current_build_dir() / 'gen' |
| 57 | generated_others = [] |
| 58 | generated_sources = [] |
| 59 | |
| 60 | # Source the generated meson files. |
| 61 | subdir('gen') |
| 62 | foreach d : selected_subdirs |
| 63 | subdir('gen' / d) |
| 64 | endforeach |
| 65 | |
| 66 | # Parse through the list from sdbus++-gendir and put into sets. |
| 67 | generated_headers = [] |
| 68 | generated_cpp = [] |
| 69 | generated_others_files = [] |
| 70 | |
| 71 | foreach g : generated_sources generated_others |
| 72 | foreach f : g.to_list() |
| 73 | rel_path = run_command( |
| 74 | realpath_prog, |
| 75 | '--relative-to', generated_root, |
| 76 | f.full_path(), |
| 77 | ).stdout().strip().split('\n')[-1] |
| 78 | |
| 79 | if rel_path.endswith('.hpp') |
| 80 | generated_headers += rel_path |
| 81 | elif rel_path.endswith('.cpp') |
| 82 | generated_cpp += rel_path |
| 83 | else |
| 84 | generated_others_files += rel_path |
| 85 | endif |
| 86 | endforeach |
| 87 | endforeach |
| 88 | |
| 89 | deps = [] |
| 90 | sources = [] |
| 91 | if get_option('install-error-yaml').disabled() |
| 92 | sdbusplus_dep = dependency('sdbusplus') |
George Liu | 9ed399d | 2021-09-10 13:14:27 +0800 | [diff] [blame] | 93 | if sdbusplus_dep.found() |
| 94 | sdbusplusplus_prog = find_program('sdbus++') |
| 95 | sdbuspp_gen_meson_prog = find_program('sdbus++-gen-meson') |
| 96 | else |
| 97 | sdbusplus_proj = subproject('sdbusplus', required: true) |
| 98 | sdbusplus_dep = sdbusplus_proj.get_variable('sdbusplus_dep') |
| 99 | sdbusplusplus_prog = sdbusplus_proj.get_variable('sdbusplusplus_prog') |
| 100 | sdbuspp_gen_meson_prog = sdbusplus_proj.get_variable( |
| 101 | 'sdbuspp_gen_meson_prog' |
| 102 | ) |
| 103 | endif |
| 104 | |
| 105 | sdeventplus_dep = dependency( |
| 106 | 'sdeventplus', |
| 107 | fallback: [ |
| 108 | 'sdeventplus', |
| 109 | 'sdeventplus_dep' |
| 110 | ], |
| 111 | ) |
| 112 | phosphor_logging_dep = dependency( |
| 113 | 'phosphor-logging', |
| 114 | fallback: [ |
| 115 | 'phosphor-logging', |
| 116 | 'phosphor_logging_dep' |
| 117 | ], |
| 118 | ) |
| 119 | phosphor_dbus_interfaces_dep = dependency( |
| 120 | 'phosphor-dbus-interfaces', |
| 121 | fallback: [ |
| 122 | 'phosphor-dbus-interfaces', |
| 123 | 'phosphor_dbus_interfaces_dep' |
| 124 | ], |
| 125 | ) |
George Liu | bddcf85 | 2021-09-08 08:46:22 +0800 | [diff] [blame] | 126 | |
| 127 | deps += [ |
| 128 | sdbusplus_dep, |
| 129 | sdeventplus_dep, |
| 130 | phosphor_logging_dep, |
| 131 | phosphor_dbus_interfaces_dep, |
| 132 | ] |
| 133 | |
| 134 | sources += [ |
| 135 | 'app.cpp', |
| 136 | 'occ_pass_through.cpp', |
| 137 | 'occ_manager.cpp', |
| 138 | 'occ_status.cpp', |
| 139 | 'occ_device.cpp', |
| 140 | 'occ_errors.cpp', |
| 141 | 'occ_presence.cpp', |
| 142 | 'occ_command.cpp', |
| 143 | 'occ_dbus.cpp', |
| 144 | 'powercap.cpp', |
| 145 | 'i2c_occ.cpp', |
| 146 | 'utils.cpp', |
| 147 | ] |
| 148 | |
| 149 | if get_option('with-host-communication-protocol')=='pldm' |
George Liu | 9ed399d | 2021-09-10 13:14:27 +0800 | [diff] [blame] | 150 | libpldm_dep = dependency( |
| 151 | 'libpldm', |
| 152 | fallback: ['pldm', 'libpldm_dep'], |
| 153 | default_options: ['libpldm-only=enabled', 'oem-ibm=enabled'], |
| 154 | ) |
George Liu | bddcf85 | 2021-09-08 08:46:22 +0800 | [diff] [blame] | 155 | deps += [ |
| 156 | libpldm_dep, |
| 157 | ] |
| 158 | sources += [ |
| 159 | 'pldm.cpp', |
| 160 | ] |
| 161 | endif |
| 162 | |
| 163 | if get_option('power10-support').enabled() |
| 164 | sources += [ |
| 165 | 'powermode.cpp', |
| 166 | ] |
| 167 | endif |
| 168 | |
| 169 | yamldir = get_option('yamldir') |
| 170 | if yamldir == '' |
| 171 | yamldir = meson.project_source_root() / 'example/occ_sensor.yaml' |
| 172 | endif |
| 173 | |
| 174 | # Generate occ-sensor.hpp. |
| 175 | occ_sensor_hpp = custom_target( |
| 176 | 'occ-sensor.hpp', |
| 177 | command : [ |
| 178 | python_prog, |
| 179 | meson.project_source_root() + '/sensor_gen.py', |
| 180 | '-f', meson.project_source_root() / yamldir, |
| 181 | '-i', meson.current_build_dir(), |
| 182 | ], |
| 183 | output : 'occ-sensor.hpp') |
| 184 | sources += [occ_sensor_hpp] |
| 185 | |
| 186 | executable( |
| 187 | 'openpower-occ-control', |
| 188 | sources, |
| 189 | generated_sources, |
| 190 | include_directories: ['.', 'gen'], |
| 191 | implicit_include_directories: true, |
| 192 | dependencies: deps, |
| 193 | install: true, |
| 194 | install_dir: get_option('bindir') |
| 195 | ) |
| 196 | endif |
| 197 | |
| 198 | if not get_option('tests').disabled() |
| 199 | subdir('test') |
| 200 | endif |