xref: /openbmc/openpower-hw-diags/meson.build (revision 54e71c06)
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
39conf.set('CONFIG_PHAL_API', get_option('phal').allowed())
40
41configure_file(input: 'config.h.in', output: 'config.h', configuration: conf)
42
43#-------------------------------------------------------------------------------
44# 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.
57libhei_dep = dependency('hei', fallback : ['libhei', 'libhei_dep'])
58
59phosphor_logging_dep = dependency('phosphor-logging',
60    fallback: ['phosphor-logging', 'phosphor_logging_dep'])
61
62sdbusplus_dep       = dependency('sdbusplus', version : '>=1.0')
63dbus_interfaces_dep = dependency('phosphor-dbus-interfaces')
64
65libpdbg_dep = cmplr.find_library('pdbg')
66
67fmt_dep = dependency('fmt')
68
69if get_option('phal').allowed()
70  libphal_dep = cmplr.find_library('phal')
71endif
72
73libpldm_dep = dependency('libpldm')
74
75pthread = declare_dependency(link_args : '-pthread')
76lrt = declare_dependency(link_args : '-lrt')
77
78# JSON parser
79nlohmann_json_dep = dependency('nlohmann_json', include_type: 'system')
80
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
92#-------------------------------------------------------------------------------
93# Build the local static libraries
94#-------------------------------------------------------------------------------
95
96subdir('analyzer')
97subdir('attn')
98subdir('util')
99
100hwdiags_libs = [
101    analyzer_lib,
102    attn_lib,
103    util_lib,
104]
105
106#-------------------------------------------------------------------------------
107# Build the executable
108#-------------------------------------------------------------------------------
109
110no_listener_mode = get_option('nlmode')
111
112if not no_listener_mode.disabled()
113  executable('openpower-hw-diags',
114              sources : [ 'main_nl.cpp', 'cli.cpp', buildinfo, plugins_src ],
115              dependencies : [ libhei_dep ],
116              link_with : hwdiags_libs,
117              install : true)
118else
119  executable('openpower-hw-diags',
120              sources : [ 'main.cpp', 'cli.cpp', 'listener.cpp', buildinfo,
121                          plugins_src ],
122              dependencies : [lrt, pthread, libhei_dep],
123              link_with : hwdiags_libs,
124              install : true)
125endif
126
127#-------------------------------------------------------------------------------
128# Test, if configured
129#-------------------------------------------------------------------------------
130
131build_tests = get_option('tests')
132
133if not build_tests.disabled()
134
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
189  subdir('test')
190endif
191