xref: /openbmc/pldm/meson.build (revision a114c1075310e5fa24211a4796fe1ed25b828d69)
1project('pldm', ['c', 'cpp'],
2        version: '0.1', meson_version: '>=0.57.0',
3        default_options: [
4          'warning_level=3',
5          'default_library=shared',
6          'werror=true',
7          'cpp_std=c++20',
8          'buildtype=debugoptimized'
9        ])
10
11# Wno-psabi reduces the number of "Note:" messages when cross-compiling some STL
12# stuff for ARM. See https://stackoverflow.com/questions/48149323/strange-gcc-warning-when-compiling-qt-project
13# Basically, gcc 6 and gcc 7 are not ABI compatible, but since the whole OpenBMC
14# project uses the same compiler, we can safely ignmore these info notes.
15add_project_arguments('-Wno-psabi', language: 'cpp')
16
17
18# Disable FORTIFY_SOURCE when compiling with no optimization
19if(get_option('optimization') == '0')
20  add_project_arguments('-U_FORTIFY_SOURCE',language:['cpp','c'])
21  message('Disabling FORTIFY_SOURCE as optimization is set to 0')
22endif
23
24package_datadir = join_paths(get_option('prefix'), get_option('datadir'), meson.project_name())
25package_localstatedir = join_paths(get_option('prefix'), get_option('localstatedir'), meson.project_name())
26
27conf_data = configuration_data()
28if get_option('libpldmresponder').enabled()
29conf_data.set_quoted('BIOS_JSONS_DIR', join_paths(package_datadir, 'bios'))
30conf_data.set_quoted('BIOS_TABLES_DIR', join_paths(package_localstatedir, 'bios'))
31conf_data.set_quoted('PDR_JSONS_DIR', join_paths(package_datadir, 'pdr'))
32conf_data.set_quoted('FRU_JSONS_DIR', join_paths(package_datadir, 'fru'))
33conf_data.set_quoted('FRU_MASTER_JSON', join_paths(package_datadir, 'fru_master.json'))
34conf_data.set_quoted('HOST_JSONS_DIR', join_paths(package_datadir, 'host'))
35conf_data.set_quoted('EVENTS_JSONS_DIR', join_paths(package_datadir, 'events'))
36conf_data.set('HEARTBEAT_TIMEOUT', get_option('heartbeat-timeout-seconds'))
37add_project_arguments('-DLIBPLDMRESPONDER', language : ['c','cpp'])
38endif
39if get_option('softoff').enabled()
40  conf_data.set('SOFTOFF_TIMEOUT_SECONDS', get_option('softoff-timeout-seconds'))
41endif
42if get_option('oem-ibm').enabled()
43  conf_data.set_quoted('FILE_TABLE_JSON', join_paths(package_datadir, 'fileTable.json'))
44  conf_data.set_quoted('LID_RUNNING_DIR', '/var/lib/phosphor-software-manager/hostfw/running')
45  conf_data.set_quoted('LID_ALTERNATE_DIR', '/var/lib/phosphor-software-manager/hostfw/alternate')
46  conf_data.set_quoted('LID_STAGING_DIR', '/var/lib/phosphor-software-manager/hostfw/staging')
47  conf_data.set_quoted('LID_RUNNING_PATCH_DIR', '/usr/local/share/hostfw/running')
48  conf_data.set_quoted('LID_ALTERNATE_PATCH_DIR', '/usr/local/share/hostfw/alternate')
49  conf_data.set_quoted('LID_STAGING_DIR', '/var/lib/phosphor-software-manager/hostfw/staging')
50  conf_data.set('DMA_MAXSIZE', get_option('oem-ibm-dma-maxsize'))
51  add_project_arguments('-DOEM_IBM', language : 'c')
52  add_project_arguments('-DOEM_IBM', language : 'cpp')
53endif
54conf_data.set('PLDM_VERBOSITY',get_option('verbosity'))
55conf_data.set('NUMBER_OF_REQUEST_RETRIES', get_option('number-of-request-retries'))
56conf_data.set('INSTANCE_ID_EXPIRATION_INTERVAL',get_option('instance-id-expiration-interval'))
57conf_data.set('RESPONSE_TIME_OUT',get_option('response-time-out'))
58if get_option('libpldm-only').disabled()
59  conf_data.set_quoted('HOST_EID_PATH', join_paths(package_datadir, 'host_eid'))
60endif
61configure_file(output: 'config.h',
62  configuration: conf_data
63)
64
65phosphor_dbus_interfaces = dependency(
66  'phosphor-dbus-interfaces',
67  fallback: ['phosphor-dbus-interfaces', 'phosphor_dbus_interfaces_dep'],
68)
69sdbusplus = dependency(
70  'sdbusplus',
71  fallback: ['sdbusplus', 'sdbusplus_dep'],
72)
73sdeventplus = dependency(
74  'sdeventplus',
75  fallback: ['sdeventplus', 'sdeventplus_dep'],
76)
77
78cpp = meson.get_compiler('cpp')
79
80if cpp.has_header('nlohmann/json.hpp')
81  nlohmann_json = declare_dependency()
82else
83  subproject('nlohmann-json')
84  nlohmann_json = declare_dependency(
85    include_directories: [
86      'subprojects/nlohmann-json/single_include',
87      'subprojects/nlohmann-json/single_include/nlohmann',
88    ]
89  )
90endif
91
92if cpp.has_header('CLI/CLI.hpp')
93  CLI11_dep = declare_dependency()
94else
95  CLI11_dep = dependency(
96    'CLI11',
97    fallback: [ 'CLI11', 'CLI11_dep' ],
98  )
99endif
100
101if cpp.has_header_symbol('function2/function2.hpp', 'fu2::unique_function')
102  function2_dep = declare_dependency()
103else
104  subproject('function2')
105  function2_dep = declare_dependency(
106    include_directories: [
107      'subprojects/function2/include/function2'
108    ]
109  )
110endif
111
112if get_option('oe-sdk').enabled()
113  # Setup OE SYSROOT
114  OECORE_TARGET_SYSROOT = run_command('sh', '-c', 'echo $OECORE_TARGET_SYSROOT').stdout().strip()
115  if OECORE_TARGET_SYSROOT == ''
116      error('Unable to get $OECORE_TARGET_SYSROOT, check your environment.')
117  endif
118  message('OE_SYSROOT: ' + OECORE_TARGET_SYSROOT)
119  rpath = ':'.join([OECORE_TARGET_SYSROOT + '/lib', OECORE_TARGET_SYSROOT + '/usr/lib'])
120  ld_so = run_command('sh', '-c', 'find ' + OECORE_TARGET_SYSROOT + '/lib/ld-*.so | sort -r -n | head -n1').stdout().strip()
121  dynamic_linker = ['-Wl,-dynamic-linker,' + ld_so]
122else
123  dynamic_linker = []
124endif
125
126if get_option('tests').enabled()
127    gtest = dependency('gtest', main: true, disabler: true, required: false)
128    gmock = dependency('gmock', disabler: true, required: false)
129    if not gtest.found() or not gmock.found()
130        gtest_proj = import('cmake').subproject('googletest', required: false)
131        if gtest_proj.found()
132            gtest = declare_dependency(
133                dependencies: [
134                    dependency('threads'),
135                    gtest_proj.dependency('gtest'),
136                    gtest_proj.dependency('gtest_main'),
137                ]
138            )
139            gmock = gtest_proj.dependency('gmock')
140        else
141            assert(
142                not get_option('tests').enabled(),
143                'Googletest is required if tests are enabled'
144            )
145        endif
146    endif
147endif
148
149subdir('libpldm')
150
151if get_option('libpldm-only').disabled()
152
153libpldmutils_headers = ['.']
154libpldmutils = library(
155  'pldmutils',
156  'common/utils.cpp',
157  version: meson.project_version(),
158  dependencies: [
159      libpldm_dep,
160      phosphor_dbus_interfaces,
161      nlohmann_json,
162      sdbusplus,
163  ],
164  install: true,
165  include_directories: include_directories(libpldmutils_headers),
166)
167
168libpldmutils = declare_dependency(
169  include_directories: include_directories(libpldmutils_headers),
170  link_with: libpldmutils)
171
172deps = [
173  function2_dep,
174  libpldm_dep,
175  libpldmutils,
176  nlohmann_json,
177  sdbusplus,
178  sdeventplus,
179  phosphor_dbus_interfaces,
180]
181
182if get_option('libpldmresponder').enabled()
183subdir('libpldmresponder')
184deps += [
185  libpldmresponder
186]
187endif
188
189executable(
190  'pldmd',
191  'pldmd/pldmd.cpp',
192  'pldmd/dbus_impl_requester.cpp',
193  'pldmd/instance_id.cpp',
194  'pldmd/dbus_impl_pdr.cpp',
195  implicit_include_directories: false,
196  dependencies: deps,
197  install: true,
198  install_dir: get_option('bindir'))
199
200if get_option('systemd').enabled()
201  systemd_system_unit_dir = dependency('systemd').get_variable(
202          pkgconfig: 'systemdsystemunitdir')
203
204  configure_file(
205    copy: true,
206    input: 'pldmd/service_files/pldmd.service',
207    install: true,
208    install_dir: systemd_system_unit_dir,
209    output: 'pldmd.service',
210  )
211
212  configure_file(
213    input: 'pldmd/verbosity/verbosity',
214    output: 'pldm_verbosity',
215    configuration: conf_data,
216    install: true,
217    install_dir: join_paths(get_option('sysconfdir'), 'default'))
218
219  if get_option('oem-ibm').enabled()
220    subdir('oem/ibm/service_files')
221  endif
222endif
223
224subdir('pldmtool')
225
226subdir('configurations')
227
228if get_option('utilities').enabled()
229  subdir('utilities')
230endif
231
232if get_option('softoff').enabled()
233  subdir('softoff')
234endif
235
236if get_option('tests').enabled()
237  subdir('common/test')
238  subdir('host-bmc/test')
239  subdir('requester/test')
240  subdir('test')
241endif
242
243endif # pldm-only
244