xref: /openbmc/phosphor-led-manager/meson.build (revision d1c1f0e990446c8862ae876302dd82a636d0968d)
1project(
2    'phosphor-ledmanager', '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('BUSNAME', 'xyz.openbmc_project.LED.GroupManager')
15conf_data.set_quoted('OBJPATH', '/xyz/openbmc_project/led/groups')
16conf_data.set_quoted('LED_JSON_FILE', '/usr/share/phosphor-led-manager/led-group-config.json')
17conf_data.set_quoted('SAVED_GROUPS_FILE', '/var/lib/phosphor-led-manager/savedGroups')
18conf_data.set_quoted('CALLOUT_FWD_ASSOCIATION', 'callout')
19conf_data.set_quoted('CALLOUT_REV_ASSOCIATION', 'fault')
20conf_data.set_quoted('ELOG_ENTRY', 'entry')
21conf_data.set_quoted('LED_FAULT', 'fault')
22
23conf_data.set('CLASS_VERSION', 1)
24conf_data.set('LED_USE_JSON', get_option('use-json').enabled())
25conf_data.set('USE_LAMP_TEST', get_option('use-lamp-test').enabled())
26conf_data.set('MONITOR_OPERATIONAL_STATUS', get_option('monitor-operational-status').enabled())
27
28sdbusplus_dep = dependency('sdbusplus', required: false)
29if sdbusplus_dep.found()
30    sdbusplusplus_prog = find_program('sdbus++')
31    sdbuspp_gen_meson_prog = find_program('sdbus++-gen-meson')
32else
33    sdbusplus_proj = subproject('sdbusplus', required: true)
34    sdbusplus_dep = sdbusplus_proj.get_variable('sdbusplus_dep')
35    sdbusplusplus_prog = sdbusplus_proj.get_variable('sdbusplusplus_prog')
36    sdbuspp_gen_meson_prog = sdbusplus_proj.get_variable(
37        'sdbuspp_gen_meson_prog'
38    )
39endif
40
41sdeventplus_dep = dependency(
42    'sdeventplus',
43    fallback: [
44        'sdeventplus',
45        'sdeventplus_dep'
46    ],
47)
48phosphor_logging_dep = dependency(
49    'phosphor-logging',
50    fallback: [
51        'phosphor-logging',
52        'phosphor_logging_dep'
53    ],
54)
55phosphor_dbus_interfaces_dep = dependency(
56    'phosphor-dbus-interfaces',
57    fallback: [
58        'phosphor-dbus-interfaces',
59        'phosphor_dbus_interfaces_dep'
60    ],
61)
62prog_python = find_program('python3', required: true)
63realpath_prog = find_program('realpath')
64
65cpp = meson.get_compiler('cpp')
66if cpp.has_header('nlohmann/json.hpp')
67    nlohmann_json_dep = declare_dependency()
68else
69    subproject('nlohmann', required: false)
70    nlohmann_json_dep = declare_dependency(
71        include_directories: [
72            'subprojects/nlohmann/single_include',
73            'subprojects/nlohmann/single_include/nlohmann',
74        ]
75    )
76endif
77
78# Get Cereal dependency.
79cereal_dep = dependency('cereal', required: false)
80has_cereal = cpp.has_header_symbol(
81    'cereal/cereal.hpp',
82    'cereal::specialize',
83    dependencies: cereal_dep,
84    required: false)
85if not has_cereal
86    cereal_opts = import('cmake').subproject_options()
87    cereal_opts.add_cmake_defines({'BUILD_TESTS': 'OFF'})
88    cereal_proj = import('cmake').subproject(
89        'cereal',
90        options: cereal_opts,
91        required: false)
92    assert(cereal_proj.found(), 'cereal is required')
93    cereal_dep = cereal_proj.dependency('cereal')
94endif
95
96selected_subdirs = []
97selected_subdirs += 'xyz/openbmc_project'
98
99generated_root = meson.current_build_dir() / 'gen'
100generated_others = []
101generated_sources = []
102
103# Source the generated meson files.
104subdir('gen')
105foreach d : selected_subdirs
106  subdir('gen' / d)
107endforeach
108
109# Parse through the list from sdbus++-gendir and put into sets.
110generated_headers = []
111generated_cpp = []
112generated_others_files = []
113
114foreach g : generated_sources generated_others
115    foreach f : g.to_list()
116        rel_path = run_command(
117            realpath_prog,
118            '--relative-to', generated_root,
119            f.full_path(),
120        ).stdout().strip().split('\n')[-1]
121
122        if rel_path.endswith('.hpp')
123            generated_headers += rel_path
124        elif rel_path.endswith('.cpp')
125            generated_cpp += rel_path
126        else
127            generated_others_files += rel_path
128        endif
129    endforeach
130endforeach
131
132deps = [
133    sdbusplus_dep,
134    sdeventplus_dep,
135    phosphor_logging_dep,
136    phosphor_dbus_interfaces_dep,
137    nlohmann_json_dep,
138    cereal_dep,
139]
140
141sources = [
142    'group.cpp',
143    'led-main.cpp',
144    'manager.cpp',
145    'serialize.cpp',
146    'utils.cpp',
147]
148
149if get_option('use-json').disabled()
150    led_gen_hpp = custom_target(
151        'led-gen.hpp',
152        command : [
153            prog_python,
154            meson.project_source_root() + '/parse_led.py',
155            '-i', meson.project_source_root(),
156            '-o', meson.current_build_dir(),
157        ],
158        output : 'led-gen.hpp')
159    sources += [led_gen_hpp]
160endif
161
162if get_option('use-lamp-test').enabled()
163    conf_data.set_quoted('LAMP_TEST_OBJECT', '/xyz/openbmc_project/led/groups/lamp_test')
164    conf_data.set_quoted('HOST_LAMP_TEST_OBJECT', '/xyz/openbmc_project/led/groups/host_lamp_test')
165    conf_data.set_quoted('LAMP_TEST_LED_OVERRIDES_JSON', '/usr/share/phosphor-led-manager/lamp-test-led-overrides.json')
166    conf_data.set('LAMP_TEST_TIMEOUT_IN_SECS', 240)
167
168    sources += ['lamptest.cpp']
169endif
170
171configure_file(output: 'config.h',
172    configuration: conf_data
173)
174
175install_data(
176    'scripts/led-set-all-groups-asserted.sh',
177    install_dir: get_option('bindir')
178)
179
180executable(
181    'phosphor-ledmanager',
182    sources,
183    generated_sources,
184    include_directories: include_directories('gen'),
185    implicit_include_directories: true,
186    dependencies: deps,
187    install: true,
188    install_dir: get_option('bindir')
189)
190subdir('fault-monitor')
191
192build_tests = get_option('tests')
193if not build_tests.disabled()
194  subdir('test')
195endif
196
197install_subdir('configs',
198    install_dir: get_option('datadir') / 'phosphor-led-manager',
199    strip_directory: true)
200