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