1project(
2    'phosphor-pid-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    ]
10)
11
12cxx = meson.get_compiler('cpp')
13
14conf_data = configuration_data()
15
16bindir = get_option('prefix') / get_option('bindir')
17conf_data.set('BINDIR', bindir)
18conf_data.set('SYSTEMD_TARGET', get_option('systemd_target'))
19conf_data.set('STRICT_FAILSAFE_PWM', get_option('strict-failsafe-pwm'))
20
21configure_file(output: 'config.h',
22    configuration: conf_data
23)
24
25if get_option('oe-sdk').allowed()
26    OECORE_TARGET_SYSROOT = run_command('sh', '-c', 'echo $OECORE_TARGET_SYSROOT').stdout().strip()
27    if OECORE_TARGET_SYSROOT == ''
28        error('OECORE_TARGET_SYSROOT must be set with enable oe-sdk')
29    endif
30    message('Enabling OE-SDK at OECORE_TARGET_SYSROOT: ' + OECORE_TARGET_SYSROOT)
31    rpath = ':'.join([OECORE_TARGET_SYSROOT + '/lib', OECORE_TARGET_SYSROOT + '/usr/lib'])
32    ld_so = run_command('sh', '-c', 'find ' + OECORE_TARGET_SYSROOT + '/lib/ld-*.so | sort -r -n | head -n1').stdout().strip()
33    dynamic_linker = ['-Wl,-dynamic-linker,' + ld_so]
34else
35    dynamic_linker = []
36endif
37
38systemd = dependency('systemd')
39systemd_system_unit_dir = systemd.get_variable(
40        'systemdsystemunitdir',
41        pkgconfig_define: ['prefix', get_option('prefix')])
42
43configure_file(input: 'phosphor-pid-control.service.in',
44               output: 'phosphor-pid-control.service',
45               configuration: conf_data,
46               install: true,
47               install_dir: systemd_system_unit_dir)
48
49phosphor_dbus_interfaces_dep = dependency('phosphor-dbus-interfaces')
50phosphor_logging_dep = dependency('phosphor-logging')
51sdbusplus_dep = dependency('sdbusplus')
52libsystemd_dep = dependency('libsystemd')
53ipmid_dep = dependency('libipmid')
54
55if cxx.has_header('nlohmann/json.hpp')
56    nlohmann_json_dep = declare_dependency()
57else
58    nlohmann_json_dep = dependency('nlohmann-json')
59endif
60
61if cxx.has_header('CLI/CLI.hpp')
62    CLI11_dep = declare_dependency()
63else
64    CLI11_dep = dependency('CLI11')
65endif
66
67deps = [
68    CLI11_dep,
69    ipmid_dep,
70    libsystemd_dep,
71    nlohmann_json_dep,
72    phosphor_dbus_interfaces_dep,
73    phosphor_logging_dep,
74    sdbusplus_dep,
75]
76
77root_inc = include_directories(
78    '.',
79    'buildjson',
80    'dbus',
81    'errors',
82    'experiments',
83    'ipmi',
84    'notimpl',
85    'pid',
86    'sensors',
87    'sysfs',
88)
89
90setsensor_sources = [
91    'setsensor.cpp'
92]
93
94libswampd_sources = [
95    'main.cpp',
96    'util.cpp',
97    'notimpl/readonly.cpp',
98    'notimpl/writeonly.cpp',
99    'dbus/dbusconfiguration.cpp',
100    'dbus/dbusutil.cpp',
101    'dbus/dbushelper.cpp',
102    'dbus/dbuspassiveredundancy.cpp',
103    'dbus/dbuspassive.cpp',
104    'dbus/dbusactiveread.cpp',
105    'dbus/dbuswrite.cpp',
106    'sysfs/sysfsread.cpp',
107    'sysfs/sysfswrite.cpp',
108    'sysfs/util.cpp',
109    'sensors/pluggable.cpp',
110    'sensors/host.cpp',
111    'sensors/builder.cpp',
112    'sensors/buildjson.cpp',
113    'sensors/manager.cpp',
114    'sensors/build_utils.cpp',
115    'pid/ec/pid.cpp',
116    'pid/ec/logging.cpp',
117    'pid/ec/stepwise.cpp',
118    'pid/fancontroller.cpp',
119    'pid/thermalcontroller.cpp',
120    'pid/pidcontroller.cpp',
121    'pid/stepwisecontroller.cpp',
122    'pid/builder.cpp',
123    'pid/buildjson.cpp',
124    'pid/zone.cpp',
125    'pid/util.cpp',
126    'pid/pidloop.cpp',
127    'pid/tuning.cpp',
128    'buildjson/buildjson.cpp',
129    'experiments/drive.cpp',
130]
131
132libmanualcmds_sources = [
133    'ipmi/main_ipmi.cpp',
134    'ipmi/manualcmds.cpp',
135    'ipmi/dbus_mode.cpp',
136]
137
138libmanualcmds = library(
139    'manualcmds',
140    libmanualcmds_sources,
141    implicit_include_directories: false,
142    dependencies: deps,
143    version: meson.project_version(),
144    override_options: ['b_lundef=false'],
145    install: true,
146    install_dir: get_option('libdir') / 'ipmid-providers')
147
148executable(
149    'swampd',
150    libswampd_sources,
151    implicit_include_directories: false,
152    include_directories: root_inc,
153    dependencies: deps,
154    install: true,
155    install_dir: get_option('bindir')
156)
157
158executable(
159    'setsensor',
160    setsensor_sources,
161    implicit_include_directories: true,
162    dependencies: deps,
163    install: true,
164    install_dir: get_option('bindir')
165)
166
167if not get_option('tests').disabled()
168    subdir('test')
169endif
170