Zane Shelley | f480b73 | 2020-06-11 10:05:16 -0500 | [diff] [blame] | 1 | # See README.md for details. |
Zane Shelley | 248cbf8 | 2019-05-03 17:07:18 -0500 | [diff] [blame] | 2 | project('openpower-hw-diags', 'cpp', |
Patrick Williams | 7c80e52 | 2023-07-12 11:16:00 -0500 | [diff] [blame] | 3 | version: '0.1', meson_version: '>=1.1.1', |
Zane Shelley | 248cbf8 | 2019-05-03 17:07:18 -0500 | [diff] [blame] | 4 | default_options: [ |
| 5 | 'warning_level=3', |
| 6 | 'werror=true', |
Patrick Williams | 7c80e52 | 2023-07-12 11:16:00 -0500 | [diff] [blame] | 7 | 'cpp_std=c++23', |
Zane Shelley | 248cbf8 | 2019-05-03 17:07:18 -0500 | [diff] [blame] | 8 | ]) |
| 9 | |
Zane Shelley | d2854b7 | 2021-08-04 22:23:20 -0500 | [diff] [blame] | 10 | # Package directory root, which will contain required data files. |
| 11 | package_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. |
| 16 | package_args = [ '-DPACKAGE_DIR="' + package_dir + '/"' ] |
| 17 | |
Zane Shelley | d9573f4 | 2020-12-02 15:52:06 -0600 | [diff] [blame] | 18 | #------------------------------------------------------------------------------- |
Ben Tyner | eea4542 | 2021-04-15 10:54:14 -0500 | [diff] [blame] | 19 | # Versioning |
| 20 | #------------------------------------------------------------------------------- |
| 21 | buildinfo = 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 | #------------------------------------------------------------------------------- |
Zane Shelley | d9573f4 | 2020-12-02 15:52:06 -0600 | [diff] [blame] | 28 | # Compiler |
| 29 | #------------------------------------------------------------------------------- |
| 30 | |
Zane Shelley | f80482a | 2020-12-02 15:13:13 -0600 | [diff] [blame] | 31 | cmplr = meson.get_compiler('cpp') |
| 32 | |
Zane Shelley | d9573f4 | 2020-12-02 15:52:06 -0600 | [diff] [blame] | 33 | #------------------------------------------------------------------------------- |
Zane Shelley | 3a85108 | 2021-03-23 16:45:28 -0500 | [diff] [blame] | 34 | # Config file |
| 35 | #------------------------------------------------------------------------------- |
| 36 | |
| 37 | conf = configuration_data() |
| 38 | |
| 39 | conf.set('CONFIG_PHAL_API', get_option('phal').enabled()) |
| 40 | |
| 41 | configure_file(input: 'config.h.in', output: 'config.h', configuration: conf) |
| 42 | |
| 43 | #------------------------------------------------------------------------------- |
Zane Shelley | d9573f4 | 2020-12-02 15:52:06 -0600 | [diff] [blame] | 44 | # Include directories |
| 45 | #------------------------------------------------------------------------------- |
| 46 | |
| 47 | # Only using the base directory. All header includes should provide the full |
| 48 | # path from the base directory. |
| 49 | incdir = 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. |
Zane Shelley | f480b73 | 2020-06-11 10:05:16 -0500 | [diff] [blame] | 57 | libhei_dep = dependency('hei', fallback : ['libhei', 'libhei_dep']) |
Ben Tyner | 92e39fd | 2020-02-05 18:11:02 -0600 | [diff] [blame] | 58 | |
Zane Shelley | 30984d1 | 2021-12-22 17:17:54 -0600 | [diff] [blame] | 59 | phosphor_logging_dep = dependency('phosphor-logging', |
| 60 | fallback: ['phosphor-logging', 'phosphor_logging_dep']) |
| 61 | |
Zane Shelley | 61465db | 2020-10-30 14:53:11 -0500 | [diff] [blame] | 62 | sdbusplus_dep = dependency('sdbusplus', version : '>=1.0') |
| 63 | dbus_interfaces_dep = dependency('phosphor-dbus-interfaces') |
| 64 | |
Zane Shelley | f80482a | 2020-12-02 15:13:13 -0600 | [diff] [blame] | 65 | libpdbg_dep = cmplr.find_library('pdbg') |
| 66 | |
Zane Shelley | 55e7fec | 2022-01-28 15:29:44 -0600 | [diff] [blame] | 67 | fmt_dep = dependency('fmt') |
| 68 | |
Ben Tyner | b971517 | 2021-09-29 08:46:19 -0500 | [diff] [blame] | 69 | if get_option('phal').enabled() |
| 70 | libphal_dep = cmplr.find_library('phal') |
| 71 | endif |
| 72 | |
Ben Tyner | bb90afc | 2022-12-14 20:50:33 -0600 | [diff] [blame] | 73 | libpldm_dep = dependency('libpldm') |
| 74 | |
Zane Shelley | c252894 | 2020-12-02 15:42:42 -0600 | [diff] [blame] | 75 | pthread = declare_dependency(link_args : '-pthread') |
| 76 | lrt = declare_dependency(link_args : '-lrt') |
| 77 | |
Zane Shelley | 5191bae | 2021-08-04 22:48:28 -0500 | [diff] [blame] | 78 | # JSON parser |
| 79 | if cmplr.has_header('nlohmann/json.hpp') |
| 80 | nlohmann_json_dep = declare_dependency() |
| 81 | else |
| 82 | subproject('nlohmann', required: false) |
| 83 | nlohmann_json_dep = declare_dependency( |
| 84 | include_directories: [ |
| 85 | 'subprojects/nlohmann/single_include', |
| 86 | 'subprojects/nlohmann/single_include/nlohmann', |
| 87 | ] |
| 88 | ) |
| 89 | nlohmann_json_dep = nlohmann_json_dep.as_system('system') |
| 90 | endif |
| 91 | |
| 92 | # JSON validator |
| 93 | if cmplr.has_header('valijson/validator.hpp') |
| 94 | valijson_dep = declare_dependency() |
| 95 | else |
| 96 | subproject('valijson', required: false) |
| 97 | valijson_dep = declare_dependency( |
| 98 | include_directories: 'subprojects/valijson/include' |
| 99 | ) |
| 100 | valijson_dep = valijson_dep.as_system('system') |
| 101 | endif |
| 102 | |
Zane Shelley | c252894 | 2020-12-02 15:42:42 -0600 | [diff] [blame] | 103 | #------------------------------------------------------------------------------- |
Zane Shelley | d9573f4 | 2020-12-02 15:52:06 -0600 | [diff] [blame] | 104 | # Build the local static libraries |
Zane Shelley | c252894 | 2020-12-02 15:42:42 -0600 | [diff] [blame] | 105 | #------------------------------------------------------------------------------- |
| 106 | |
Ben Tyner | 0205f3b | 2020-02-24 10:24:47 -0600 | [diff] [blame] | 107 | subdir('analyzer') |
Ben Tyner | ef32015 | 2020-01-09 10:31:23 -0600 | [diff] [blame] | 108 | subdir('attn') |
Zane Shelley | f80482a | 2020-12-02 15:13:13 -0600 | [diff] [blame] | 109 | subdir('util') |
Zane Shelley | 248cbf8 | 2019-05-03 17:07:18 -0500 | [diff] [blame] | 110 | |
Zane Shelley | c252894 | 2020-12-02 15:42:42 -0600 | [diff] [blame] | 111 | hwdiags_libs = [ |
| 112 | analyzer_lib, |
| 113 | attn_lib, |
| 114 | util_lib, |
| 115 | ] |
| 116 | |
| 117 | #------------------------------------------------------------------------------- |
| 118 | # Build the executable |
| 119 | #------------------------------------------------------------------------------- |
Ben Tyner | 8c2f8b2 | 2020-03-27 10:39:31 -0500 | [diff] [blame] | 120 | |
Ben Tyner | d3cda74 | 2020-05-04 08:00:28 -0500 | [diff] [blame] | 121 | no_listener_mode = get_option('nlmode') |
| 122 | |
| 123 | if not no_listener_mode.disabled() |
Ben Tyner | 832526d | 2021-05-05 13:34:28 -0500 | [diff] [blame] | 124 | executable('openpower-hw-diags', |
Zane Shelley | 475237a | 2022-02-03 11:04:54 -0600 | [diff] [blame] | 125 | sources : [ 'main_nl.cpp', 'cli.cpp', buildinfo, plugins_src ], |
| 126 | dependencies : [ libhei_dep ], |
Zane Shelley | c252894 | 2020-12-02 15:42:42 -0600 | [diff] [blame] | 127 | link_with : hwdiags_libs, |
Ben Tyner | d3cda74 | 2020-05-04 08:00:28 -0500 | [diff] [blame] | 128 | install : true) |
| 129 | else |
Ben Tyner | 832526d | 2021-05-05 13:34:28 -0500 | [diff] [blame] | 130 | executable('openpower-hw-diags', |
Zane Shelley | 475237a | 2022-02-03 11:04:54 -0600 | [diff] [blame] | 131 | sources : [ 'main.cpp', 'cli.cpp', 'listener.cpp', buildinfo, |
| 132 | plugins_src ], |
| 133 | dependencies : [lrt, pthread, libhei_dep], |
Zane Shelley | c252894 | 2020-12-02 15:42:42 -0600 | [diff] [blame] | 134 | link_with : hwdiags_libs, |
Ben Tyner | d3cda74 | 2020-05-04 08:00:28 -0500 | [diff] [blame] | 135 | install : true) |
| 136 | endif |
Ben Tyner | 0205f3b | 2020-02-24 10:24:47 -0600 | [diff] [blame] | 137 | |
Zane Shelley | c252894 | 2020-12-02 15:42:42 -0600 | [diff] [blame] | 138 | #------------------------------------------------------------------------------- |
| 139 | # Test, if configured |
| 140 | #------------------------------------------------------------------------------- |
| 141 | |
Zane Shelley | 248cbf8 | 2019-05-03 17:07:18 -0500 | [diff] [blame] | 142 | build_tests = get_option('tests') |
| 143 | |
| 144 | if not build_tests.disabled() |
austinfcui | 5dbebde | 2022-04-12 16:30:38 -0500 | [diff] [blame] | 145 | |
| 146 | # IMPORTANT NOTE: |
| 147 | # We cannot link the test executables to `util_lib` because: |
| 148 | # - It is built without `-DTEST_TRACE` and any of the util functions that |
| 149 | # use `trace.hpp` will throw a linker error because we don't have access |
| 150 | # to phosphor-logging in test ... yet. This issue will go away once we |
| 151 | # have converted all of our trace to use the `lg2` interfaces. |
| 152 | # - Some functions related to pdbg and dbus simply cannot be built in the |
| 153 | # test environment. Instead, there are alternate implementation of those |
| 154 | # functions to simulate them for testing (see `test/*-sim-only.cpp`). |
| 155 | # Instead we will build a `test_util_lib` that will contain the `util` files |
| 156 | # that we need in test along with simulated versions of some util functions. |
| 157 | |
| 158 | # IMPORTANT NOTE: |
| 159 | # When running GCOV reports, the Jenkins CI script explicitly ignores any |
| 160 | # libraries and executables built in the `test/` directory. Therefore, this |
| 161 | # `test_util_lib` library must be built here instead in order to get any GCOV |
| 162 | # credit for the code. |
| 163 | |
| 164 | test_args = [ |
| 165 | '-DTEST_TRACE', |
| 166 | package_args, |
| 167 | ] |
| 168 | |
| 169 | test_util_srcs = [ |
| 170 | files( |
| 171 | 'util/data_file.cpp', |
| 172 | 'util/ffdc_file.cpp', |
| 173 | 'util/pdbg.cpp', |
| 174 | 'util/temporary_file.cpp', |
| 175 | 'test/dbus-sim-only.cpp', |
| 176 | 'test/pdbg-sim-only.cpp', |
| 177 | ), |
| 178 | ] |
| 179 | |
| 180 | test_util_deps = [ |
| 181 | libhei_dep, |
| 182 | libpdbg_dep, |
| 183 | phosphor_logging_dep, |
| 184 | ] |
| 185 | |
| 186 | test_util_lib = static_library('test_util_lib', |
| 187 | sources : test_util_srcs, |
| 188 | include_directories : incdir, |
| 189 | dependencies : test_util_deps, |
| 190 | cpp_args : test_args, |
| 191 | install : true, |
| 192 | ) |
| 193 | |
| 194 | test_libs = [ |
| 195 | analyzer_lib, |
| 196 | attn_lib, |
| 197 | test_util_lib, |
| 198 | ] |
| 199 | |
Zane Shelley | 248cbf8 | 2019-05-03 17:07:18 -0500 | [diff] [blame] | 200 | subdir('test') |
| 201 | endif |