xref: /openbmc/openpower-hw-diags/meson.build (revision 3dc7bc88)
1# See README.md for details.
2project('openpower-hw-diags', 'cpp',
3        version: '0.1', meson_version: '>=1.1.1',
4        default_options: [
5          'warning_level=3',
6          'werror=true',
7          'cpp_std=c++23',
8        ])
9
10# 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
18#-------------------------------------------------------------------------------
19# 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#-------------------------------------------------------------------------------
28# Compiler
29#-------------------------------------------------------------------------------
30
31cmplr = meson.get_compiler('cpp')
32
33#-------------------------------------------------------------------------------
34# Config file
35#-------------------------------------------------------------------------------
36
37conf = configuration_data()
38
39# OpenPOWER dump object path override
40conf.set_quoted('OP_DUMP_OBJ_PATH', get_option('op_dump_obj_path'))
41
42conf.set('CONFIG_PHAL_API', get_option('phal').allowed())
43
44configure_file(input: 'config.h.in', output: 'config.h', configuration: conf)
45
46#-------------------------------------------------------------------------------
47# Include directories
48#-------------------------------------------------------------------------------
49
50# Only using the base directory. All header includes should provide the full
51# path from the base directory.
52incdir = include_directories('.')
53
54#-------------------------------------------------------------------------------
55# External library dependencies
56#-------------------------------------------------------------------------------
57
58# Look if the libhei library has already been built and installed. If not,
59# default to the subproject.
60libhei_dep = dependency('hei', fallback : ['libhei', 'libhei_dep'])
61
62phosphor_logging_dep = dependency('phosphor-logging',
63    fallback: ['phosphor-logging', 'phosphor_logging_dep'])
64
65sdbusplus_dep       = dependency('sdbusplus', version : '>=1.0')
66dbus_interfaces_dep = dependency('phosphor-dbus-interfaces')
67
68libpdbg_dep = dependency('pdbg')
69
70if get_option('phal').allowed()
71  libphal_dep = cmplr.find_library('phal')
72endif
73
74libpldm_dep = dependency('libpldm')
75
76pthread = declare_dependency(link_args : '-pthread')
77lrt = declare_dependency(link_args : '-lrt')
78
79# JSON parser
80nlohmann_json_dep = dependency('nlohmann_json', include_type: 'system')
81
82# JSON validator
83if cmplr.has_header('valijson/validator.hpp')
84    valijson_dep = declare_dependency()
85else
86    valijson_dep = dependency('valijson', include_type: 'system')
87endif
88
89#-------------------------------------------------------------------------------
90# Build the local static libraries
91#-------------------------------------------------------------------------------
92
93subdir('analyzer')
94subdir('attn')
95subdir('util')
96
97hwdiags_libs = [
98    analyzer_lib,
99    attn_lib,
100    util_lib,
101]
102
103#-------------------------------------------------------------------------------
104# Build the executable
105#-------------------------------------------------------------------------------
106
107no_listener_mode = get_option('nlmode')
108
109if not no_listener_mode.disabled()
110  executable('openpower-hw-diags',
111              sources : [ 'main_nl.cpp', 'cli.cpp', buildinfo, plugins_src ],
112              dependencies : [ libhei_dep ],
113              link_with : hwdiags_libs,
114              install : true)
115else
116  executable('openpower-hw-diags',
117              sources : [ 'main.cpp', 'cli.cpp', 'listener.cpp', buildinfo,
118                          plugins_src ],
119              dependencies : [lrt, pthread, libhei_dep],
120              link_with : hwdiags_libs,
121              install : true)
122endif
123
124#-------------------------------------------------------------------------------
125# Test, if configured
126#-------------------------------------------------------------------------------
127
128build_tests = get_option('tests')
129
130if not build_tests.disabled()
131
132  # IMPORTANT NOTE:
133  # We cannot link the test executables to `util_lib` because:
134  #   - It is built without `-DTEST_TRACE` and any of the util functions that
135  #     use `trace.hpp` will throw a linker error because we don't have access
136  #     to phosphor-logging in test ... yet. This issue will go away once we
137  #     have converted all of our trace to use the `lg2` interfaces.
138  #   - Some functions related to pdbg and dbus simply cannot be built in the
139  #     test environment. Instead, there are alternate implementation of those
140  #     functions to simulate them for testing (see `test/*-sim-only.cpp`).
141  # Instead we will build a `test_util_lib` that will contain the `util` files
142  # that we need in test along with simulated versions of some util functions.
143
144  # IMPORTANT NOTE:
145  # When running GCOV reports, the Jenkins CI script explicitly ignores any
146  # libraries and executables built in the `test/` directory. Therefore, this
147  # `test_util_lib` library must be built here instead in order to get any GCOV
148  # credit for the code.
149
150  test_args = [
151    '-DTEST_TRACE',
152    package_args,
153  ]
154
155  test_util_srcs = [
156    files(
157      'util/data_file.cpp',
158      'util/ffdc_file.cpp',
159      'util/pdbg.cpp',
160      'util/temporary_file.cpp',
161      'test/dbus-sim-only.cpp',
162      'test/pdbg-sim-only.cpp',
163    ),
164  ]
165
166  test_util_deps = [
167    libhei_dep,
168    libpdbg_dep,
169    phosphor_logging_dep,
170  ]
171
172  test_util_lib = static_library('test_util_lib',
173    sources             : test_util_srcs,
174    include_directories : incdir,
175    dependencies        : test_util_deps,
176    cpp_args            : test_args,
177    install             : true,
178  )
179
180  test_libs = [
181    analyzer_lib,
182    attn_lib,
183    test_util_lib,
184  ]
185
186  subdir('test')
187endif
188