1project(
2    'phosphor-ledmanager', 'cpp',
3    version : '1.0.0',
4    meson_version: '>=0.54.1',
5    default_options: [
6        'warning_level=3',
7        'werror=true',
8        'cpp_std=c++17',
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 = dependency('sdeventplus')
42phosphorlogging = dependency('phosphor-logging')
43phosphordbusinterfaces = dependency('phosphor-dbus-interfaces')
44gtest = dependency('gtest', main: true, disabler: true, required: true)
45gmock = dependency('gmock', disabler: true, required: true)
46prog_python = find_program('python3', required: true)
47realpath_prog = find_program('realpath')
48
49cpp = meson.get_compiler('cpp')
50if cpp.has_header('nlohmann/json.hpp')
51    nlohmann_json = declare_dependency()
52else
53    subproject('nlohmann', required: false)
54    nlohmann_json = declare_dependency(
55        include_directories: [
56            'subprojects/nlohmann/single_include',
57            'subprojects/nlohmann/single_include/nlohmann',
58        ]
59    )
60endif
61
62selected_subdirs = []
63selected_subdirs += 'xyz/openbmc_project'
64
65generated_root = meson.current_build_dir() / 'gen'
66generated_others = []
67generated_sources = []
68
69# Source the generated meson files.
70subdir('gen')
71foreach d : selected_subdirs
72  subdir('gen' / d)
73endforeach
74
75# Parse through the list from sdbus++-gendir and put into sets.
76generated_headers = []
77generated_cpp = []
78generated_others_files = []
79
80foreach g : generated_sources generated_others
81    foreach f : g.to_list()
82        rel_path = run_command(
83            realpath_prog,
84            '--relative-to', generated_root,
85            f.full_path(),
86        ).stdout().strip().split('\n')[-1]
87
88        if rel_path.endswith('.hpp')
89            generated_headers += rel_path
90        elif rel_path.endswith('.cpp')
91            generated_cpp += rel_path
92        else
93            generated_others_files += rel_path
94        endif
95    endforeach
96endforeach
97
98deps = [
99    sdbusplus_dep,
100    sdeventplus,
101    phosphorlogging,
102    phosphordbusinterfaces,
103    nlohmann_json
104]
105
106sources = [
107    'group.cpp',
108    'led-main.cpp',
109    'manager.cpp',
110    'serialize.cpp',
111    'utils.cpp',
112]
113
114if get_option('use-json').disabled()
115    led_gen_hpp = custom_target(
116        'led-gen.hpp',
117        command : [
118            prog_python,
119            meson.source_root() + '/parse_led.py',
120            '-i', meson.source_root(),
121            '-o', meson.current_build_dir(),
122        ],
123        output : 'led-gen.hpp')
124    sources += [led_gen_hpp]
125endif
126
127if get_option('use-lamp-test').enabled()
128    conf_data.set_quoted('LAMP_TEST_OBJECT', '/xyz/openbmc_project/led/groups/lamp_test')
129    conf_data.set_quoted('HOST_LAMP_TEST_OBJECT', '/xyz/openbmc_project/led/groups/host_lamp_test')
130    conf_data.set_quoted('LAMP_TEST_LED_OVERRIDES_JSON', '/usr/share/phosphor-led-manager/lamp-test-led-overrides.json')
131    conf_data.set('LAMP_TEST_TIMEOUT_IN_SECS', 240)
132
133    sources += ['lamptest.cpp']
134endif
135
136configure_file(output: 'config.h',
137    configuration: conf_data
138)
139
140install_data(
141    'scripts/led-set-all-groups-asserted.sh',
142    install_dir: get_option('bindir')
143)
144
145executable(
146    'phosphor-ledmanager',
147    sources,
148    generated_sources,
149    include_directories: include_directories('gen'),
150    dependencies: sdbusplus_dep,
151    implicit_include_directories: true,
152    dependencies: deps,
153    install: true,
154    install_dir: get_option('bindir')
155)
156subdir('fault-monitor')
157
158build_tests = get_option('tests')
159if not build_tests.disabled()
160  subdir('test')
161endif
162
163install_subdir('configs',
164    install_dir: get_option('datadir') / 'phosphor-led-manager',
165    strip_directory: true)
166