xref: /openbmc/openpower-hw-diags/meson.build (revision 55e7fec3b6fc836749ad5f57b6213074ce29324b)
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
5961465db5SZane Shelleysdbusplus_dep       = dependency('sdbusplus', version : '>=1.0')
6061465db5SZane Shelleydbus_interfaces_dep = dependency('phosphor-dbus-interfaces')
6161465db5SZane Shelley
62f80482a5SZane Shelleylibpdbg_dep = cmplr.find_library('pdbg')
63f80482a5SZane Shelley
64*55e7fec3SZane Shelleyfmt_dep = dependency('fmt')
65*55e7fec3SZane Shelley
66b9715179SBen Tynerif get_option('phal').enabled()
67b9715179SBen Tyner  libphal_dep = cmplr.find_library('phal')
68b9715179SBen Tynerendif
69b9715179SBen Tyner
7013683089SBen Tyner# See if phosphor-logging is available, if not use test case logging code. This
7113683089SBen Tyner# allows for local builds outside of CI test sandbox.
7213683089SBen Tynerh = 'phosphor-logging/log.hpp'
7313683089SBen Tynerif cmplr.compiles('#include <@0@>'.format(h), name : '#include <@0@>'.format(h))
7413683089SBen Tyner    test_arg = []
7513683089SBen Tyner    phosphor_logging = true
7613683089SBen Tynerelse
7713683089SBen Tyner    test_arg = [
7813683089SBen Tyner        '-DTEST_TRACE',
7913683089SBen Tyner    ]
8013683089SBen Tyner    phosphor_logging = false
8113683089SBen Tynerendif
8213683089SBen Tyner
83c252894dSZane Shelleypthread = declare_dependency(link_args : '-pthread')
84c252894dSZane Shelleylrt = declare_dependency(link_args : '-lrt')
85c252894dSZane Shelley
865191bae9SZane Shelley# JSON parser
875191bae9SZane Shelleyif cmplr.has_header('nlohmann/json.hpp')
885191bae9SZane Shelley    nlohmann_json_dep = declare_dependency()
895191bae9SZane Shelleyelse
905191bae9SZane Shelley    subproject('nlohmann', required: false)
915191bae9SZane Shelley    nlohmann_json_dep = declare_dependency(
925191bae9SZane Shelley        include_directories: [
935191bae9SZane Shelley            'subprojects/nlohmann/single_include',
945191bae9SZane Shelley            'subprojects/nlohmann/single_include/nlohmann',
955191bae9SZane Shelley        ]
965191bae9SZane Shelley    )
975191bae9SZane Shelley    nlohmann_json_dep = nlohmann_json_dep.as_system('system')
985191bae9SZane Shelleyendif
995191bae9SZane Shelley
1005191bae9SZane Shelley# JSON validator
1015191bae9SZane Shelleyif cmplr.has_header('valijson/validator.hpp')
1025191bae9SZane Shelley    valijson_dep = declare_dependency()
1035191bae9SZane Shelleyelse
1045191bae9SZane Shelley    subproject('valijson', required: false)
1055191bae9SZane Shelley    valijson_dep = declare_dependency(
1065191bae9SZane Shelley        include_directories: 'subprojects/valijson/include'
1075191bae9SZane Shelley    )
1085191bae9SZane Shelley    valijson_dep = valijson_dep.as_system('system')
1095191bae9SZane Shelleyendif
1105191bae9SZane Shelley
111c252894dSZane Shelley#-------------------------------------------------------------------------------
112d9573f48SZane Shelley# Build the local static libraries
113c252894dSZane Shelley#-------------------------------------------------------------------------------
114c252894dSZane Shelley
1150205f3b3SBen Tynersubdir('analyzer')
116ef320154SBen Tynersubdir('attn')
117f80482a5SZane Shelleysubdir('util')
118248cbf83SZane Shelley
119c252894dSZane Shelleyhwdiags_libs = [
120c252894dSZane Shelley    analyzer_lib,
121c252894dSZane Shelley    attn_lib,
122c252894dSZane Shelley    util_lib,
123c252894dSZane Shelley]
124c252894dSZane Shelley
125c252894dSZane Shelley#-------------------------------------------------------------------------------
126c252894dSZane Shelley# Build the executable
127c252894dSZane Shelley#-------------------------------------------------------------------------------
1288c2f8b24SBen Tyner
129d3cda742SBen Tynerno_listener_mode = get_option('nlmode')
130d3cda742SBen Tyner
131d3cda742SBen Tynerif not no_listener_mode.disabled()
132832526dfSBen Tyner  executable('openpower-hw-diags',
133475237a4SZane Shelley              sources : [ 'main_nl.cpp', 'cli.cpp', buildinfo, plugins_src ],
134475237a4SZane Shelley              dependencies : [ libhei_dep ],
135c252894dSZane Shelley              link_with : hwdiags_libs,
136d3cda742SBen Tyner              install : true)
137d3cda742SBen Tynerelse
138832526dfSBen Tyner  executable('openpower-hw-diags',
139475237a4SZane Shelley              sources : [ 'main.cpp', 'cli.cpp', 'listener.cpp', buildinfo,
140475237a4SZane Shelley                          plugins_src ],
141475237a4SZane Shelley              dependencies : [lrt, pthread, libhei_dep],
142c252894dSZane Shelley              link_with : hwdiags_libs,
14313683089SBen Tyner              cpp_args : test_arg,
1440205f3b3SBen Tyner              install : true)
145d3cda742SBen Tynerendif
1460205f3b3SBen Tyner
147c252894dSZane Shelley#-------------------------------------------------------------------------------
148c252894dSZane Shelley# Test, if configured
149c252894dSZane Shelley#-------------------------------------------------------------------------------
150c252894dSZane Shelley
151248cbf83SZane Shelleybuild_tests = get_option('tests')
152248cbf83SZane Shelley
153248cbf83SZane Shelleyif not build_tests.disabled()
154248cbf83SZane Shelley  subdir('test')
155248cbf83SZane Shelleyendif
156