xref: /openbmc/openpower-hw-diags/meson.build (revision 135793a8)
1# See README.md for details.
2project('openpower-hw-diags', 'cpp',
3        version: '0.1', meson_version: '>=0.50.0',
4        default_options: [
5          'warning_level=3',
6          'werror=true',
7          'cpp_std=c++17',
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
64if get_option('phal').enabled()
65  libphal_dep = cmplr.find_library('phal')
66endif
67
68# See if phosphor-logging is available, if not use test case logging code. This
69# allows for local builds outside of CI test sandbox.
70h = 'phosphor-logging/log.hpp'
71if cmplr.compiles('#include <@0@>'.format(h), name : '#include <@0@>'.format(h))
72    test_arg = []
73    phosphor_logging = true
74else
75    test_arg = [
76        '-DTEST_TRACE',
77    ]
78    phosphor_logging = false
79endif
80
81pthread = declare_dependency(link_args : '-pthread')
82lrt = declare_dependency(link_args : '-lrt')
83
84# JSON parser
85if cmplr.has_header('nlohmann/json.hpp')
86    nlohmann_json_dep = declare_dependency()
87else
88    subproject('nlohmann', required: false)
89    nlohmann_json_dep = declare_dependency(
90        include_directories: [
91            'subprojects/nlohmann/single_include',
92            'subprojects/nlohmann/single_include/nlohmann',
93        ]
94    )
95    nlohmann_json_dep = nlohmann_json_dep.as_system('system')
96endif
97
98# JSON validator
99if cmplr.has_header('valijson/validator.hpp')
100    valijson_dep = declare_dependency()
101else
102    subproject('valijson', required: false)
103    valijson_dep = declare_dependency(
104        include_directories: 'subprojects/valijson/include'
105    )
106    valijson_dep = valijson_dep.as_system('system')
107endif
108
109#-------------------------------------------------------------------------------
110# Build the local static libraries
111#-------------------------------------------------------------------------------
112
113subdir('analyzer')
114subdir('attn')
115subdir('util')
116
117hwdiags_libs = [
118    analyzer_lib,
119    attn_lib,
120    util_lib,
121]
122
123#-------------------------------------------------------------------------------
124# Build the executable
125#-------------------------------------------------------------------------------
126
127no_listener_mode = get_option('nlmode')
128
129if not no_listener_mode.disabled()
130  executable('openpower-hw-diags',
131              sources : [ 'main_nl.cpp', 'cli.cpp', buildinfo ],
132              link_with : hwdiags_libs,
133              install : true)
134else
135  executable('openpower-hw-diags',
136              sources : [ 'main.cpp', 'cli.cpp', 'listener.cpp', buildinfo ],
137              dependencies : [lrt, pthread],
138              link_with : hwdiags_libs,
139              cpp_args : test_arg,
140              install : true)
141endif
142
143#-------------------------------------------------------------------------------
144# Test, if configured
145#-------------------------------------------------------------------------------
146
147build_tests = get_option('tests')
148
149if not build_tests.disabled()
150  subdir('test')
151endif
152