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
13conf_data = configuration_data()
14conf_data.set_quoted('OCC_CONTROL_BUSNAME', 'org.open_power.OCC.Control')
15conf_data.set_quoted('OCC_CONTROL_ROOT', '/org/open_power/control')
16conf_data.set_quoted('OCC_SENSORS_ROOT', '/xyz/openbmc_project/sensors')
17conf_data.set_quoted('CPU_NAME', 'cpu')
18conf_data.set_quoted('OCC_NAME', 'occ')
19conf_data.set_quoted('OCC_MASTER_NAME', 'occ-hwmon.1')
20conf_data.set_quoted('OCC_DEV_PATH', '/dev/occ')
21conf_data.set_quoted('CPU_SUBPATH', '/xyz/openbmc_project/inventory/system/chassis/motherboard')
22
23conf_data.set('MAX_CPUS', get_option('max-cpus'))
24conf_data.set('OCC_CPU_TEMP_SENSOR_TYPE', 0xC0)
25conf_data.set('OCC_DIMM_TEMP_SENSOR_TYPE', 0xD0)
26conf_data.set('PS_DERATING_FACTOR', 90)
27
28if 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')
32else
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/')
35endif
36
37if 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())
42endif
43
44configure_file(output: 'config.h',
45    configuration: conf_data
46)
47
48sdbusplusplus_prog = find_program('sdbus++')
49sdbuspp_gen_meson_prog = find_program('sdbus++-gen-meson')
50python_prog = find_program('python3', required: true)
51realpath_prog = find_program('realpath')
52
53selected_subdirs = []
54selected_subdirs += 'org/open_power/OCC'
55
56generated_root = meson.current_build_dir() / 'gen'
57generated_others = []
58generated_sources = []
59
60# Source the generated meson files.
61subdir('gen')
62foreach d : selected_subdirs
63  subdir('gen' / d)
64endforeach
65
66# Parse through the list from sdbus++-gendir and put into sets.
67generated_headers = []
68generated_cpp = []
69generated_others_files = []
70
71foreach 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
87endforeach
88
89deps = []
90sources = []
91if get_option('install-error-yaml').disabled()
92    sdbusplus_dep = dependency('sdbusplus')
93    sdeventplus_dep = dependency('sdeventplus')
94    phosphor_logging_dep = dependency('phosphor-logging')
95    phosphor_dbus_interfaces_dep = dependency('phosphor-dbus-interfaces')
96
97    deps += [
98        sdbusplus_dep,
99        sdeventplus_dep,
100        phosphor_logging_dep,
101        phosphor_dbus_interfaces_dep,
102    ]
103
104    sources += [
105        'app.cpp',
106        'occ_pass_through.cpp',
107        'occ_manager.cpp',
108        'occ_status.cpp',
109        'occ_device.cpp',
110        'occ_errors.cpp',
111        'occ_presence.cpp',
112        'occ_command.cpp',
113        'occ_dbus.cpp',
114        'powercap.cpp',
115        'i2c_occ.cpp',
116        'utils.cpp',
117    ]
118
119    if get_option('with-host-communication-protocol')=='pldm'
120        libpldm_dep = dependency('libpldm')
121        deps += [
122            libpldm_dep,
123        ]
124        sources += [
125            'pldm.cpp',
126        ]
127    endif
128
129    if get_option('power10-support').enabled()
130        sources += [
131            'powermode.cpp',
132        ]
133    endif
134
135    yamldir = get_option('yamldir')
136    if yamldir == ''
137        yamldir = meson.project_source_root() / 'example/occ_sensor.yaml'
138    endif
139
140    # Generate occ-sensor.hpp.
141    occ_sensor_hpp = custom_target(
142        'occ-sensor.hpp',
143        command : [
144            python_prog,
145            meson.project_source_root() + '/sensor_gen.py',
146            '-f', meson.project_source_root() / yamldir,
147            '-i', meson.current_build_dir(),
148        ],
149        output : 'occ-sensor.hpp')
150    sources += [occ_sensor_hpp]
151
152    executable(
153        'openpower-occ-control',
154        sources,
155        generated_sources,
156        include_directories: ['.', 'gen'],
157        implicit_include_directories: true,
158        dependencies: deps,
159        install: true,
160        install_dir: get_option('bindir')
161    )
162endif
163
164if not get_option('tests').disabled()
165  subdir('test')
166endif
167