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