xref: /openbmc/openpower-hw-diags/meson.build (revision 0c1487cb)
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 = cmplr.find_library('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    subproject('valijson', required: false)
87    valijson_dep = declare_dependency(
88        include_directories: 'subprojects/valijson/include'
89    )
90    valijson_dep = valijson_dep.as_system('system')
91endif
92
93#-------------------------------------------------------------------------------
94# Build the local static libraries
95#-------------------------------------------------------------------------------
96
97subdir('analyzer')
98subdir('attn')
99subdir('util')
100
101hwdiags_libs = [
102    analyzer_lib,
103    attn_lib,
104    util_lib,
105]
106
107#-------------------------------------------------------------------------------
108# Build the executable
109#-------------------------------------------------------------------------------
110
111no_listener_mode = get_option('nlmode')
112
113if not no_listener_mode.disabled()
114  executable('openpower-hw-diags',
115              sources : [ 'main_nl.cpp', 'cli.cpp', buildinfo, plugins_src ],
116              dependencies : [ libhei_dep ],
117              link_with : hwdiags_libs,
118              install : true)
119else
120  executable('openpower-hw-diags',
121              sources : [ 'main.cpp', 'cli.cpp', 'listener.cpp', buildinfo,
122                          plugins_src ],
123              dependencies : [lrt, pthread, libhei_dep],
124              link_with : hwdiags_libs,
125              install : true)
126endif
127
128#-------------------------------------------------------------------------------
129# Test, if configured
130#-------------------------------------------------------------------------------
131
132build_tests = get_option('tests')
133
134if not build_tests.disabled()
135
136  # IMPORTANT NOTE:
137  # We cannot link the test executables to `util_lib` because:
138  #   - It is built without `-DTEST_TRACE` and any of the util functions that
139  #     use `trace.hpp` will throw a linker error because we don't have access
140  #     to phosphor-logging in test ... yet. This issue will go away once we
141  #     have converted all of our trace to use the `lg2` interfaces.
142  #   - Some functions related to pdbg and dbus simply cannot be built in the
143  #     test environment. Instead, there are alternate implementation of those
144  #     functions to simulate them for testing (see `test/*-sim-only.cpp`).
145  # Instead we will build a `test_util_lib` that will contain the `util` files
146  # that we need in test along with simulated versions of some util functions.
147
148  # IMPORTANT NOTE:
149  # When running GCOV reports, the Jenkins CI script explicitly ignores any
150  # libraries and executables built in the `test/` directory. Therefore, this
151  # `test_util_lib` library must be built here instead in order to get any GCOV
152  # credit for the code.
153
154  test_args = [
155    '-DTEST_TRACE',
156    package_args,
157  ]
158
159  test_util_srcs = [
160    files(
161      'util/data_file.cpp',
162      'util/ffdc_file.cpp',
163      'util/pdbg.cpp',
164      'util/temporary_file.cpp',
165      'test/dbus-sim-only.cpp',
166      'test/pdbg-sim-only.cpp',
167    ),
168  ]
169
170  test_util_deps = [
171    libhei_dep,
172    libpdbg_dep,
173    phosphor_logging_dep,
174  ]
175
176  test_util_lib = static_library('test_util_lib',
177    sources             : test_util_srcs,
178    include_directories : incdir,
179    dependencies        : test_util_deps,
180    cpp_args            : test_args,
181    install             : true,
182  )
183
184  test_libs = [
185    analyzer_lib,
186    attn_lib,
187    test_util_lib,
188  ]
189
190  subdir('test')
191endif
192