1project(
2    'phosphor-gpio-monitor',
3    'cpp',
4    default_options: [
5        'warning_level=3',
6        'werror=true',
7        'cpp_std=c++23',
8        'buildtype=debugoptimized'
9    ],
10    license: 'Apache-2.0',
11    version: '1.0',
12    meson_version: '>=1.1.1',
13)
14
15cxx = meson.get_compiler('cpp')
16
17libevdev = dependency('libevdev')
18libsystemd = dependency('libsystemd')
19libgpiod = dependency('libgpiod')
20phosphor_dbus_interfaces = dependency('phosphor-dbus-interfaces')
21phosphor_logging = dependency('phosphor-logging')
22sdbusplus = dependency('sdbusplus')
23systemd = dependency('systemd')
24
25if cxx.has_header('nlohmann/json.hpp')
26    nlohmann_json_dep = declare_dependency()
27else
28    subproject('nlohmann', required: false)
29    nlohmann_json_dep = declare_dependency(
30        include_directories: [
31            'subprojects/nlohmann-json/single_include',
32            'subprojects/nlohmann-json/single_include/nlohmann',
33        ]
34    )
35endif
36
37if cxx.has_header('CLI/CLI.hpp')
38    cli11_dep = declare_dependency()
39else
40    cli11_dep = dependency('CLI11')
41endif
42
43boost_args = ['-DBOOST_ASIO_DISABLE_THREADS',
44              '-DBOOST_ERROR_CODE_HEADER_ONLY',
45              '-DBOOST_SYSTEM_NO_DEPRECATED']
46
47systemd_system_unit_dir = systemd.get_variable(
48    'systemdsystemunitdir',
49    pkgconfig_define: ['prefix', get_option('prefix')])
50
51fs = import('fs')
52fs.copyfile(
53    'phosphor-gpio-monitor@.service',
54    install: true,
55    install_dir: systemd_system_unit_dir
56)
57
58fs.copyfile(
59    'phosphor-multi-gpio-monitor.service',
60    install: true,
61    install_dir: systemd_system_unit_dir
62)
63
64fs.copyfile(
65    'phosphor-gpio-presence@.service',
66    install: true,
67    install_dir: systemd_system_unit_dir
68)
69
70udev = dependency('udev')
71udev_rules_dir = join_paths(
72    udev.get_variable(
73        'udevdir',
74        pkgconfig_define: ['prefix', get_option('prefix')],
75    ),
76    'rules.d',
77)
78
79fs.copyfile(
80    '99-gpio-keys.rules',
81    install: true,
82    install_dir: udev_rules_dir
83)
84
85fs.copyfile(
86    'phosphor-multi-gpio-monitor.json',
87    install: true,
88    install_dir: get_option('datadir') / 'phosphor-gpio-monitor'
89)
90
91libevdev_o = static_library(
92    'libevdev_o',
93    'evdev.cpp',
94    dependencies: [
95        libevdev,
96        phosphor_dbus_interfaces,
97        phosphor_logging,
98        sdbusplus,
99    ]
100)
101
102libmonitor_o = static_library(
103    'libmonitor_o',
104     'monitor.cpp',
105    dependencies: [
106        libevdev,
107        libsystemd,
108        phosphor_logging,
109    ],
110    link_with: [
111        libevdev_o,
112    ],
113)
114
115phosphor_gpio_monitor = executable(
116    'phosphor-gpio-monitor',
117    'mainapp.cpp',
118    dependencies: [
119        cli11_dep,
120        libevdev,
121        libsystemd,
122        phosphor_logging,
123    ],
124    install: true,
125    link_with: [
126        libevdev_o,
127        libmonitor_o,
128    ],
129)
130
131executable(
132   'phosphor-multi-gpio-monitor',
133   'gpioMonMain.cpp',
134   'gpioMon.cpp',
135   dependencies: [
136        cli11_dep,
137        libgpiod,
138        nlohmann_json_dep,
139        phosphor_logging,
140        sdbusplus,
141    ],
142    cpp_args: boost_args,
143    install: true,
144)
145
146subdir('presence')
147
148build_tests = get_option('tests')
149if build_tests.allowed()
150    subdir('test')
151endif
152