xref: /openbmc/openpower-hw-diags/meson.build (revision 55e7fec3b6fc836749ad5f57b6213074ce29324b)
1# See README.md for details.
2project('openpower-hw-diags', 'cpp',
3        version: '0.1', meson_version: '>=0.57.0',
4        default_options: [
5          'warning_level=3',
6          'werror=true',
7          'cpp_std=c++20',
8        ])
9
10# Package directory root, which will contain required data files.
11package_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.
16package_args = [ '-DPACKAGE_DIR="' + package_dir + '/"' ]
17
18#-------------------------------------------------------------------------------
19# Versioning
20#-------------------------------------------------------------------------------
21buildinfo = 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#-------------------------------------------------------------------------------
28# Compiler
29#-------------------------------------------------------------------------------
30
31cmplr = meson.get_compiler('cpp')
32
33#-------------------------------------------------------------------------------
34# Config file
35#-------------------------------------------------------------------------------
36
37conf = configuration_data()
38
39conf.set('CONFIG_PHAL_API', get_option('phal').enabled())
40
41configure_file(input: 'config.h.in', output: 'config.h', configuration: conf)
42
43#-------------------------------------------------------------------------------
44# Include directories
45#-------------------------------------------------------------------------------
46
47# Only using the base directory. All header includes should provide the full
48# path from the base directory.
49incdir = 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.
57libhei_dep = dependency('hei', fallback : ['libhei', 'libhei_dep'])
58
59sdbusplus_dep       = dependency('sdbusplus', version : '>=1.0')
60dbus_interfaces_dep = dependency('phosphor-dbus-interfaces')
61
62libpdbg_dep = cmplr.find_library('pdbg')
63
64fmt_dep = dependency('fmt')
65
66if get_option('phal').enabled()
67  libphal_dep = cmplr.find_library('phal')
68endif
69
70# See if phosphor-logging is available, if not use test case logging code. This
71# allows for local builds outside of CI test sandbox.
72h = 'phosphor-logging/log.hpp'
73if cmplr.compiles('#include <@0@>'.format(h), name : '#include <@0@>'.format(h))
74    test_arg = []
75    phosphor_logging = true
76else
77    test_arg = [
78        '-DTEST_TRACE',
79    ]
80    phosphor_logging = false
81endif
82
83pthread = declare_dependency(link_args : '-pthread')
84lrt = declare_dependency(link_args : '-lrt')
85
86# JSON parser
87if cmplr.has_header('nlohmann/json.hpp')
88    nlohmann_json_dep = declare_dependency()
89else
90    subproject('nlohmann', required: false)
91    nlohmann_json_dep = declare_dependency(
92        include_directories: [
93            'subprojects/nlohmann/single_include',
94            'subprojects/nlohmann/single_include/nlohmann',
95        ]
96    )
97    nlohmann_json_dep = nlohmann_json_dep.as_system('system')
98endif
99
100# JSON validator
101if cmplr.has_header('valijson/validator.hpp')
102    valijson_dep = declare_dependency()
103else
104    subproject('valijson', required: false)
105    valijson_dep = declare_dependency(
106        include_directories: 'subprojects/valijson/include'
107    )
108    valijson_dep = valijson_dep.as_system('system')
109endif
110
111#-------------------------------------------------------------------------------
112# Build the local static libraries
113#-------------------------------------------------------------------------------
114
115subdir('analyzer')
116subdir('attn')
117subdir('util')
118
119hwdiags_libs = [
120    analyzer_lib,
121    attn_lib,
122    util_lib,
123]
124
125#-------------------------------------------------------------------------------
126# Build the executable
127#-------------------------------------------------------------------------------
128
129no_listener_mode = get_option('nlmode')
130
131if not no_listener_mode.disabled()
132  executable('openpower-hw-diags',
133              sources : [ 'main_nl.cpp', 'cli.cpp', buildinfo, plugins_src ],
134              dependencies : [ libhei_dep ],
135              link_with : hwdiags_libs,
136              install : true)
137else
138  executable('openpower-hw-diags',
139              sources : [ 'main.cpp', 'cli.cpp', 'listener.cpp', buildinfo,
140                          plugins_src ],
141              dependencies : [lrt, pthread, libhei_dep],
142              link_with : hwdiags_libs,
143              cpp_args : test_arg,
144              install : true)
145endif
146
147#-------------------------------------------------------------------------------
148# Test, if configured
149#-------------------------------------------------------------------------------
150
151build_tests = get_option('tests')
152
153if not build_tests.disabled()
154  subdir('test')
155endif
156