xref: /openbmc/pldm/meson.build (revision 5079ac4a)
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
24conf_data = configuration_data()
25if get_option('libpldmresponder').enabled()
26conf_data.set_quoted('BIOS_JSONS_DIR', '/usr/share/pldm/bios')
27conf_data.set_quoted('BIOS_TABLES_DIR', '/var/lib/pldm/bios')
28conf_data.set_quoted('PDR_JSONS_DIR', '/usr/share/pldm/pdr')
29conf_data.set_quoted('FRU_JSONS_DIR', '/usr/share/pldm/fru')
30conf_data.set_quoted('FRU_MASTER_JSON', '/usr/share/pldm/fru_master.json')
31conf_data.set_quoted('HOST_JSONS_DIR', '/usr/share/pldm/host')
32conf_data.set_quoted('EVENTS_JSONS_DIR', '/usr/share/pldm/events')
33add_project_arguments('-DLIBPLDMRESPONDER', language : ['c','cpp'])
34endif
35if get_option('softoff').enabled()
36  conf_data.set('SOFTOFF_TIMEOUT_SECONDS', get_option('softoff-timeout-seconds'))
37endif
38if get_option('oem-ibm').enabled()
39  conf_data.set_quoted('FILE_TABLE_JSON', '/usr/share/pldm/fileTable.json')
40  conf_data.set_quoted('LID_RUNNING_DIR', '/var/lib/phosphor-software-manager/hostfw/running')
41  conf_data.set_quoted('LID_ALTERNATE_DIR', '/var/lib/phosphor-software-manager/hostfw/alternate')
42  conf_data.set_quoted('LID_STAGING_DIR', '/var/lib/phosphor-software-manager/hostfw/staging')
43  conf_data.set_quoted('LID_RUNNING_PATCH_DIR', '/usr/local/share/hostfw/running')
44  conf_data.set_quoted('LID_ALTERNATE_PATCH_DIR', '/usr/local/share/hostfw/alternate')
45  conf_data.set_quoted('LID_STAGING_DIR', '/var/lib/phosphor-software-manager/hostfw/staging')
46  conf_data.set('DMA_MAXSIZE', get_option('oem-ibm-dma-maxsize'))
47  add_project_arguments('-DOEM_IBM', language : 'c')
48  add_project_arguments('-DOEM_IBM', language : 'cpp')
49endif
50conf_data.set('PLDM_VERBOSITY',get_option('verbosity'))
51conf_data.set('NUMBER_OF_REQUEST_RETRIES', get_option('number-of-request-retries'))
52conf_data.set('INSTANCE_ID_EXPIRATION_INTERVAL',get_option('instance-id-expiration-interval'))
53conf_data.set('RESPONSE_TIME_OUT',get_option('response-time-out'))
54configure_file(output: 'config.h',
55  configuration: conf_data
56)
57
58phosphor_dbus_interfaces = dependency(
59  'phosphor-dbus-interfaces',
60  fallback: ['phosphor-dbus-interfaces', 'phosphor_dbus_interfaces_dep'],
61)
62sdbusplus = dependency(
63  'sdbusplus',
64  fallback: ['sdbusplus', 'sdbusplus_dep'],
65)
66sdeventplus = dependency(
67  'sdeventplus',
68  fallback: ['sdeventplus', 'sdeventplus_dep'],
69)
70systemd = dependency('systemd')
71
72cpp = meson.get_compiler('cpp')
73
74if cpp.has_header('nlohmann/json.hpp')
75  nlohmann_json = declare_dependency()
76else
77  subproject('nlohmann-json')
78  nlohmann_json = declare_dependency(
79    include_directories: [
80      'subprojects/nlohmann-json/single_include',
81      'subprojects/nlohmann-json/single_include/nlohmann',
82    ]
83  )
84endif
85
86if cpp.has_header('CLI/CLI.hpp')
87  CLI11_dep = declare_dependency()
88else
89  CLI11_dep = dependency(
90    'CLI11',
91    fallback: [ 'CLI11', 'CLI11_dep' ],
92  )
93endif
94
95if cpp.has_header_symbol('function2/function2.hpp', 'fu2::unique_function')
96  function2_dep = declare_dependency()
97else
98  subproject('function2')
99  function2_dep = declare_dependency(
100    include_directories: [
101      'subprojects/function2/include/function2'
102    ]
103  )
104endif
105
106if get_option('oe-sdk').enabled()
107  # Setup OE SYSROOT
108  OECORE_TARGET_SYSROOT = run_command('sh', '-c', 'echo $OECORE_TARGET_SYSROOT').stdout().strip()
109  if OECORE_TARGET_SYSROOT == ''
110      error('Unable to get $OECORE_TARGET_SYSROOT, check your environment.')
111  endif
112  message('OE_SYSROOT: ' + OECORE_TARGET_SYSROOT)
113  rpath = ':'.join([OECORE_TARGET_SYSROOT + '/lib', OECORE_TARGET_SYSROOT + '/usr/lib'])
114  ld_so = run_command('sh', '-c', 'find ' + OECORE_TARGET_SYSROOT + '/lib/ld-*.so | sort -r -n | head -n1').stdout().strip()
115  dynamic_linker = ['-Wl,-dynamic-linker,' + ld_so]
116else
117  dynamic_linker = []
118endif
119
120if get_option('tests').enabled()
121    gtest = dependency('gtest', main: true, disabler: true, required: false)
122    gmock = dependency('gmock', disabler: true, required: false)
123    if not gtest.found() or not gmock.found()
124        gtest_proj = import('cmake').subproject('googletest', required: false)
125        if gtest_proj.found()
126            gtest = declare_dependency(
127                dependencies: [
128                    dependency('threads'),
129                    gtest_proj.dependency('gtest'),
130                    gtest_proj.dependency('gtest_main'),
131                ]
132            )
133            gmock = gtest_proj.dependency('gmock')
134        else
135            assert(
136                not get_option('tests').enabled(),
137                'Googletest is required if tests are enabled'
138            )
139        endif
140    endif
141endif
142
143subdir('libpldm')
144
145if get_option('libpldm-only').disabled()
146
147libpldmutils_headers = ['.']
148libpldmutils = library(
149  'pldmutils',
150  'common/utils.cpp',
151  version: meson.project_version(),
152  dependencies: [
153      libpldm_dep,
154      phosphor_dbus_interfaces,
155      nlohmann_json,
156      sdbusplus,
157  ],
158  install: true,
159  include_directories: include_directories(libpldmutils_headers),
160)
161
162libpldmutils = declare_dependency(
163  include_directories: include_directories(libpldmutils_headers),
164  link_with: libpldmutils)
165
166deps = [
167  function2_dep,
168  libpldm_dep,
169  libpldmutils,
170  nlohmann_json,
171  sdbusplus,
172  sdeventplus,
173  phosphor_dbus_interfaces,
174]
175
176if get_option('libpldmresponder').enabled()
177subdir('libpldmresponder')
178deps += [
179  libpldmresponder
180]
181endif
182
183executable(
184  'pldmd',
185  'pldmd/pldmd.cpp',
186  'pldmd/dbus_impl_requester.cpp',
187  'pldmd/instance_id.cpp',
188  'pldmd/dbus_impl_pdr.cpp',
189  implicit_include_directories: false,
190  dependencies: deps,
191  install: true,
192  install_dir: get_option('bindir'))
193
194systemd_system_unit_dir = systemd.get_variable(
195        pkgconfig: 'systemdsystemunitdir',
196        pkgconfig_define: ['prefix', get_option('prefix')])
197
198configure_file(
199  copy: true,
200  input: 'pldmd/service_files/pldmd.service',
201  install: true,
202  install_dir: systemd_system_unit_dir,
203  output: 'pldmd.service',
204)
205
206configure_file(
207  input: 'pldmd/verbosity/verbosity',
208  output: 'pldm_verbosity',
209  configuration: conf_data,
210  install: true,
211  install_dir: '/etc/default')
212
213if get_option('oem-ibm').enabled()
214  subdir('oem/ibm/service_files')
215endif
216
217subdir('pldmtool')
218
219subdir('configurations')
220
221if get_option('utilities').enabled()
222  subdir('utilities')
223endif
224
225if get_option('softoff').enabled()
226  subdir('softoff')
227endif
228
229if get_option('tests').enabled()
230  subdir('common/test')
231  subdir('host-bmc/test')
232  subdir('requester/test')
233  subdir('test')
234endif
235
236endif # pldm-only
237