xref: /openbmc/openpower-hw-diags/meson.build (revision 9cdfa247)
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
59phosphor_logging_dep = dependency('phosphor-logging',
60    fallback: ['phosphor-logging', 'phosphor_logging_dep'])
61
62sdbusplus_dep       = dependency('sdbusplus', version : '>=1.0')
63dbus_interfaces_dep = dependency('phosphor-dbus-interfaces')
64
65libpdbg_dep = cmplr.find_library('pdbg')
66
67fmt_dep = dependency('fmt')
68
69if get_option('phal').enabled()
70  libphal_dep = cmplr.find_library('phal')
71endif
72
73pthread = declare_dependency(link_args : '-pthread')
74lrt = declare_dependency(link_args : '-lrt')
75
76# JSON parser
77if cmplr.has_header('nlohmann/json.hpp')
78    nlohmann_json_dep = declare_dependency()
79else
80    subproject('nlohmann', required: false)
81    nlohmann_json_dep = declare_dependency(
82        include_directories: [
83            'subprojects/nlohmann/single_include',
84            'subprojects/nlohmann/single_include/nlohmann',
85        ]
86    )
87    nlohmann_json_dep = nlohmann_json_dep.as_system('system')
88endif
89
90# JSON validator
91if cmplr.has_header('valijson/validator.hpp')
92    valijson_dep = declare_dependency()
93else
94    subproject('valijson', required: false)
95    valijson_dep = declare_dependency(
96        include_directories: 'subprojects/valijson/include'
97    )
98    valijson_dep = valijson_dep.as_system('system')
99endif
100
101#-------------------------------------------------------------------------------
102# Build the local static libraries
103#-------------------------------------------------------------------------------
104
105subdir('analyzer')
106subdir('attn')
107subdir('util')
108
109hwdiags_libs = [
110    analyzer_lib,
111    attn_lib,
112    util_lib,
113]
114
115#-------------------------------------------------------------------------------
116# Build the executable
117#-------------------------------------------------------------------------------
118
119no_listener_mode = get_option('nlmode')
120
121if not no_listener_mode.disabled()
122  executable('openpower-hw-diags',
123              sources : [ 'main_nl.cpp', 'cli.cpp', buildinfo, plugins_src ],
124              dependencies : [ libhei_dep ],
125              link_with : hwdiags_libs,
126              install : true)
127else
128  executable('openpower-hw-diags',
129              sources : [ 'main.cpp', 'cli.cpp', 'listener.cpp', buildinfo,
130                          plugins_src ],
131              dependencies : [lrt, pthread, libhei_dep],
132              link_with : hwdiags_libs,
133              install : true)
134endif
135
136#-------------------------------------------------------------------------------
137# Test, if configured
138#-------------------------------------------------------------------------------
139
140build_tests = get_option('tests')
141
142if not build_tests.disabled()
143  subdir('test')
144endif
145