blob: a0fa4256655f2a49df341a72388b7848e50ed0d5 [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 Barithaya9b1a0b62024-10-14 19:16:11 +053048if cmplr.has_header('poll.h')
49 add_project_arguments('-DPLDM_HAS_POLL=1', language: 'cpp')
50endif
51
Zane Shelley3a851082021-03-23 16:45:28 -050052configure_file(input: 'config.h.in', output: 'config.h', configuration: conf)
53
54#-------------------------------------------------------------------------------
Zane Shelleyd9573f42020-12-02 15:52:06 -060055# Include directories
56#-------------------------------------------------------------------------------
57
58# Only using the base directory. All header includes should provide the full
59# path from the base directory.
60incdir = include_directories('.')
61
62#-------------------------------------------------------------------------------
63# External library dependencies
64#-------------------------------------------------------------------------------
65
66# Look if the libhei library has already been built and installed. If not,
67# default to the subproject.
Patrick Williamsc322c322025-02-01 08:38:07 -050068libhei_dep = dependency('hei', fallback: ['libhei', 'libhei_dep'])
Ben Tyner92e39fd2020-02-05 18:11:02 -060069
Patrick Williamsc322c322025-02-01 08:38:07 -050070phosphor_logging_dep = dependency(
71 'phosphor-logging',
72 fallback: ['phosphor-logging', 'phosphor_logging_dep'],
73)
Zane Shelley30984d12021-12-22 17:17:54 -060074
Patrick Williamsc322c322025-02-01 08:38:07 -050075sdbusplus_dep = dependency('sdbusplus', version: '>=1.0')
Zane Shelley61465db2020-10-30 14:53:11 -050076dbus_interfaces_dep = dependency('phosphor-dbus-interfaces')
77
Andrew Jeffery7f516a02024-06-27 19:42:19 +093078libpdbg_dep = dependency('pdbg')
Zane Shelleyf80482a2020-12-02 15:13:13 -060079
Patrick Williams7619ab72023-11-29 06:44:58 -060080if get_option('phal').allowed()
Patrick Williamsc322c322025-02-01 08:38:07 -050081 libphal_dep = cmplr.find_library('phal')
Ben Tynerb9715172021-09-29 08:46:19 -050082endif
83
Ben Tynerbb90afc2022-12-14 20:50:33 -060084libpldm_dep = dependency('libpldm')
85
Patrick Williamsc322c322025-02-01 08:38:07 -050086pthread = declare_dependency(link_args: '-pthread')
87lrt = declare_dependency(link_args: '-lrt')
Zane Shelleyc2528942020-12-02 15:42:42 -060088
Zane Shelley5191bae2021-08-04 22:48:28 -050089# JSON parser
Patrick Williams54e71c02023-12-07 12:00:20 -060090nlohmann_json_dep = dependency('nlohmann_json', include_type: 'system')
Zane Shelley5191bae2021-08-04 22:48:28 -050091
92# JSON validator
93if cmplr.has_header('valijson/validator.hpp')
94 valijson_dep = declare_dependency()
95else
Andrew Jeffery3dc7bc82024-06-27 19:52:38 +093096 valijson_dep = dependency('valijson', include_type: 'system')
Zane Shelley5191bae2021-08-04 22:48:28 -050097endif
98
Zane Shelleyc2528942020-12-02 15:42:42 -060099#-------------------------------------------------------------------------------
Zane Shelleyd9573f42020-12-02 15:52:06 -0600100# Build the local static libraries
Zane Shelleyc2528942020-12-02 15:42:42 -0600101#-------------------------------------------------------------------------------
102
Ben Tyner0205f3b2020-02-24 10:24:47 -0600103subdir('analyzer')
Ben Tyneref320152020-01-09 10:31:23 -0600104subdir('attn')
Zane Shelleyf80482a2020-12-02 15:13:13 -0600105subdir('util')
Zane Shelley248cbf82019-05-03 17:07:18 -0500106
Patrick Williamsc322c322025-02-01 08:38:07 -0500107hwdiags_libs = [analyzer_lib, attn_lib, util_lib]
Zane Shelleyc2528942020-12-02 15:42:42 -0600108
109#-------------------------------------------------------------------------------
110# Build the executable
111#-------------------------------------------------------------------------------
Ben Tyner8c2f8b22020-03-27 10:39:31 -0500112
Ben Tynerd3cda742020-05-04 08:00:28 -0500113no_listener_mode = get_option('nlmode')
114
Patrick Williams588ca2b2025-01-30 17:48:11 -0500115if no_listener_mode.allowed()
Patrick Williamsc322c322025-02-01 08:38:07 -0500116 executable(
117 'openpower-hw-diags',
118 sources: ['main_nl.cpp', 'cli.cpp', buildinfo, plugins_src],
119 dependencies: [libhei_dep, nlohmann_json_dep, phosphor_logging_dep],
120 link_with: hwdiags_libs,
121 install: true,
122 )
Ben Tynerd3cda742020-05-04 08:00:28 -0500123else
Patrick Williamsc322c322025-02-01 08:38:07 -0500124 executable(
125 'openpower-hw-diags',
126 sources: ['main.cpp', 'cli.cpp', 'listener.cpp', buildinfo, plugins_src],
127 dependencies: [
128 lrt,
129 pthread,
130 libhei_dep,
131 nlohmann_json_dep,
132 phosphor_logging_dep,
133 ],
134 link_with: hwdiags_libs,
135 install: true,
136 )
Ben Tynerd3cda742020-05-04 08:00:28 -0500137endif
Ben Tyner0205f3b2020-02-24 10:24:47 -0600138
Zane Shelleyc2528942020-12-02 15:42:42 -0600139#-------------------------------------------------------------------------------
140# Test, if configured
141#-------------------------------------------------------------------------------
142
Zane Shelley248cbf82019-05-03 17:07:18 -0500143build_tests = get_option('tests')
144
Patrick Williams588ca2b2025-01-30 17:48:11 -0500145if build_tests.allowed()
austinfcui5dbebde2022-04-12 16:30:38 -0500146
Patrick Williamsc322c322025-02-01 08:38:07 -0500147 # IMPORTANT NOTE:
148 # We cannot link the test executables to `util_lib` because:
149 # - It is built without `-DTEST_TRACE` and any of the util functions that
150 # use `trace.hpp` will throw a linker error because we don't have access
151 # to phosphor-logging in test ... yet. This issue will go away once we
152 # have converted all of our trace to use the `lg2` interfaces.
153 # - Some functions related to pdbg and dbus simply cannot be built in the
154 # test environment. Instead, there are alternate implementation of those
155 # functions to simulate them for testing (see `test/*-sim-only.cpp`).
156 # Instead we will build a `test_util_lib` that will contain the `util` files
157 # that we need in test along with simulated versions of some util functions.
austinfcui5dbebde2022-04-12 16:30:38 -0500158
Patrick Williamsc322c322025-02-01 08:38:07 -0500159 # IMPORTANT NOTE:
160 # When running GCOV reports, the Jenkins CI script explicitly ignores any
161 # libraries and executables built in the `test/` directory. Therefore, this
162 # `test_util_lib` library must be built here instead in order to get any GCOV
163 # credit for the code.
austinfcui5dbebde2022-04-12 16:30:38 -0500164
Patrick Williamsc322c322025-02-01 08:38:07 -0500165 test_args = ['-DTEST_TRACE', package_args]
austinfcui5dbebde2022-04-12 16:30:38 -0500166
Patrick Williamsc322c322025-02-01 08:38:07 -0500167 test_util_srcs = [
168 files(
169 'test/dbus-sim-only.cpp',
170 'test/pdbg-sim-only.cpp',
171 'util/data_file.cpp',
172 'util/ffdc_file.cpp',
173 'util/pdbg.cpp',
174 'util/temporary_file.cpp',
175 ),
176 ]
austinfcui5dbebde2022-04-12 16:30:38 -0500177
Patrick Williamsc322c322025-02-01 08:38:07 -0500178 test_util_deps = [
179 libhei_dep,
180 libpdbg_dep,
181 nlohmann_json_dep,
182 phosphor_logging_dep,
183 valijson_dep,
184 ]
austinfcui5dbebde2022-04-12 16:30:38 -0500185
Patrick Williamsc322c322025-02-01 08:38:07 -0500186 test_util_lib = static_library(
187 'test_util_lib',
188 sources: test_util_srcs,
189 include_directories: incdir,
190 dependencies: test_util_deps,
191 cpp_args: test_args,
192 install: true,
193 )
austinfcui5dbebde2022-04-12 16:30:38 -0500194
Patrick Williamsc322c322025-02-01 08:38:07 -0500195 test_libs = [analyzer_lib, attn_lib, test_util_lib]
austinfcui5dbebde2022-04-12 16:30:38 -0500196
Patrick Williamsc322c322025-02-01 08:38:07 -0500197 subdir('test')
Zane Shelley248cbf82019-05-03 17:07:18 -0500198endif