xref: /openbmc/openpower-hw-diags/meson.build (revision b971517919737064c1283aa8708768ec7b3e5f11)
1f480b739SZane Shelley# See README.md for details.
2248cbf83SZane Shelleyproject('openpower-hw-diags', 'cpp',
34e3faa23SZane Shelley        version: '0.1', meson_version: '>=0.50.0',
4248cbf83SZane Shelley        default_options: [
5248cbf83SZane Shelley          'warning_level=3',
6248cbf83SZane Shelley          'werror=true',
792e39fd9SBen Tyner          'cpp_std=c++17',
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*b9715179SBen Tynerif get_option('phal').enabled()
65*b9715179SBen Tyner  libphal_dep = cmplr.find_library('phal')
66*b9715179SBen Tynerendif
67*b9715179SBen Tyner
6813683089SBen Tyner# See if phosphor-logging is available, if not use test case logging code. This
6913683089SBen Tyner# allows for local builds outside of CI test sandbox.
7013683089SBen Tynerh = 'phosphor-logging/log.hpp'
7113683089SBen Tynerif cmplr.compiles('#include <@0@>'.format(h), name : '#include <@0@>'.format(h))
7213683089SBen Tyner    test_arg = []
7313683089SBen Tyner    phosphor_logging = true
7413683089SBen Tynerelse
7513683089SBen Tyner    test_arg = [
7613683089SBen Tyner        '-DTEST_TRACE',
7713683089SBen Tyner    ]
7813683089SBen Tyner    phosphor_logging = false
7913683089SBen Tynerendif
8013683089SBen Tyner
81c252894dSZane Shelleypthread = declare_dependency(link_args : '-pthread')
82c252894dSZane Shelleylrt = declare_dependency(link_args : '-lrt')
83c252894dSZane Shelley
845191bae9SZane Shelley# JSON parser
855191bae9SZane Shelleyif cmplr.has_header('nlohmann/json.hpp')
865191bae9SZane Shelley    nlohmann_json_dep = declare_dependency()
875191bae9SZane Shelleyelse
885191bae9SZane Shelley    subproject('nlohmann', required: false)
895191bae9SZane Shelley    nlohmann_json_dep = declare_dependency(
905191bae9SZane Shelley        include_directories: [
915191bae9SZane Shelley            'subprojects/nlohmann/single_include',
925191bae9SZane Shelley            'subprojects/nlohmann/single_include/nlohmann',
935191bae9SZane Shelley        ]
945191bae9SZane Shelley    )
955191bae9SZane Shelley    nlohmann_json_dep = nlohmann_json_dep.as_system('system')
965191bae9SZane Shelleyendif
975191bae9SZane Shelley
985191bae9SZane Shelley# JSON validator
995191bae9SZane Shelleyif cmplr.has_header('valijson/validator.hpp')
1005191bae9SZane Shelley    valijson_dep = declare_dependency()
1015191bae9SZane Shelleyelse
1025191bae9SZane Shelley    subproject('valijson', required: false)
1035191bae9SZane Shelley    valijson_dep = declare_dependency(
1045191bae9SZane Shelley        include_directories: 'subprojects/valijson/include'
1055191bae9SZane Shelley    )
1065191bae9SZane Shelley    valijson_dep = valijson_dep.as_system('system')
1075191bae9SZane Shelleyendif
1085191bae9SZane Shelley
109c252894dSZane Shelley#-------------------------------------------------------------------------------
110d9573f48SZane Shelley# Build the local static libraries
111c252894dSZane Shelley#-------------------------------------------------------------------------------
112c252894dSZane Shelley
1130205f3b3SBen Tynersubdir('analyzer')
114ef320154SBen Tynersubdir('attn')
115f80482a5SZane Shelleysubdir('util')
116248cbf83SZane Shelley
117c252894dSZane Shelleyhwdiags_libs = [
118c252894dSZane Shelley    analyzer_lib,
119c252894dSZane Shelley    attn_lib,
120c252894dSZane Shelley    util_lib,
121c252894dSZane Shelley]
122c252894dSZane Shelley
123c252894dSZane Shelley#-------------------------------------------------------------------------------
124c252894dSZane Shelley# Build the executable
125c252894dSZane Shelley#-------------------------------------------------------------------------------
1268c2f8b24SBen Tyner
127d3cda742SBen Tynerno_listener_mode = get_option('nlmode')
128d3cda742SBen Tyner
129d3cda742SBen Tynerif not no_listener_mode.disabled()
130832526dfSBen Tyner  executable('openpower-hw-diags',
131832526dfSBen Tyner              sources : [ 'main_nl.cpp', 'cli.cpp', buildinfo ],
132c252894dSZane Shelley              link_with : hwdiags_libs,
133d3cda742SBen Tyner              install : true)
134d3cda742SBen Tynerelse
135832526dfSBen Tyner  executable('openpower-hw-diags',
136832526dfSBen Tyner              sources : [ 'main.cpp', 'cli.cpp', 'listener.cpp', buildinfo ],
1378c2f8b24SBen Tyner              dependencies : [lrt, pthread],
138c252894dSZane Shelley              link_with : hwdiags_libs,
13913683089SBen Tyner              cpp_args : test_arg,
1400205f3b3SBen Tyner              install : true)
141d3cda742SBen Tynerendif
1420205f3b3SBen Tyner
143c252894dSZane Shelley#-------------------------------------------------------------------------------
144c252894dSZane Shelley# Test, if configured
145c252894dSZane Shelley#-------------------------------------------------------------------------------
146c252894dSZane Shelley
147248cbf83SZane Shelleybuild_tests = get_option('tests')
148248cbf83SZane Shelley
149248cbf83SZane Shelleyif not build_tests.disabled()
150248cbf83SZane Shelley  subdir('test')
151248cbf83SZane Shelleyendif
152