blob: 7fea7c2edb236fddbd52275417ca31163ee5b2c9 [file] [log] [blame]
Zane Shelleyf480b732020-06-11 10:05:16 -05001# See README.md for details.
Patrick Williamsc322c322025-02-01 08:38:07 -05002project(
3 'openpower-hw-diags',
4 'cpp',
5 version: '0.1',
6 meson_version: '>=1.1.1',
7 default_options: ['warning_level=3', 'werror=true', 'cpp_std=c++23'],
8)
Zane Shelley248cbf82019-05-03 17:07:18 -05009
Zane Shelleyd2854b72021-08-04 22:23:20 -050010# Package directory root, which will contain required data files.
Patrick Williamsc322c322025-02-01 08:38:07 -050011package_dir = join_paths(
12 get_option('prefix'),
13 get_option('datadir'),
14 meson.project_name(),
15)
Zane Shelleyd2854b72021-08-04 22:23:20 -050016
17# Compiler option so that source knows the package directory.
Patrick Williamsc322c322025-02-01 08:38:07 -050018package_args = ['-DPACKAGE_DIR="' + package_dir + '/"']
Zane Shelleyd2854b72021-08-04 22:23:20 -050019
Zane Shelleyd9573f42020-12-02 15:52:06 -060020#-------------------------------------------------------------------------------
Ben Tynereea45422021-04-15 10:54:14 -050021# Versioning
22#-------------------------------------------------------------------------------
Patrick Williamsc322c322025-02-01 08:38:07 -050023buildinfo = vcs_tag(
24 command: ['git', 'describe', '--always', '--long'],
25 input: 'buildinfo.hpp.in',
26 output: 'buildinfo.hpp',
27 replace_string: '@BUILDINFO@',
28 fallback: '0',
29)
Ben Tynereea45422021-04-15 10:54:14 -050030
31#-------------------------------------------------------------------------------
Zane Shelleyd9573f42020-12-02 15:52:06 -060032# Compiler
33#-------------------------------------------------------------------------------
34
Zane Shelleyf80482a2020-12-02 15:13:13 -060035cmplr = meson.get_compiler('cpp')
36
Zane Shelleyd9573f42020-12-02 15:52:06 -060037#-------------------------------------------------------------------------------
Zane Shelley3a851082021-03-23 16:45:28 -050038# Config file
39#-------------------------------------------------------------------------------
40
41conf = configuration_data()
42
Dhruvaraj Subhashchandran0c1487c2024-06-01 11:07:26 -050043# OpenPOWER dump object path override
44conf.set_quoted('OP_DUMP_OBJ_PATH', get_option('op_dump_obj_path'))
45
Patrick Williams7619ab72023-11-29 06:44:58 -060046conf.set('CONFIG_PHAL_API', get_option('phal').allowed())
Zane Shelley3a851082021-03-23 16:45:28 -050047
Pavithra Barithaya316acda2025-01-20 14:57:12 +053048if(get_option('transport-implementation')) == 'mctp-demux'
49 add_project_arguments('-DPLDM_TRANSPORT_WITH_MCTP_DEMUX', language : 'cpp')
50else
51 add_project_arguments('-DPLDM_TRANSPORT_WITH_AF_MCTP', language: 'cpp')
52endif
53
Pavithra Barithaya9b1a0b62024-10-14 19:16:11 +053054if cmplr.has_header('poll.h')
55 add_project_arguments('-DPLDM_HAS_POLL=1', language: 'cpp')
56endif
57
Zane Shelley3a851082021-03-23 16:45:28 -050058configure_file(input: 'config.h.in', output: 'config.h', configuration: conf)
59
60#-------------------------------------------------------------------------------
Zane Shelleyd9573f42020-12-02 15:52:06 -060061# Include directories
62#-------------------------------------------------------------------------------
63
64# Only using the base directory. All header includes should provide the full
65# path from the base directory.
66incdir = include_directories('.')
67
68#-------------------------------------------------------------------------------
69# External library dependencies
70#-------------------------------------------------------------------------------
71
72# Look if the libhei library has already been built and installed. If not,
73# default to the subproject.
Patrick Williamsc322c322025-02-01 08:38:07 -050074libhei_dep = dependency('hei', fallback: ['libhei', 'libhei_dep'])
Ben Tyner92e39fd2020-02-05 18:11:02 -060075
Patrick Williamsc322c322025-02-01 08:38:07 -050076phosphor_logging_dep = dependency(
77 'phosphor-logging',
78 fallback: ['phosphor-logging', 'phosphor_logging_dep'],
79)
Zane Shelley30984d12021-12-22 17:17:54 -060080
Patrick Williamsc322c322025-02-01 08:38:07 -050081sdbusplus_dep = dependency('sdbusplus', version: '>=1.0')
Zane Shelley61465db2020-10-30 14:53:11 -050082dbus_interfaces_dep = dependency('phosphor-dbus-interfaces')
83
Andrew Jeffery7f516a02024-06-27 19:42:19 +093084libpdbg_dep = dependency('pdbg')
Zane Shelleyf80482a2020-12-02 15:13:13 -060085
Patrick Williams7619ab72023-11-29 06:44:58 -060086if get_option('phal').allowed()
Patrick Williamsc322c322025-02-01 08:38:07 -050087 libphal_dep = cmplr.find_library('phal')
Ben Tynerb9715172021-09-29 08:46:19 -050088endif
89
Ben Tynerbb90afc2022-12-14 20:50:33 -060090libpldm_dep = dependency('libpldm')
91
Patrick Williamsc322c322025-02-01 08:38:07 -050092pthread = declare_dependency(link_args: '-pthread')
93lrt = declare_dependency(link_args: '-lrt')
Zane Shelleyc2528942020-12-02 15:42:42 -060094
Zane Shelley5191bae2021-08-04 22:48:28 -050095# JSON parser
Patrick Williams54e71c02023-12-07 12:00:20 -060096nlohmann_json_dep = dependency('nlohmann_json', include_type: 'system')
Zane Shelley5191bae2021-08-04 22:48:28 -050097
98# JSON validator
99if cmplr.has_header('valijson/validator.hpp')
100 valijson_dep = declare_dependency()
101else
Andrew Jeffery3dc7bc82024-06-27 19:52:38 +0930102 valijson_dep = dependency('valijson', include_type: 'system')
Zane Shelley5191bae2021-08-04 22:48:28 -0500103endif
104
Zane Shelleyc2528942020-12-02 15:42:42 -0600105#-------------------------------------------------------------------------------
Zane Shelleyd9573f42020-12-02 15:52:06 -0600106# Build the local static libraries
Zane Shelleyc2528942020-12-02 15:42:42 -0600107#-------------------------------------------------------------------------------
108
Ben Tyner0205f3b2020-02-24 10:24:47 -0600109subdir('analyzer')
Ben Tyneref320152020-01-09 10:31:23 -0600110subdir('attn')
Zane Shelleyf80482a2020-12-02 15:13:13 -0600111subdir('util')
Zane Shelley248cbf82019-05-03 17:07:18 -0500112
Patrick Williamsc322c322025-02-01 08:38:07 -0500113hwdiags_libs = [analyzer_lib, attn_lib, util_lib]
Zane Shelleyc2528942020-12-02 15:42:42 -0600114
115#-------------------------------------------------------------------------------
116# Build the executable
117#-------------------------------------------------------------------------------
Ben Tyner8c2f8b22020-03-27 10:39:31 -0500118
Ben Tynerd3cda742020-05-04 08:00:28 -0500119no_listener_mode = get_option('nlmode')
120
Patrick Williams588ca2b2025-01-30 17:48:11 -0500121if no_listener_mode.allowed()
Patrick Williamsc322c322025-02-01 08:38:07 -0500122 executable(
123 'openpower-hw-diags',
124 sources: ['main_nl.cpp', 'cli.cpp', buildinfo, plugins_src],
125 dependencies: [libhei_dep, nlohmann_json_dep, phosphor_logging_dep],
126 link_with: hwdiags_libs,
127 install: true,
128 )
Ben Tynerd3cda742020-05-04 08:00:28 -0500129else
Patrick Williamsc322c322025-02-01 08:38:07 -0500130 executable(
131 'openpower-hw-diags',
132 sources: ['main.cpp', 'cli.cpp', 'listener.cpp', buildinfo, plugins_src],
133 dependencies: [
134 lrt,
135 pthread,
136 libhei_dep,
137 nlohmann_json_dep,
138 phosphor_logging_dep,
139 ],
140 link_with: hwdiags_libs,
141 install: true,
142 )
Ben Tynerd3cda742020-05-04 08:00:28 -0500143endif
Ben Tyner0205f3b2020-02-24 10:24:47 -0600144
Zane Shelleyc2528942020-12-02 15:42:42 -0600145#-------------------------------------------------------------------------------
146# Test, if configured
147#-------------------------------------------------------------------------------
148
Zane Shelley248cbf82019-05-03 17:07:18 -0500149build_tests = get_option('tests')
150
Patrick Williams588ca2b2025-01-30 17:48:11 -0500151if build_tests.allowed()
austinfcui5dbebde2022-04-12 16:30:38 -0500152
Patrick Williamsc322c322025-02-01 08:38:07 -0500153 # IMPORTANT NOTE:
154 # We cannot link the test executables to `util_lib` because:
155 # - It is built without `-DTEST_TRACE` and any of the util functions that
156 # use `trace.hpp` will throw a linker error because we don't have access
157 # to phosphor-logging in test ... yet. This issue will go away once we
158 # have converted all of our trace to use the `lg2` interfaces.
159 # - Some functions related to pdbg and dbus simply cannot be built in the
160 # test environment. Instead, there are alternate implementation of those
161 # functions to simulate them for testing (see `test/*-sim-only.cpp`).
162 # Instead we will build a `test_util_lib` that will contain the `util` files
163 # that we need in test along with simulated versions of some util functions.
austinfcui5dbebde2022-04-12 16:30:38 -0500164
Patrick Williamsc322c322025-02-01 08:38:07 -0500165 # IMPORTANT NOTE:
166 # When running GCOV reports, the Jenkins CI script explicitly ignores any
167 # libraries and executables built in the `test/` directory. Therefore, this
168 # `test_util_lib` library must be built here instead in order to get any GCOV
169 # credit for the code.
austinfcui5dbebde2022-04-12 16:30:38 -0500170
Patrick Williamsc322c322025-02-01 08:38:07 -0500171 test_args = ['-DTEST_TRACE', package_args]
austinfcui5dbebde2022-04-12 16:30:38 -0500172
Patrick Williamsc322c322025-02-01 08:38:07 -0500173 test_util_srcs = [
174 files(
175 'test/dbus-sim-only.cpp',
176 'test/pdbg-sim-only.cpp',
177 'util/data_file.cpp',
178 'util/ffdc_file.cpp',
179 'util/pdbg.cpp',
180 'util/temporary_file.cpp',
181 ),
182 ]
austinfcui5dbebde2022-04-12 16:30:38 -0500183
Patrick Williamsc322c322025-02-01 08:38:07 -0500184 test_util_deps = [
185 libhei_dep,
186 libpdbg_dep,
187 nlohmann_json_dep,
188 phosphor_logging_dep,
189 valijson_dep,
190 ]
austinfcui5dbebde2022-04-12 16:30:38 -0500191
Patrick Williamsc322c322025-02-01 08:38:07 -0500192 test_util_lib = static_library(
193 'test_util_lib',
194 sources: test_util_srcs,
195 include_directories: incdir,
196 dependencies: test_util_deps,
197 cpp_args: test_args,
198 install: true,
199 )
austinfcui5dbebde2022-04-12 16:30:38 -0500200
Patrick Williamsc322c322025-02-01 08:38:07 -0500201 test_libs = [analyzer_lib, attn_lib, test_util_lib]
austinfcui5dbebde2022-04-12 16:30:38 -0500202
Patrick Williamsc322c322025-02-01 08:38:07 -0500203 subdir('test')
Zane Shelley248cbf82019-05-03 17:07:18 -0500204endif