blob: cb32679e76ba889711c2a7c41a5f9b5b71dbc53b [file] [log] [blame]
Zane Shelleyf480b732020-06-11 10:05:16 -05001# See README.md for details.
Zane Shelley248cbf82019-05-03 17:07:18 -05002project('openpower-hw-diags', 'cpp',
Patrick Williams7c80e522023-07-12 11:16:00 -05003 version: '0.1', meson_version: '>=1.1.1',
Zane Shelley248cbf82019-05-03 17:07:18 -05004 default_options: [
5 'warning_level=3',
6 'werror=true',
Patrick Williams7c80e522023-07-12 11:16:00 -05007 'cpp_std=c++23',
Zane Shelley248cbf82019-05-03 17:07:18 -05008 ])
9
Zane Shelleyd2854b72021-08-04 22:23:20 -050010# Package directory root, which will contain required data files.
11package_dir = join_paths( get_option('prefix'),
12 get_option('datadir'),
13 meson.project_name() )
14
15# Compiler option so that source knows the package directory.
16package_args = [ '-DPACKAGE_DIR="' + package_dir + '/"' ]
17
Zane Shelleyd9573f42020-12-02 15:52:06 -060018#-------------------------------------------------------------------------------
Ben Tynereea45422021-04-15 10:54:14 -050019# Versioning
20#-------------------------------------------------------------------------------
21buildinfo = vcs_tag(command: ['git', 'describe', '--always', '--long'],
22 input: 'buildinfo.hpp.in',
23 output: 'buildinfo.hpp',
24 replace_string:'@BUILDINFO@',
25 fallback: '0')
26
27#-------------------------------------------------------------------------------
Zane Shelleyd9573f42020-12-02 15:52:06 -060028# Compiler
29#-------------------------------------------------------------------------------
30
Zane Shelleyf80482a2020-12-02 15:13:13 -060031cmplr = meson.get_compiler('cpp')
32
Zane Shelleyd9573f42020-12-02 15:52:06 -060033#-------------------------------------------------------------------------------
Zane Shelley3a851082021-03-23 16:45:28 -050034# Config file
35#-------------------------------------------------------------------------------
36
37conf = configuration_data()
38
Patrick Williams7619ab72023-11-29 06:44:58 -060039conf.set('CONFIG_PHAL_API', get_option('phal').allowed())
Zane Shelley3a851082021-03-23 16:45:28 -050040
41configure_file(input: 'config.h.in', output: 'config.h', configuration: conf)
42
43#-------------------------------------------------------------------------------
Zane Shelleyd9573f42020-12-02 15:52:06 -060044# Include directories
45#-------------------------------------------------------------------------------
46
47# Only using the base directory. All header includes should provide the full
48# path from the base directory.
49incdir = include_directories('.')
50
51#-------------------------------------------------------------------------------
52# External library dependencies
53#-------------------------------------------------------------------------------
54
55# Look if the libhei library has already been built and installed. If not,
56# default to the subproject.
Zane Shelleyf480b732020-06-11 10:05:16 -050057libhei_dep = dependency('hei', fallback : ['libhei', 'libhei_dep'])
Ben Tyner92e39fd2020-02-05 18:11:02 -060058
Zane Shelley30984d12021-12-22 17:17:54 -060059phosphor_logging_dep = dependency('phosphor-logging',
60 fallback: ['phosphor-logging', 'phosphor_logging_dep'])
61
Zane Shelley61465db2020-10-30 14:53:11 -050062sdbusplus_dep = dependency('sdbusplus', version : '>=1.0')
63dbus_interfaces_dep = dependency('phosphor-dbus-interfaces')
64
Zane Shelleyf80482a2020-12-02 15:13:13 -060065libpdbg_dep = cmplr.find_library('pdbg')
66
Zane Shelley55e7fec2022-01-28 15:29:44 -060067fmt_dep = dependency('fmt')
68
Patrick Williams7619ab72023-11-29 06:44:58 -060069if get_option('phal').allowed()
Ben Tynerb9715172021-09-29 08:46:19 -050070 libphal_dep = cmplr.find_library('phal')
71endif
72
Ben Tynerbb90afc2022-12-14 20:50:33 -060073libpldm_dep = dependency('libpldm')
74
Zane Shelleyc2528942020-12-02 15:42:42 -060075pthread = declare_dependency(link_args : '-pthread')
76lrt = declare_dependency(link_args : '-lrt')
77
Zane Shelley5191bae2021-08-04 22:48:28 -050078# JSON parser
Patrick Williams54e71c02023-12-07 12:00:20 -060079nlohmann_json_dep = dependency('nlohmann_json', include_type: 'system')
Zane Shelley5191bae2021-08-04 22:48:28 -050080
81# JSON validator
82if cmplr.has_header('valijson/validator.hpp')
83 valijson_dep = declare_dependency()
84else
85 subproject('valijson', required: false)
86 valijson_dep = declare_dependency(
87 include_directories: 'subprojects/valijson/include'
88 )
89 valijson_dep = valijson_dep.as_system('system')
90endif
91
Zane Shelleyc2528942020-12-02 15:42:42 -060092#-------------------------------------------------------------------------------
Zane Shelleyd9573f42020-12-02 15:52:06 -060093# Build the local static libraries
Zane Shelleyc2528942020-12-02 15:42:42 -060094#-------------------------------------------------------------------------------
95
Ben Tyner0205f3b2020-02-24 10:24:47 -060096subdir('analyzer')
Ben Tyneref320152020-01-09 10:31:23 -060097subdir('attn')
Zane Shelleyf80482a2020-12-02 15:13:13 -060098subdir('util')
Zane Shelley248cbf82019-05-03 17:07:18 -050099
Zane Shelleyc2528942020-12-02 15:42:42 -0600100hwdiags_libs = [
101 analyzer_lib,
102 attn_lib,
103 util_lib,
104]
105
106#-------------------------------------------------------------------------------
107# Build the executable
108#-------------------------------------------------------------------------------
Ben Tyner8c2f8b22020-03-27 10:39:31 -0500109
Ben Tynerd3cda742020-05-04 08:00:28 -0500110no_listener_mode = get_option('nlmode')
111
112if not no_listener_mode.disabled()
Ben Tyner832526d2021-05-05 13:34:28 -0500113 executable('openpower-hw-diags',
Zane Shelley475237a2022-02-03 11:04:54 -0600114 sources : [ 'main_nl.cpp', 'cli.cpp', buildinfo, plugins_src ],
115 dependencies : [ libhei_dep ],
Zane Shelleyc2528942020-12-02 15:42:42 -0600116 link_with : hwdiags_libs,
Ben Tynerd3cda742020-05-04 08:00:28 -0500117 install : true)
118else
Ben Tyner832526d2021-05-05 13:34:28 -0500119 executable('openpower-hw-diags',
Zane Shelley475237a2022-02-03 11:04:54 -0600120 sources : [ 'main.cpp', 'cli.cpp', 'listener.cpp', buildinfo,
121 plugins_src ],
122 dependencies : [lrt, pthread, libhei_dep],
Zane Shelleyc2528942020-12-02 15:42:42 -0600123 link_with : hwdiags_libs,
Ben Tynerd3cda742020-05-04 08:00:28 -0500124 install : true)
125endif
Ben Tyner0205f3b2020-02-24 10:24:47 -0600126
Zane Shelleyc2528942020-12-02 15:42:42 -0600127#-------------------------------------------------------------------------------
128# Test, if configured
129#-------------------------------------------------------------------------------
130
Zane Shelley248cbf82019-05-03 17:07:18 -0500131build_tests = get_option('tests')
132
133if not build_tests.disabled()
austinfcui5dbebde2022-04-12 16:30:38 -0500134
135 # IMPORTANT NOTE:
136 # We cannot link the test executables to `util_lib` because:
137 # - It is built without `-DTEST_TRACE` and any of the util functions that
138 # use `trace.hpp` will throw a linker error because we don't have access
139 # to phosphor-logging in test ... yet. This issue will go away once we
140 # have converted all of our trace to use the `lg2` interfaces.
141 # - Some functions related to pdbg and dbus simply cannot be built in the
142 # test environment. Instead, there are alternate implementation of those
143 # functions to simulate them for testing (see `test/*-sim-only.cpp`).
144 # Instead we will build a `test_util_lib` that will contain the `util` files
145 # that we need in test along with simulated versions of some util functions.
146
147 # IMPORTANT NOTE:
148 # When running GCOV reports, the Jenkins CI script explicitly ignores any
149 # libraries and executables built in the `test/` directory. Therefore, this
150 # `test_util_lib` library must be built here instead in order to get any GCOV
151 # credit for the code.
152
153 test_args = [
154 '-DTEST_TRACE',
155 package_args,
156 ]
157
158 test_util_srcs = [
159 files(
160 'util/data_file.cpp',
161 'util/ffdc_file.cpp',
162 'util/pdbg.cpp',
163 'util/temporary_file.cpp',
164 'test/dbus-sim-only.cpp',
165 'test/pdbg-sim-only.cpp',
166 ),
167 ]
168
169 test_util_deps = [
170 libhei_dep,
171 libpdbg_dep,
172 phosphor_logging_dep,
173 ]
174
175 test_util_lib = static_library('test_util_lib',
176 sources : test_util_srcs,
177 include_directories : incdir,
178 dependencies : test_util_deps,
179 cpp_args : test_args,
180 install : true,
181 )
182
183 test_libs = [
184 analyzer_lib,
185 attn_lib,
186 test_util_lib,
187 ]
188
Zane Shelley248cbf82019-05-03 17:07:18 -0500189 subdir('test')
190endif