blob: 269ec49445f7455423973f4a65bdf0c2f6f9daac [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
48configure_file(input: 'config.h.in', output: 'config.h', configuration: conf)
49
50#-------------------------------------------------------------------------------
Zane Shelleyd9573f42020-12-02 15:52:06 -060051# Include directories
52#-------------------------------------------------------------------------------
53
54# Only using the base directory. All header includes should provide the full
55# path from the base directory.
56incdir = include_directories('.')
57
58#-------------------------------------------------------------------------------
59# External library dependencies
60#-------------------------------------------------------------------------------
61
62# Look if the libhei library has already been built and installed. If not,
63# default to the subproject.
Patrick Williamsc322c322025-02-01 08:38:07 -050064libhei_dep = dependency('hei', fallback: ['libhei', 'libhei_dep'])
Ben Tyner92e39fd2020-02-05 18:11:02 -060065
Patrick Williamsc322c322025-02-01 08:38:07 -050066phosphor_logging_dep = dependency(
67 'phosphor-logging',
68 fallback: ['phosphor-logging', 'phosphor_logging_dep'],
69)
Zane Shelley30984d12021-12-22 17:17:54 -060070
Patrick Williamsc322c322025-02-01 08:38:07 -050071sdbusplus_dep = dependency('sdbusplus', version: '>=1.0')
Zane Shelley61465db2020-10-30 14:53:11 -050072dbus_interfaces_dep = dependency('phosphor-dbus-interfaces')
73
Andrew Jeffery7f516a02024-06-27 19:42:19 +093074libpdbg_dep = dependency('pdbg')
Zane Shelleyf80482a2020-12-02 15:13:13 -060075
Patrick Williams7619ab72023-11-29 06:44:58 -060076if get_option('phal').allowed()
Patrick Williamsc322c322025-02-01 08:38:07 -050077 libphal_dep = cmplr.find_library('phal')
Ben Tynerb9715172021-09-29 08:46:19 -050078endif
79
Ben Tynerbb90afc2022-12-14 20:50:33 -060080libpldm_dep = dependency('libpldm')
81
Patrick Williamsc322c322025-02-01 08:38:07 -050082pthread = declare_dependency(link_args: '-pthread')
83lrt = declare_dependency(link_args: '-lrt')
Zane Shelleyc2528942020-12-02 15:42:42 -060084
Zane Shelley5191bae2021-08-04 22:48:28 -050085# JSON parser
Patrick Williams54e71c02023-12-07 12:00:20 -060086nlohmann_json_dep = dependency('nlohmann_json', include_type: 'system')
Zane Shelley5191bae2021-08-04 22:48:28 -050087
88# JSON validator
89if cmplr.has_header('valijson/validator.hpp')
90 valijson_dep = declare_dependency()
91else
Andrew Jeffery3dc7bc82024-06-27 19:52:38 +093092 valijson_dep = dependency('valijson', include_type: 'system')
Zane Shelley5191bae2021-08-04 22:48:28 -050093endif
94
Zane Shelleyc2528942020-12-02 15:42:42 -060095#-------------------------------------------------------------------------------
Zane Shelleyd9573f42020-12-02 15:52:06 -060096# Build the local static libraries
Zane Shelleyc2528942020-12-02 15:42:42 -060097#-------------------------------------------------------------------------------
98
Ben Tyner0205f3b2020-02-24 10:24:47 -060099subdir('analyzer')
Ben Tyneref320152020-01-09 10:31:23 -0600100subdir('attn')
Zane Shelleyf80482a2020-12-02 15:13:13 -0600101subdir('util')
Zane Shelley248cbf82019-05-03 17:07:18 -0500102
Patrick Williamsc322c322025-02-01 08:38:07 -0500103hwdiags_libs = [analyzer_lib, attn_lib, util_lib]
Zane Shelleyc2528942020-12-02 15:42:42 -0600104
105#-------------------------------------------------------------------------------
106# Build the executable
107#-------------------------------------------------------------------------------
Ben Tyner8c2f8b22020-03-27 10:39:31 -0500108
Ben Tynerd3cda742020-05-04 08:00:28 -0500109no_listener_mode = get_option('nlmode')
110
Patrick Williams588ca2b2025-01-30 17:48:11 -0500111if no_listener_mode.allowed()
Patrick Williamsc322c322025-02-01 08:38:07 -0500112 executable(
113 'openpower-hw-diags',
114 sources: ['main_nl.cpp', 'cli.cpp', buildinfo, plugins_src],
115 dependencies: [libhei_dep, nlohmann_json_dep, phosphor_logging_dep],
116 link_with: hwdiags_libs,
117 install: true,
118 )
Ben Tynerd3cda742020-05-04 08:00:28 -0500119else
Patrick Williamsc322c322025-02-01 08:38:07 -0500120 executable(
121 'openpower-hw-diags',
122 sources: ['main.cpp', 'cli.cpp', 'listener.cpp', buildinfo, plugins_src],
123 dependencies: [
124 lrt,
125 pthread,
126 libhei_dep,
127 nlohmann_json_dep,
128 phosphor_logging_dep,
129 ],
130 link_with: hwdiags_libs,
131 install: true,
132 )
Ben Tynerd3cda742020-05-04 08:00:28 -0500133endif
Ben Tyner0205f3b2020-02-24 10:24:47 -0600134
Zane Shelleyc2528942020-12-02 15:42:42 -0600135#-------------------------------------------------------------------------------
136# Test, if configured
137#-------------------------------------------------------------------------------
138
Zane Shelley248cbf82019-05-03 17:07:18 -0500139build_tests = get_option('tests')
140
Patrick Williams588ca2b2025-01-30 17:48:11 -0500141if build_tests.allowed()
austinfcui5dbebde2022-04-12 16:30:38 -0500142
Patrick Williamsc322c322025-02-01 08:38:07 -0500143 # IMPORTANT NOTE:
144 # We cannot link the test executables to `util_lib` because:
145 # - It is built without `-DTEST_TRACE` and any of the util functions that
146 # use `trace.hpp` will throw a linker error because we don't have access
147 # to phosphor-logging in test ... yet. This issue will go away once we
148 # have converted all of our trace to use the `lg2` interfaces.
149 # - Some functions related to pdbg and dbus simply cannot be built in the
150 # test environment. Instead, there are alternate implementation of those
151 # functions to simulate them for testing (see `test/*-sim-only.cpp`).
152 # Instead we will build a `test_util_lib` that will contain the `util` files
153 # that we need in test along with simulated versions of some util functions.
austinfcui5dbebde2022-04-12 16:30:38 -0500154
Patrick Williamsc322c322025-02-01 08:38:07 -0500155 # IMPORTANT NOTE:
156 # When running GCOV reports, the Jenkins CI script explicitly ignores any
157 # libraries and executables built in the `test/` directory. Therefore, this
158 # `test_util_lib` library must be built here instead in order to get any GCOV
159 # credit for the code.
austinfcui5dbebde2022-04-12 16:30:38 -0500160
Patrick Williamsc322c322025-02-01 08:38:07 -0500161 test_args = ['-DTEST_TRACE', package_args]
austinfcui5dbebde2022-04-12 16:30:38 -0500162
Patrick Williamsc322c322025-02-01 08:38:07 -0500163 test_util_srcs = [
164 files(
165 'test/dbus-sim-only.cpp',
166 'test/pdbg-sim-only.cpp',
167 'util/data_file.cpp',
168 'util/ffdc_file.cpp',
169 'util/pdbg.cpp',
170 'util/temporary_file.cpp',
171 ),
172 ]
austinfcui5dbebde2022-04-12 16:30:38 -0500173
Patrick Williamsc322c322025-02-01 08:38:07 -0500174 test_util_deps = [
175 libhei_dep,
176 libpdbg_dep,
177 nlohmann_json_dep,
178 phosphor_logging_dep,
179 valijson_dep,
180 ]
austinfcui5dbebde2022-04-12 16:30:38 -0500181
Patrick Williamsc322c322025-02-01 08:38:07 -0500182 test_util_lib = static_library(
183 'test_util_lib',
184 sources: test_util_srcs,
185 include_directories: incdir,
186 dependencies: test_util_deps,
187 cpp_args: test_args,
188 install: true,
189 )
austinfcui5dbebde2022-04-12 16:30:38 -0500190
Patrick Williamsc322c322025-02-01 08:38:07 -0500191 test_libs = [analyzer_lib, attn_lib, test_util_lib]
austinfcui5dbebde2022-04-12 16:30:38 -0500192
Patrick Williamsc322c322025-02-01 08:38:07 -0500193 subdir('test')
Zane Shelley248cbf82019-05-03 17:07:18 -0500194endif