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