xref: /openbmc/openpower-hw-diags/meson.build (revision bb90afc716ee903340e4f93767b02d0eecc955fa)
1f480b739SZane Shelley# See README.md for details.
2248cbf83SZane Shelleyproject('openpower-hw-diags', 'cpp',
32923775fSZane Shelley        version: '0.1', meson_version: '>=0.57.0',
4248cbf83SZane Shelley        default_options: [
5248cbf83SZane Shelley          'warning_level=3',
6248cbf83SZane Shelley          'werror=true',
72923775fSZane Shelley          'cpp_std=c++20',
8248cbf83SZane Shelley        ])
9248cbf83SZane Shelley
10d2854b75SZane Shelley# Package directory root, which will contain required data files.
11d2854b75SZane Shelleypackage_dir = join_paths( get_option('prefix'),
12d2854b75SZane Shelley                          get_option('datadir'),
13d2854b75SZane Shelley                          meson.project_name() )
14d2854b75SZane Shelley
15d2854b75SZane Shelley# Compiler option so that source knows the package directory.
16d2854b75SZane Shelleypackage_args = [ '-DPACKAGE_DIR="' + package_dir + '/"' ]
17d2854b75SZane Shelley
18d9573f48SZane Shelley#-------------------------------------------------------------------------------
19eea45427SBen Tyner# Versioning
20eea45427SBen Tyner#-------------------------------------------------------------------------------
21eea45427SBen Tynerbuildinfo = vcs_tag(command: ['git', 'describe', '--always', '--long'],
22eea45427SBen Tyner                  input: 'buildinfo.hpp.in',
23eea45427SBen Tyner                  output: 'buildinfo.hpp',
24eea45427SBen Tyner                  replace_string:'@BUILDINFO@',
25eea45427SBen Tyner                  fallback: '0')
26eea45427SBen Tyner
27eea45427SBen Tyner#-------------------------------------------------------------------------------
28d9573f48SZane Shelley# Compiler
29d9573f48SZane Shelley#-------------------------------------------------------------------------------
30d9573f48SZane Shelley
31f80482a5SZane Shelleycmplr = meson.get_compiler('cpp')
32f80482a5SZane Shelley
33d9573f48SZane Shelley#-------------------------------------------------------------------------------
343a85108fSZane Shelley# Config file
353a85108fSZane Shelley#-------------------------------------------------------------------------------
363a85108fSZane Shelley
373a85108fSZane Shelleyconf = configuration_data()
383a85108fSZane Shelley
393a85108fSZane Shelleyconf.set('CONFIG_PHAL_API', get_option('phal').enabled())
403a85108fSZane Shelley
413a85108fSZane Shelleyconfigure_file(input: 'config.h.in', output: 'config.h', configuration: conf)
423a85108fSZane Shelley
433a85108fSZane Shelley#-------------------------------------------------------------------------------
44d9573f48SZane Shelley# Include directories
45d9573f48SZane Shelley#-------------------------------------------------------------------------------
46d9573f48SZane Shelley
47d9573f48SZane Shelley# Only using the base directory. All header includes should provide the full
48d9573f48SZane Shelley# path from the base directory.
49d9573f48SZane Shelleyincdir = include_directories('.')
50d9573f48SZane Shelley
51d9573f48SZane Shelley#-------------------------------------------------------------------------------
52d9573f48SZane Shelley# External library dependencies
53d9573f48SZane Shelley#-------------------------------------------------------------------------------
54d9573f48SZane Shelley
55d9573f48SZane Shelley# Look if the libhei library has already been built and installed. If not,
56d9573f48SZane Shelley# default to the subproject.
57f480b739SZane Shelleylibhei_dep = dependency('hei', fallback : ['libhei', 'libhei_dep'])
5892e39fd9SBen Tyner
5930984d15SZane Shelleyphosphor_logging_dep = dependency('phosphor-logging',
6030984d15SZane Shelley    fallback: ['phosphor-logging', 'phosphor_logging_dep'])
6130984d15SZane Shelley
6261465db5SZane Shelleysdbusplus_dep       = dependency('sdbusplus', version : '>=1.0')
6361465db5SZane Shelleydbus_interfaces_dep = dependency('phosphor-dbus-interfaces')
6461465db5SZane Shelley
65f80482a5SZane Shelleylibpdbg_dep = cmplr.find_library('pdbg')
66f80482a5SZane Shelley
6755e7fec3SZane Shelleyfmt_dep = dependency('fmt')
6855e7fec3SZane Shelley
69b9715179SBen Tynerif get_option('phal').enabled()
70b9715179SBen Tyner  libphal_dep = cmplr.find_library('phal')
71b9715179SBen Tynerendif
72b9715179SBen Tyner
73*bb90afc7SBen Tynerlibpldm_dep = dependency('libpldm')
74*bb90afc7SBen Tyner
75c252894dSZane Shelleypthread = declare_dependency(link_args : '-pthread')
76c252894dSZane Shelleylrt = declare_dependency(link_args : '-lrt')
77c252894dSZane Shelley
785191bae9SZane Shelley# JSON parser
795191bae9SZane Shelleyif cmplr.has_header('nlohmann/json.hpp')
805191bae9SZane Shelley    nlohmann_json_dep = declare_dependency()
815191bae9SZane Shelleyelse
825191bae9SZane Shelley    subproject('nlohmann', required: false)
835191bae9SZane Shelley    nlohmann_json_dep = declare_dependency(
845191bae9SZane Shelley        include_directories: [
855191bae9SZane Shelley            'subprojects/nlohmann/single_include',
865191bae9SZane Shelley            'subprojects/nlohmann/single_include/nlohmann',
875191bae9SZane Shelley        ]
885191bae9SZane Shelley    )
895191bae9SZane Shelley    nlohmann_json_dep = nlohmann_json_dep.as_system('system')
905191bae9SZane Shelleyendif
915191bae9SZane Shelley
925191bae9SZane Shelley# JSON validator
935191bae9SZane Shelleyif cmplr.has_header('valijson/validator.hpp')
945191bae9SZane Shelley    valijson_dep = declare_dependency()
955191bae9SZane Shelleyelse
965191bae9SZane Shelley    subproject('valijson', required: false)
975191bae9SZane Shelley    valijson_dep = declare_dependency(
985191bae9SZane Shelley        include_directories: 'subprojects/valijson/include'
995191bae9SZane Shelley    )
1005191bae9SZane Shelley    valijson_dep = valijson_dep.as_system('system')
1015191bae9SZane Shelleyendif
1025191bae9SZane Shelley
103c252894dSZane Shelley#-------------------------------------------------------------------------------
104d9573f48SZane Shelley# Build the local static libraries
105c252894dSZane Shelley#-------------------------------------------------------------------------------
106c252894dSZane Shelley
1070205f3b3SBen Tynersubdir('analyzer')
108ef320154SBen Tynersubdir('attn')
109f80482a5SZane Shelleysubdir('util')
110248cbf83SZane Shelley
111c252894dSZane Shelleyhwdiags_libs = [
112c252894dSZane Shelley    analyzer_lib,
113c252894dSZane Shelley    attn_lib,
114c252894dSZane Shelley    util_lib,
115c252894dSZane Shelley]
116c252894dSZane Shelley
117c252894dSZane Shelley#-------------------------------------------------------------------------------
118c252894dSZane Shelley# Build the executable
119c252894dSZane Shelley#-------------------------------------------------------------------------------
1208c2f8b24SBen Tyner
121d3cda742SBen Tynerno_listener_mode = get_option('nlmode')
122d3cda742SBen Tyner
123d3cda742SBen Tynerif not no_listener_mode.disabled()
124832526dfSBen Tyner  executable('openpower-hw-diags',
125475237a4SZane Shelley              sources : [ 'main_nl.cpp', 'cli.cpp', buildinfo, plugins_src ],
126475237a4SZane Shelley              dependencies : [ libhei_dep ],
127c252894dSZane Shelley              link_with : hwdiags_libs,
128d3cda742SBen Tyner              install : true)
129d3cda742SBen Tynerelse
130832526dfSBen Tyner  executable('openpower-hw-diags',
131475237a4SZane Shelley              sources : [ 'main.cpp', 'cli.cpp', 'listener.cpp', buildinfo,
132475237a4SZane Shelley                          plugins_src ],
133475237a4SZane Shelley              dependencies : [lrt, pthread, libhei_dep],
134c252894dSZane Shelley              link_with : hwdiags_libs,
1350205f3b3SBen Tyner              install : true)
136d3cda742SBen Tynerendif
1370205f3b3SBen Tyner
138c252894dSZane Shelley#-------------------------------------------------------------------------------
139c252894dSZane Shelley# Test, if configured
140c252894dSZane Shelley#-------------------------------------------------------------------------------
141c252894dSZane Shelley
142248cbf83SZane Shelleybuild_tests = get_option('tests')
143248cbf83SZane Shelley
144248cbf83SZane Shelleyif not build_tests.disabled()
1455dbebde0Saustinfcui
1465dbebde0Saustinfcui  # IMPORTANT NOTE:
1475dbebde0Saustinfcui  # We cannot link the test executables to `util_lib` because:
1485dbebde0Saustinfcui  #   - It is built without `-DTEST_TRACE` and any of the util functions that
1495dbebde0Saustinfcui  #     use `trace.hpp` will throw a linker error because we don't have access
1505dbebde0Saustinfcui  #     to phosphor-logging in test ... yet. This issue will go away once we
1515dbebde0Saustinfcui  #     have converted all of our trace to use the `lg2` interfaces.
1525dbebde0Saustinfcui  #   - Some functions related to pdbg and dbus simply cannot be built in the
1535dbebde0Saustinfcui  #     test environment. Instead, there are alternate implementation of those
1545dbebde0Saustinfcui  #     functions to simulate them for testing (see `test/*-sim-only.cpp`).
1555dbebde0Saustinfcui  # Instead we will build a `test_util_lib` that will contain the `util` files
1565dbebde0Saustinfcui  # that we need in test along with simulated versions of some util functions.
1575dbebde0Saustinfcui
1585dbebde0Saustinfcui  # IMPORTANT NOTE:
1595dbebde0Saustinfcui  # When running GCOV reports, the Jenkins CI script explicitly ignores any
1605dbebde0Saustinfcui  # libraries and executables built in the `test/` directory. Therefore, this
1615dbebde0Saustinfcui  # `test_util_lib` library must be built here instead in order to get any GCOV
1625dbebde0Saustinfcui  # credit for the code.
1635dbebde0Saustinfcui
1645dbebde0Saustinfcui  test_args = [
1655dbebde0Saustinfcui    '-DTEST_TRACE',
1665dbebde0Saustinfcui    package_args,
1675dbebde0Saustinfcui  ]
1685dbebde0Saustinfcui
1695dbebde0Saustinfcui  test_util_srcs = [
1705dbebde0Saustinfcui    files(
1715dbebde0Saustinfcui      'util/data_file.cpp',
1725dbebde0Saustinfcui      'util/ffdc_file.cpp',
1735dbebde0Saustinfcui      'util/pdbg.cpp',
1745dbebde0Saustinfcui      'util/temporary_file.cpp',
1755dbebde0Saustinfcui      'test/dbus-sim-only.cpp',
1765dbebde0Saustinfcui      'test/pdbg-sim-only.cpp',
1775dbebde0Saustinfcui    ),
1785dbebde0Saustinfcui  ]
1795dbebde0Saustinfcui
1805dbebde0Saustinfcui  test_util_deps = [
1815dbebde0Saustinfcui    libhei_dep,
1825dbebde0Saustinfcui    libpdbg_dep,
1835dbebde0Saustinfcui    phosphor_logging_dep,
1845dbebde0Saustinfcui  ]
1855dbebde0Saustinfcui
1865dbebde0Saustinfcui  test_util_lib = static_library('test_util_lib',
1875dbebde0Saustinfcui    sources             : test_util_srcs,
1885dbebde0Saustinfcui    include_directories : incdir,
1895dbebde0Saustinfcui    dependencies        : test_util_deps,
1905dbebde0Saustinfcui    cpp_args            : test_args,
1915dbebde0Saustinfcui    install             : true,
1925dbebde0Saustinfcui  )
1935dbebde0Saustinfcui
1945dbebde0Saustinfcui  test_libs = [
1955dbebde0Saustinfcui    analyzer_lib,
1965dbebde0Saustinfcui    attn_lib,
1975dbebde0Saustinfcui    test_util_lib,
1985dbebde0Saustinfcui  ]
1995dbebde0Saustinfcui
200248cbf83SZane Shelley  subdir('test')
201248cbf83SZane Shelleyendif
202