blob: 8e48b2629b8ddce24c5bd13bdcacdee1a42b1397 [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',
Zane Shelley29237752021-12-22 11:00:30 -06003 version: '0.1', meson_version: '>=0.57.0',
Zane Shelley248cbf82019-05-03 17:07:18 -05004 default_options: [
5 'warning_level=3',
6 'werror=true',
Zane Shelley29237752021-12-22 11:00:30 -06007 'cpp_std=c++20',
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
39conf.set('CONFIG_PHAL_API', get_option('phal').enabled())
40
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
Ben Tynerb9715172021-09-29 08:46:19 -050069if get_option('phal').enabled()
70 libphal_dep = cmplr.find_library('phal')
71endif
72
Zane Shelleyc2528942020-12-02 15:42:42 -060073pthread = declare_dependency(link_args : '-pthread')
74lrt = declare_dependency(link_args : '-lrt')
75
Zane Shelley5191bae2021-08-04 22:48:28 -050076# JSON parser
77if cmplr.has_header('nlohmann/json.hpp')
78 nlohmann_json_dep = declare_dependency()
79else
80 subproject('nlohmann', required: false)
81 nlohmann_json_dep = declare_dependency(
82 include_directories: [
83 'subprojects/nlohmann/single_include',
84 'subprojects/nlohmann/single_include/nlohmann',
85 ]
86 )
87 nlohmann_json_dep = nlohmann_json_dep.as_system('system')
88endif
89
90# JSON validator
91if cmplr.has_header('valijson/validator.hpp')
92 valijson_dep = declare_dependency()
93else
94 subproject('valijson', required: false)
95 valijson_dep = declare_dependency(
96 include_directories: 'subprojects/valijson/include'
97 )
98 valijson_dep = valijson_dep.as_system('system')
99endif
100
Zane Shelleyc2528942020-12-02 15:42:42 -0600101#-------------------------------------------------------------------------------
Zane Shelleyd9573f42020-12-02 15:52:06 -0600102# Build the local static libraries
Zane Shelleyc2528942020-12-02 15:42:42 -0600103#-------------------------------------------------------------------------------
104
Ben Tyner0205f3b2020-02-24 10:24:47 -0600105subdir('analyzer')
Ben Tyneref320152020-01-09 10:31:23 -0600106subdir('attn')
Zane Shelleyf80482a2020-12-02 15:13:13 -0600107subdir('util')
Zane Shelley248cbf82019-05-03 17:07:18 -0500108
Zane Shelleyc2528942020-12-02 15:42:42 -0600109hwdiags_libs = [
110 analyzer_lib,
111 attn_lib,
112 util_lib,
113]
114
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
121if not no_listener_mode.disabled()
Ben Tyner832526d2021-05-05 13:34:28 -0500122 executable('openpower-hw-diags',
Zane Shelley475237a2022-02-03 11:04:54 -0600123 sources : [ 'main_nl.cpp', 'cli.cpp', buildinfo, plugins_src ],
124 dependencies : [ libhei_dep ],
Zane Shelleyc2528942020-12-02 15:42:42 -0600125 link_with : hwdiags_libs,
Ben Tynerd3cda742020-05-04 08:00:28 -0500126 install : true)
127else
Ben Tyner832526d2021-05-05 13:34:28 -0500128 executable('openpower-hw-diags',
Zane Shelley475237a2022-02-03 11:04:54 -0600129 sources : [ 'main.cpp', 'cli.cpp', 'listener.cpp', buildinfo,
130 plugins_src ],
131 dependencies : [lrt, pthread, libhei_dep],
Zane Shelleyc2528942020-12-02 15:42:42 -0600132 link_with : hwdiags_libs,
Ben Tynerd3cda742020-05-04 08:00:28 -0500133 install : true)
134endif
Ben Tyner0205f3b2020-02-24 10:24:47 -0600135
Zane Shelleyc2528942020-12-02 15:42:42 -0600136#-------------------------------------------------------------------------------
137# Test, if configured
138#-------------------------------------------------------------------------------
139
Zane Shelley248cbf82019-05-03 17:07:18 -0500140build_tests = get_option('tests')
141
142if not build_tests.disabled()
austinfcui5dbebde2022-04-12 16:30:38 -0500143
144 # IMPORTANT NOTE:
145 # We cannot link the test executables to `util_lib` because:
146 # - It is built without `-DTEST_TRACE` and any of the util functions that
147 # use `trace.hpp` will throw a linker error because we don't have access
148 # to phosphor-logging in test ... yet. This issue will go away once we
149 # have converted all of our trace to use the `lg2` interfaces.
150 # - Some functions related to pdbg and dbus simply cannot be built in the
151 # test environment. Instead, there are alternate implementation of those
152 # functions to simulate them for testing (see `test/*-sim-only.cpp`).
153 # Instead we will build a `test_util_lib` that will contain the `util` files
154 # that we need in test along with simulated versions of some util functions.
155
156 # IMPORTANT NOTE:
157 # When running GCOV reports, the Jenkins CI script explicitly ignores any
158 # libraries and executables built in the `test/` directory. Therefore, this
159 # `test_util_lib` library must be built here instead in order to get any GCOV
160 # credit for the code.
161
162 test_args = [
163 '-DTEST_TRACE',
164 package_args,
165 ]
166
167 test_util_srcs = [
168 files(
169 'util/data_file.cpp',
170 'util/ffdc_file.cpp',
171 'util/pdbg.cpp',
172 'util/temporary_file.cpp',
173 'test/dbus-sim-only.cpp',
174 'test/pdbg-sim-only.cpp',
175 ),
176 ]
177
178 test_util_deps = [
179 libhei_dep,
180 libpdbg_dep,
181 phosphor_logging_dep,
182 ]
183
184 test_util_lib = static_library('test_util_lib',
185 sources : test_util_srcs,
186 include_directories : incdir,
187 dependencies : test_util_deps,
188 cpp_args : test_args,
189 install : true,
190 )
191
192 test_libs = [
193 analyzer_lib,
194 attn_lib,
195 test_util_lib,
196 ]
197
Zane Shelley248cbf82019-05-03 17:07:18 -0500198 subdir('test')
199endif