1project(
2    'openpower-occ-control', 'cpp',
3    version : '1.0.0',
4    meson_version: '>=1.1.1',
5    default_options: [
6        'warning_level=3',
7        'werror=true',
8        'cpp_std=c++23',
9        'buildtype=debugoptimized'
10    ]
11)
12
13cxx = meson.get_compiler('cpp')
14
15conf_data = configuration_data()
16conf_data.set_quoted('OCC_CONTROL_BUSNAME', 'org.open_power.OCC.Control')
17conf_data.set_quoted('OCC_CONTROL_ROOT', '/org/open_power/control')
18conf_data.set_quoted('OCC_SENSORS_ROOT', '/xyz/openbmc_project/sensors')
19conf_data.set_quoted('CPU_NAME', 'cpu')
20conf_data.set_quoted('OCC_NAME', 'occ')
21conf_data.set_quoted('OCC_MASTER_NAME', 'occ-hwmon.1')
22conf_data.set_quoted('OCC_DEV_PATH', '/dev/occ')
23conf_data.set_quoted('CPU_SUBPATH', '/xyz/openbmc_project/inventory/system/chassis/motherboard')
24conf_data.set_quoted('OCC_CONTROL_PERSIST_PATH', '/var/lib/openpower-occ-control')
25conf_data.set_quoted('OP_DUMP_OBJ_PATH', get_option('op_dump_obj_path'))
26
27conf_data.set('MAX_CPUS', get_option('max-cpus'))
28conf_data.set('OCC_CPU_TEMP_SENSOR_TYPE', 0xC0)
29conf_data.set('OCC_DIMM_TEMP_SENSOR_TYPE', 0xD0)
30conf_data.set('PS_DERATING_FACTOR', get_option('ps-derating-factor'))
31
32if get_option('i2c-occ').allowed()
33    conf_data.set_quoted('OCC_HWMON_PATH', '/sys/bus/i2c/drivers/occ-hwmon/')
34    conf_data.set_quoted('DEV_PATH', '/sys/bus/i2c/devices')
35    conf_data.set_quoted('I2C_OCC_DEVICE_NAME', 'p8-occ-hwmon')
36else
37    conf_data.set_quoted('OCC_HWMON_PATH', '/sys/bus/platform/drivers/occ-hwmon/')
38    conf_data.set_quoted('DEV_PATH', '/sys/bus/platform/devices/')
39endif
40
41conf_data.set('I2C_OCC', get_option('i2c-occ').allowed())
42conf_data.set('READ_OCC_SENSORS', get_option('read-occ-sensors').allowed())
43conf_data.set('PLDM', get_option('with-host-communication-protocol')=='pldm')
44conf_data.set('POWER10', get_option('power10-support').allowed())
45
46if get_option('transport-implementation') == 'mctp-demux'
47    conf_data.set('PLDM_TRANSPORT_WITH_MCTP_DEMUX', 1)
48elif get_option('transport-implementation') == 'af-mctp'
49    conf_data.set('PLDM_TRANSPORT_WITH_AF_MCTP', 1)
50endif
51
52if cxx.has_header('poll.h')
53    conf_data.set('PLDM_HAS_POLL', 1)
54endif
55
56configure_file(output: 'config.h',
57    configuration: conf_data
58)
59
60install_data('occ-active.sh',
61    install_mode: 'rwxr-xr-x',
62    install_dir: get_option('bindir')
63)
64
65systemd = dependency('systemd')
66systemd_system_unit_dir = systemd.get_variable(
67    'systemdsystemunitdir')
68subdir('service_files')
69
70sdbusplus_dep = dependency('sdbusplus')
71
72python_prog = find_program('python3', required: true)
73
74deps = []
75sources = []
76
77cereal_dep = dependency('cereal', required: false)
78has_cereal = cxx.has_header_symbol(
79    'cereal/cereal.hpp',
80    'cereal::specialize',
81    dependencies: cereal_dep,
82    required: false)
83if not has_cereal
84    cereal_opts = import('cmake').subproject_options()
85    cereal_opts.add_cmake_defines({'BUILD_TESTS': 'OFF'})
86    cereal_proj = import('cmake').subproject(
87        'cereal',
88        options: cereal_opts,
89        required: false)
90    assert(cereal_proj.found(), 'cereal is required')
91    cereal_dep = cereal_proj.dependency('cereal')
92endif
93
94nlohmann_json_dep = dependency('nlohmann_json', include_type: 'system')
95phosphor_dbus_interfaces_dep = dependency('phosphor-dbus-interfaces')
96phosphor_logging_dep = dependency('phosphor-logging')
97sdeventplus_dep = dependency('sdeventplus')
98
99deps += [
100    cereal_dep,
101    nlohmann_json_dep,
102    phosphor_dbus_interfaces_dep,
103    phosphor_logging_dep,
104    sdbusplus_dep,
105    sdeventplus_dep,
106]
107
108sources += [
109    'app.cpp',
110    'occ_pass_through.cpp',
111    'occ_manager.cpp',
112    'occ_status.cpp',
113    'occ_device.cpp',
114    'occ_errors.cpp',
115    'occ_ffdc.cpp',
116    'occ_presence.cpp',
117    'occ_command.cpp',
118    'occ_dbus.cpp',
119    'powercap.cpp',
120    'i2c_occ.cpp',
121    'utils.cpp',
122]
123
124if get_option('with-host-communication-protocol')=='pldm'
125    libpldm_dep = dependency('libpldm')
126    deps += [
127        libpldm_dep,
128        cxx.find_library('pdbg'),
129        cxx.find_library('phal'),
130    ]
131    sources += [
132        'pldm.cpp',
133    ]
134endif
135
136if get_option('power10-support').allowed()
137    sources += [
138        'powermode.cpp',
139    ]
140endif
141
142yamldir = get_option('yamldir')
143if yamldir == ''
144    yamldir = meson.project_source_root() / 'example'
145endif
146
147# Generate occ-sensor.hpp.
148occ_sensor_hpp = custom_target(
149    'occ-sensor.hpp',
150    command : [
151        python_prog,
152        meson.project_source_root() + '/sensor_gen.py',
153        '-i', yamldir,
154    ],
155    output : 'occ-sensor.hpp')
156    sources += [occ_sensor_hpp]
157
158    executable(
159        'openpower-occ-control',
160        sources,
161        include_directories: '.',
162        implicit_include_directories: true,
163        dependencies: deps,
164        install: true,
165        install_dir: get_option('bindir')
166    )
167
168if not get_option('tests').disabled()
169  subdir('test')
170endif
171