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