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