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