blob: 101c0ce296b53b9906741052b97bf0ec31cf9a87 [file] [log] [blame]
Ed Tanousf2caadc2024-01-02 18:34:36 -08001project(
2 'bmcweb',
3 'cpp',
4 version: '1.0',
5 meson_version: '>=0.63.0',
6 default_options: [
7 'b_lto_mode=default',
8 'b_lto_threads=0',
9 'b_lto=true',
10 'b_ndebug=if-release',
11 'buildtype=debugoptimized',
12 'cpp_rtti=false',
13 'cpp_std=c++20',
14 'warning_level=3',
15 'werror=true',
16 ],
17)
Manojkiran Edaaf6298d2020-05-27 08:51:32 +053018
19# Project related links
20
21project_pretty_name = 'bmcweb'
22project_url = 'https://github.com/openbmc/' + project_pretty_name
23project_issues_url = project_url + '/issues/new'
Ed Tanousf2caadc2024-01-02 18:34:36 -080024summary('Issues', project_issues_url, section: 'Report Issues')
Manojkiran Edaaf6298d2020-05-27 08:51:32 +053025
26# Validate the c++ Standard
27
Patrick Williamsc52ee722021-10-06 15:17:42 -050028if get_option('cpp_std') != 'c++20'
29 error('This project requires c++20 support')
Manojkiran Edaaf6298d2020-05-27 08:51:32 +053030endif
31
32# Get compiler and default build type
33
34cxx = meson.get_compiler('cpp')
35build = get_option('buildtype')
36optimization = get_option('optimization')
Ed Tanousf2caadc2024-01-02 18:34:36 -080037summary('Build Type', build, section: 'Build Info')
38summary('Optimization', optimization, section: 'Build Info')
Ed Tanous5e34b672021-02-05 14:21:27 -080039
Manojkiran Edaaf6298d2020-05-27 08:51:32 +053040# remove debug information for minsize buildtype
Ed Tanousf2caadc2024-01-02 18:34:36 -080041if (get_option('buildtype') == 'minsize')
42 add_project_arguments(['-fdata-sections', '-ffunction-sections'], language: 'cpp')
43 add_project_arguments('-DNDEBUG', language: 'cpp')
Manojkiran Edaaf6298d2020-05-27 08:51:32 +053044endif
45
Ed Tanousf2caadc2024-01-02 18:34:36 -080046if (get_option('dns-resolver') == 'systemd-dbus')
47 add_project_arguments('-DBMCWEB_DBUS_DNS_RESOLVER', language: 'cpp')
Ed Tanousf8ca6d72022-06-28 12:12:03 -070048endif
49
Manojkiran Edaaf6298d2020-05-27 08:51:32 +053050# Disable lto when compiling with no optimization
Ed Tanousf2caadc2024-01-02 18:34:36 -080051if (get_option('optimization') == '0')
52 add_project_arguments('-fno-lto', language: 'cpp')
53 message('Disabling lto & its supported features as optimization is disabled')
Manojkiran Edaaf6298d2020-05-27 08:51:32 +053054endif
55
56# Include Directories
57
Ed Tanousf2caadc2024-01-02 18:34:36 -080058incdir = include_directories('include', 'redfish-core/include', 'redfish-core/lib', 'http')
Manojkiran Edaaf6298d2020-05-27 08:51:32 +053059
Ed Tanousf2caadc2024-01-02 18:34:36 -080060if (get_option('tests').allowed())
Ed Tanous25b54db2024-04-17 15:40:31 -070061 summary('unittest', 'NA', section: 'Features')
Manojkiran Edaaf6298d2020-05-27 08:51:32 +053062endif
63
Manojkiran Edaaf6298d2020-05-27 08:51:32 +053064# Add compiler arguments
65
Ed Tanousade3f092024-03-13 13:28:36 -070066if (cxx.get_id() == 'clang')
Ed Tanousf2caadc2024-01-02 18:34:36 -080067 if (cxx.version().version_compare('<17.0'))
68 error('This project requires clang-17 or higher')
69 endif
70 add_project_arguments(
71 '-Weverything',
72 '-Wformat=2',
73 '-Wno-c++98-compat-pedantic',
74 '-Wno-c++98-compat',
75 '-Wno-documentation-unknown-command',
76 '-Wno-documentation',
77 '-Wno-exit-time-destructors',
78 '-Wno-global-constructors',
79 '-Wno-newline-eof',
80 '-Wno-padded',
81 '-Wno-shadow',
82 '-Wno-used-but-marked-unused',
83 '-Wno-weak-vtables',
84 '-Wno-switch-enum',
85 '-Wno-unused-macros',
86 '-Wno-covered-switch-default',
87 language: 'cpp',
88 )
Manojkiran Edaaf6298d2020-05-27 08:51:32 +053089endif
90
Ed Tanousade3f092024-03-13 13:28:36 -070091if (cxx.get_id() == 'gcc')
Ed Tanousf2caadc2024-01-02 18:34:36 -080092 if (cxx.version().version_compare('<13.0'))
93 error('This project requires gcc-13 or higher')
94 endif
Manojkiran Edaaf6298d2020-05-27 08:51:32 +053095
Ed Tanousf2caadc2024-01-02 18:34:36 -080096 add_project_arguments(
97 '-Wformat=2',
98 '-Wcast-align',
99 '-Wconversion',
100 '-Woverloaded-virtual',
101 '-Wsign-conversion',
102 '-Wunused',
103 '-Wduplicated-cond',
104 '-Wduplicated-branches',
105 '-Wlogical-op',
106 '-Wnull-dereference',
107 '-Wunused-parameter',
108 '-Wdouble-promotion',
109 '-Wshadow',
110 '-Wno-psabi',
111 '-Wno-attributes',
112 language: 'cpp',
113 )
Ed Tanousc66403c2021-09-22 15:28:57 -0700114endif
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530115
Ed Tanousc66403c2021-09-22 15:28:57 -0700116if (get_option('buildtype') != 'plain')
Ed Tanousf2caadc2024-01-02 18:34:36 -0800117 if (get_option('b_lto') == true and get_option('optimization') != '0')
118 # Reduce the binary size by removing unnecessary
119 # dynamic symbol table entries
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530120
Ed Tanousf2caadc2024-01-02 18:34:36 -0800121 add_project_arguments(
122 cxx.get_supported_arguments(
123 [
124 '-fno-fat-lto-objects',
125 '-fvisibility=hidden',
126 '-fvisibility-inlines-hidden',
127 ],
128 ),
129 language: 'cpp',
130 )
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530131
Ed Tanousf2caadc2024-01-02 18:34:36 -0800132 if cxx.has_link_argument('-Wl,--exclude-libs,ALL')
133 add_project_link_arguments('-Wl,--exclude-libs,ALL', language: 'cpp')
134 endif
George Liue8204932021-02-01 14:42:49 +0800135 endif
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530136endif
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530137# Set Compiler Security flags
138
139security_flags = [
Ed Tanousf2caadc2024-01-02 18:34:36 -0800140 '-fstack-protector-strong',
141 '-fPIE',
142 '-fPIC',
143 '-D_FORTIFY_SOURCE=2',
144 '-Wformat',
145 '-Wformat-security',
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530146]
147
148## Add security flags for builds of type 'release','debugoptimized' and 'minsize'
149
Ed Tanousf2caadc2024-01-02 18:34:36 -0800150if not (
151 get_option('buildtype') == 'plain'
152 or get_option('buildtype').startswith('debug')
153)
154 add_project_arguments(cxx.get_supported_arguments([security_flags]), language: 'cpp')
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530155endif
156
157# Boost dependency configuration
158
159add_project_arguments(
Ed Tanousf2caadc2024-01-02 18:34:36 -0800160 cxx.get_supported_arguments(
161 [
162 '-DBOOST_ASIO_DISABLE_CONCEPTS',
163 '-DBOOST_ALL_NO_LIB',
164 '-DBOOST_ALLOW_DEPRECATED_HEADERS',
165 '-DBOOST_ASIO_DISABLE_THREADS',
166 '-DBOOST_ASIO_NO_DEPRECATED',
167 '-DBOOST_ASIO_SEPARATE_COMPILATION',
168 '-DBOOST_BEAST_SEPARATE_COMPILATION',
169 '-DBOOST_EXCEPTION_DISABLE',
170 '-DBOOST_NO_EXCEPTIONS',
171 '-DBOOST_URL_NO_SOURCE_LOCATION',
172 '-DJSON_NOEXCEPTION',
173 '-DOPENSSL_NO_FILENAMES',
174 '-DSDBUSPLUS_DISABLE_BOOST_COROUTINES',
175 ],
176 ),
177 language: 'cpp',
178)
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530179
180# Find the dependency modules, if not found use meson wrap to get them
181# automatically during the configure step
Jason M. Billsceb8ddc2020-11-23 14:38:39 -0800182bmcweb_dependencies = []
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530183
Nan Zhou8682c5a2021-11-13 11:00:07 -0800184pam = cxx.find_library('pam', required: true)
Ed Tanousf2caadc2024-01-02 18:34:36 -0800185atomic = cxx.find_library('atomic', required: true)
Ed Tanouse7923992023-12-03 14:14:02 -0800186bmcweb_dependencies += [pam, atomic]
187
Ed Tanousf2caadc2024-01-02 18:34:36 -0800188openssl = dependency('openssl', required: false, version: '>=3.0.0')
Ed Tanouse7923992023-12-03 14:14:02 -0800189if not openssl.found() or get_option('b_sanitize') != 'none'
Ed Tanousf2caadc2024-01-02 18:34:36 -0800190 openssl_proj = subproject(
191 'openssl',
192 required: true,
193 default_options: ['warning_level=0', 'werror=false'],
194 )
195 openssl = openssl_proj.get_variable('openssl_dep')
196 openssl = openssl.as_system('system')
Ed Tanouse7923992023-12-03 14:14:02 -0800197endif
198bmcweb_dependencies += [openssl]
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530199
Ed Tanousf2caadc2024-01-02 18:34:36 -0800200nghttp2 = dependency('libnghttp2', version: '>=1.52.0', required: false)
Ed Tanousfca2cbe2021-01-28 14:49:59 -0800201if not nghttp2.found()
Ed Tanousf2caadc2024-01-02 18:34:36 -0800202 cmake = import('cmake')
203 opt_var = cmake.subproject_options()
Ed Tanous211cfa42024-04-17 13:43:14 -0700204 opt_var.add_cmake_defines(
205 {
206 'ENABLE_LIB_ONLY': true,
207 'ENABLE_STATIC_LIB': true,
208 },
209 )
Ed Tanousf2caadc2024-01-02 18:34:36 -0800210 nghttp2_ex = cmake.subproject('nghttp2', options: opt_var)
Ed Tanous211cfa42024-04-17 13:43:14 -0700211 nghttp2 = nghttp2_ex.dependency('nghttp2')
Ed Tanousfca2cbe2021-01-28 14:49:59 -0800212endif
213bmcweb_dependencies += nghttp2
214
Ed Tanousf2caadc2024-01-02 18:34:36 -0800215sdbusplus = dependency('sdbusplus', required: false, include_type: 'system')
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530216if not sdbusplus.found()
Ed Tanousf2caadc2024-01-02 18:34:36 -0800217 sdbusplus_proj = subproject('sdbusplus', required: true)
218 sdbusplus = sdbusplus_proj.get_variable('sdbusplus_dep')
219 sdbusplus = sdbusplus.as_system('system')
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530220endif
Jason M. Billsceb8ddc2020-11-23 14:38:39 -0800221bmcweb_dependencies += sdbusplus
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530222
Ed Tanousc9374ff2023-05-26 09:42:08 -0700223tinyxml = dependency(
224 'tinyxml2',
Cody Smith3a097b22022-05-19 14:22:32 -0700225 include_type: 'system',
Ed Tanousc9374ff2023-05-26 09:42:08 -0700226 version: '>=9.0.0',
Konstantin Aladyshev60e299b2024-04-03 11:44:51 +0300227 default_options: ['tests=false'],
Cody Smith3a097b22022-05-19 14:22:32 -0700228)
Ed Tanousc9374ff2023-05-26 09:42:08 -0700229if not tinyxml.found()
230 tinyxml_proj = subproject('tinyxml2', required: true)
231 tinyxml = tinyxml_proj.get_variable('tinyxml_dep')
232 tinyxml = tinyxml.as_system('system')
233endif
Cody Smith3a097b22022-05-19 14:22:32 -0700234bmcweb_dependencies += tinyxml
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530235
236systemd = dependency('systemd')
237zlib = dependency('zlib')
Jason M. Billsceb8ddc2020-11-23 14:38:39 -0800238bmcweb_dependencies += [systemd, zlib]
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530239
Patrick Williamsdfd55472023-12-07 11:50:37 -0600240nlohmann_json_dep = dependency('nlohmann_json', version: '>=3.11.2', include_type: 'system')
241bmcweb_dependencies += nlohmann_json_dep
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530242
Carson Labrado2b5b4da2023-10-18 00:02:10 +0000243boost = dependency(
Ed Tanousf2caadc2024-01-02 18:34:36 -0800244 'boost',
245 modules: [
246 'url',
Carson Labrado2b5b4da2023-10-18 00:02:10 +0000247 ],
Ed Tanousf2caadc2024-01-02 18:34:36 -0800248 version: '>=1.84.0',
249 required: false,
250 include_type: 'system',
Carson Labrado2b5b4da2023-10-18 00:02:10 +0000251)
Ed Tanous6fd29552023-10-04 09:40:14 -0700252if boost.found()
Ed Tanousf2caadc2024-01-02 18:34:36 -0800253 bmcweb_dependencies += [boost]
Ed Tanous6fd29552023-10-04 09:40:14 -0700254else
Ed Tanousf2caadc2024-01-02 18:34:36 -0800255 cmake = import('cmake')
256 opt = cmake.subproject_options()
257 opt.add_cmake_defines(
258 {
259 'BOOST_INCLUDE_LIBRARIES': 'asio;beast;callable_traits;headers;process;type_index;url;uuid',
260 'BUILD_SHARED_LIBS': 'OFF',
261 },
262 )
Ed Tanous144983c2024-03-28 00:39:10 -0700263
Ed Tanousf2caadc2024-01-02 18:34:36 -0800264 boost = cmake.subproject('boost', required: true, options: opt)
265 boost_asio = boost.dependency('boost_asio').as_system()
266 boost_beast = boost.dependency('boost_beast').as_system()
267 boost_callable_traits = boost.dependency('boost_callable_traits').as_system()
268 boost_headers = boost.dependency('boost_headers').as_system()
269 boost_process = boost.dependency('boost_process').as_system()
270 boost_type_index = boost.dependency('boost_type_index').as_system()
271 boost_url = boost.dependency('boost_url').as_system()
272 boost_uuid = boost.dependency('boost_uuid').as_system()
273 bmcweb_dependencies += [
274 boost_asio,
275 boost_beast,
276 boost_callable_traits,
277 boost_headers,
278 boost_process,
279 boost_type_index,
280 boost_url,
281 boost_uuid,
282 ]
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530283endif
284
Patrick Williams549bed22023-11-29 06:45:06 -0600285if get_option('tests').allowed()
Ed Tanousf2caadc2024-01-02 18:34:36 -0800286 gtest = dependency(
287 'gtest',
288 main: true,
289 version: '>=1.14.0',
290 disabler: true,
291 required: false,
292 )
293 gmock = dependency('gmock', required: false)
294 if not gtest.found() and get_option('tests').allowed()
295 gtest_proj = subproject('gtest', required: true)
296 gtest = gtest_proj.get_variable('gtest_main_dep')
297 gmock = gtest_proj.get_variable('gmock_dep')
298 endif
299 gtest = gtest.as_system('system')
300 gmock = gmock.as_system('system')
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530301endif
302
Patrick Williams4efe3e02023-04-12 08:05:58 -0500303systemd_system_unit_dir = systemd.get_variable('systemdsystemunitdir')
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530304
Ed Tanousf2caadc2024-01-02 18:34:36 -0800305bindir = get_option('prefix') + '/' + get_option('bindir')
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530306
Ed Tanousf2caadc2024-01-02 18:34:36 -0800307summary(
308 {
309 'prefix': get_option('prefix'),
310 'bindir': bindir,
311 'systemd unit directory': systemd_system_unit_dir,
312 },
313 section: 'Directories',
314)
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530315
Ed Tanousf2caadc2024-01-02 18:34:36 -0800316install_subdir('static', install_dir: 'share/www', strip_directory: true)
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530317
Nan Zhou307386e2022-10-12 20:29:34 +0000318# Config subdirectory
319
320subdir('config')
321bmcweb_dependencies += conf_h_dep
322
Ed Tanous02f1cd92021-10-27 12:09:06 -0700323# Source files
Nan Zhou0ad63df2022-10-17 23:03:21 +0000324fs = import('fs')
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530325
Nan Zhou0ad63df2022-10-17 23:03:21 +0000326srcfiles_bmcweb = files(
Ed Tanousf2caadc2024-01-02 18:34:36 -0800327 # end large files
Ed Tanous3cd70722024-04-06 09:24:01 -0700328
Ed Tanousf2caadc2024-01-02 18:34:36 -0800329 'redfish-core/src/error_messages.cpp',
330 # Begin large files, should be at the beginning
331 'redfish-core/src/redfish.cpp',
332 'redfish-core/src/registries.cpp',
333 'redfish-core/src/utils/dbus_utils.cpp',
334 'redfish-core/src/utils/json_utils.cpp',
335 'redfish-core/src/utils/time_utils.cpp',
336 'src/boost_asio.cpp',
337 'src/boost_asio_ssl.cpp',
338 'src/boost_beast.cpp',
339 'src/dbus_singleton.cpp',
340 'src/json_html_serializer.cpp',
341 'src/ossl_random.cpp',
342 'src/webserver_run.cpp',
Nan Zhou0ad63df2022-10-17 23:03:21 +0000343)
Ed Tanous02f1cd92021-10-27 12:09:06 -0700344
Ed Tanous42bbcd82023-01-07 18:04:28 -0800345bmcweblib = static_library(
Ed Tanousf2caadc2024-01-02 18:34:36 -0800346 'bmcweblib',
347 srcfiles_bmcweb,
348 include_directories: incdir,
349 dependencies: bmcweb_dependencies,
Ed Tanous42bbcd82023-01-07 18:04:28 -0800350)
351
Ed Tanous02f1cd92021-10-27 12:09:06 -0700352# Generate the bmcweb executable
353executable(
Ed Tanousf2caadc2024-01-02 18:34:36 -0800354 'bmcweb',
355 'src/webserver_main.cpp',
356 include_directories: incdir,
357 dependencies: bmcweb_dependencies,
358 link_with: bmcweblib,
359 link_args: '-Wl,--gc-sections',
360 install: true,
361 install_dir: bindir,
Ed Tanous02f1cd92021-10-27 12:09:06 -0700362)
363
Nan Zhou0ad63df2022-10-17 23:03:21 +0000364srcfiles_unittest = files(
Ed Tanousf2caadc2024-01-02 18:34:36 -0800365 'test/http/crow_getroutes_test.cpp',
366 'test/http/http2_connection_test.cpp',
367 'test/http/http_body_test.cpp',
368 'test/http/http_connection_test.cpp',
369 'test/http/http_response_test.cpp',
370 'test/http/mutual_tls.cpp',
371 'test/http/mutual_tls_meta.cpp',
372 'test/http/parsing_test.cpp',
373 'test/http/router_test.cpp',
374 'test/http/server_sent_event_test.cpp',
375 'test/http/utility_test.cpp',
376 'test/http/verb_test.cpp',
377 'test/include/async_resolve_test.cpp',
378 'test/include/credential_pipe_test.cpp',
379 'test/include/dbus_utility_test.cpp',
380 'test/include/google/google_service_root_test.cpp',
381 'test/include/http_utility_test.cpp',
382 'test/include/human_sort_test.cpp',
383 'test/include/ibm/configfile_test.cpp',
Ed Tanousf2caadc2024-01-02 18:34:36 -0800384 'test/include/json_html_serializer.cpp',
385 'test/include/multipart_test.cpp',
386 'test/include/openbmc_dbus_rest_test.cpp',
387 'test/include/ossl_random.cpp',
388 'test/include/str_utility_test.cpp',
389 'test/redfish-core/include/privileges_test.cpp',
390 'test/redfish-core/include/redfish_aggregator_test.cpp',
391 'test/redfish-core/include/registries_test.cpp',
392 'test/redfish-core/include/utils/dbus_utils.cpp',
393 'test/redfish-core/include/utils/hex_utils_test.cpp',
394 'test/redfish-core/include/utils/ip_utils_test.cpp',
395 'test/redfish-core/include/utils/json_utils_test.cpp',
396 'test/redfish-core/include/utils/query_param_test.cpp',
397 'test/redfish-core/include/utils/stl_utils_test.cpp',
398 'test/redfish-core/include/utils/time_utils_test.cpp',
399 'test/redfish-core/lib/chassis_test.cpp',
400 'test/redfish-core/lib/log_services_dump_test.cpp',
401 'test/redfish-core/lib/log_services_test.cpp',
402 'test/redfish-core/lib/manager_diagnostic_data_test.cpp',
403 'test/redfish-core/lib/power_subsystem_test.cpp',
404 'test/redfish-core/lib/sensors_test.cpp',
405 'test/redfish-core/lib/service_root_test.cpp',
406 'test/redfish-core/lib/system_test.cpp',
407 'test/redfish-core/lib/thermal_subsystem_test.cpp',
408 'test/redfish-core/lib/update_service_test.cpp',
Nan Zhou0ad63df2022-10-17 23:03:21 +0000409)
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530410
Ed Tanousf2caadc2024-01-02 18:34:36 -0800411if (get_option('tests').allowed())
Ed Tanous02f1cd92021-10-27 12:09:06 -0700412 # generate the test executable
Nan Zhou0ad63df2022-10-17 23:03:21 +0000413 foreach test_src : srcfiles_unittest
Ed Tanousf2caadc2024-01-02 18:34:36 -0800414 test_bin = executable(
415 fs.stem(test_src),
416 test_src,
417 link_with: bmcweblib,
418 include_directories: incdir,
419 install_dir: bindir,
420 dependencies: bmcweb_dependencies
421 + [
422 gtest,
423 gmock,
424 ],
425 )
426 test(fs.stem(test_src), test_bin)
Nan Zhou0ad63df2022-10-17 23:03:21 +0000427 endforeach
Manojkiran Edaaf6298d2020-05-27 08:51:32 +0530428endif