Manojkiran Eda | af6298d | 2020-05-27 08:51:32 +0530 | [diff] [blame] | 1 | project('bmcweb', 'cpp', |
| 2 | version : '1.0', |
| 3 | meson_version: '>=0.53.2', |
| 4 | default_options: [ |
| 5 | 'werror=true', |
| 6 | 'warning_level=3', |
| 7 | 'cpp_std=c++17', |
| 8 | 'buildtype=debugoptimized', |
| 9 | 'b_ndebug=if-release', |
| 10 | 'b_lto=true', |
| 11 | # enable when https://github.com/chriskohlhoff/asio/issues/533 |
| 12 | # is resolved. ASIO default executor doesn't build with no-rtti |
| 13 | #'cpp_rtti=false' |
| 14 | ]) |
| 15 | |
| 16 | # Project related links |
| 17 | |
| 18 | project_pretty_name = 'bmcweb' |
| 19 | project_url = 'https://github.com/openbmc/' + project_pretty_name |
| 20 | project_issues_url = project_url + '/issues/new' |
| 21 | summary('Issues',project_issues_url, section: 'Report Issues') |
| 22 | |
| 23 | # Validate the c++ Standard |
| 24 | |
| 25 | if get_option('cpp_std') != 'c++17' |
| 26 | error('This project requires c++17 support') |
| 27 | endif |
| 28 | |
| 29 | # Get compiler and default build type |
| 30 | |
| 31 | cxx = meson.get_compiler('cpp') |
| 32 | build = get_option('buildtype') |
| 33 | optimization = get_option('optimization') |
| 34 | summary('Build Type',build, section : 'Build Info') |
| 35 | summary('Optimization',optimization, section : 'Build Info') |
| 36 | |
Ed Tanous | 5e34b67 | 2021-02-05 14:21:27 -0800 | [diff] [blame] | 37 | |
Manojkiran Eda | af6298d | 2020-05-27 08:51:32 +0530 | [diff] [blame] | 38 | # remove debug information for minsize buildtype |
| 39 | if(get_option('buildtype') == 'minsize') |
Ed Tanous | 5e34b67 | 2021-02-05 14:21:27 -0800 | [diff] [blame] | 40 | add_project_arguments(['-fdata-sections', '-ffunction-sections'], language : 'cpp') |
Manojkiran Eda | af6298d | 2020-05-27 08:51:32 +0530 | [diff] [blame] | 41 | add_project_arguments('-DNDEBUG', language : 'cpp') |
| 42 | endif |
| 43 | |
| 44 | # Disable lto when compiling with no optimization |
| 45 | if(get_option('optimization') == '0') |
| 46 | add_project_arguments('-fno-lto', language: 'cpp') |
| 47 | message('Disabling lto & its supported features as optimization is disabled') |
| 48 | endif |
| 49 | |
| 50 | # Include Directories |
| 51 | |
| 52 | incdir = include_directories('include','redfish-core/include', |
| 53 | 'redfish-core/lib','http') |
| 54 | |
| 55 | # Get the options and enable the respective features |
| 56 | ## create a MAP of "options : feature_flag" |
| 57 | |
| 58 | feature_map = { |
| 59 | 'insecure-disable-auth' : '-DBMCWEB_INSECURE_DISABLE_AUTHENTICATION', |
| 60 | 'insecure-disable-csrf' : '-DBMCWEB_INSECURE_DISABLE_CSRF_PREVENTION', |
| 61 | 'insecure-disable-ssl' : '-DBMCWEB_INSECURE_DISABLE_SSL', |
| 62 | 'insecure-disable-xss' : '-DBMCWEB_INSECURE_DISABLE_XSS_PREVENTION', |
| 63 | 'host-serial-socket' : '-DBMCWEB_ENABLE_HOST_SERIAL_WEBSOCKET', |
| 64 | 'ibm-management-console' : '-DBMCWEB_ENABLE_IBM_MANAGEMENT_CONSOLE', |
| 65 | 'kvm' : '-DBMCWEB_ENABLE_KVM' , |
Alan Kuo | f16f626 | 2020-12-08 19:29:59 +0800 | [diff] [blame] | 66 | 'basic-auth' : '-DBMCWEB_ENABLE_BASIC_AUTHENTICATION', |
| 67 | 'session-auth' : '-DBMCWEB_ENABLE_SESSION_AUTHENTICATION', |
| 68 | 'xtoken-auth' : '-DBMCWEB_ENABLE_XTOKEN_AUTHENTICATION', |
| 69 | 'cookie-auth' : '-DBMCWEB_ENABLE_COOKIE_AUTHENTICATION', |
Manojkiran Eda | af6298d | 2020-05-27 08:51:32 +0530 | [diff] [blame] | 70 | 'mutual-tls-auth' : '-DBMCWEB_ENABLE_MUTUAL_TLS_AUTHENTICATION', |
| 71 | 'pam' : '-DWEBSERVER_ENABLE_PAM', |
| 72 | 'insecure-push-style-notification': '-DBMCWEB_INSECURE_ENABLE_HTTP_PUSH_STYLE_EVENTING', |
| 73 | 'redfish' : '-DBMCWEB_ENABLE_REDFISH', |
| 74 | 'redfish-bmc-journal' : '-DBMCWEB_ENABLE_REDFISH_BMC_JOURNAL', |
| 75 | 'redfish-cpu-log' : '-DBMCWEB_ENABLE_REDFISH_CPU_LOG', |
| 76 | 'redfish-dbus-log' : '-DBMCWEB_ENABLE_REDFISH_DBUS_LOG_ENTRIES', |
| 77 | 'redfish-provisioning-feature' : '-DBMCWEB_ENABLE_REDFISH_PROVISIONING_FEATURE', |
| 78 | 'redfish-raw-peci' : '-DBMCWEB_ENABLE_REDFISH_RAW_PECI', |
Ravi Teja | 3fad0d5 | 2020-10-16 11:18:02 -0500 | [diff] [blame] | 79 | 'redfish-dump-log' : '-DBMCWEB_ENABLE_REDFISH_DUMP_LOG', |
Manojkiran Eda | af6298d | 2020-05-27 08:51:32 +0530 | [diff] [blame] | 80 | 'rest' : '-DBMCWEB_ENABLE_DBUS_REST', |
| 81 | 'insecure-sensor-override' : '-DBMCWEB_INSECURE_UNRESTRICTED_SENSOR_OVERRIDE', |
| 82 | 'static-hosting' : '-DBMCWEB_ENABLE_STATIC_HOSTING', |
| 83 | 'insecure-tftp-update' : '-DBMCWEB_INSECURE_ENABLE_REDFISH_FW_TFTP_UPDATE', |
| 84 | 'validate-unsecure-feature' : '-DBMCWEB_ENABLE_VALIDATION_UNSECURE_FEATURE', |
| 85 | 'vm-nbdproxy' : '-DBMCWEB_ENABLE_VM_NBDPROXY', |
| 86 | 'vm-websocket' : '-DBMCWEB_ENABLE_VM_WEBSOCKET', |
| 87 | } |
| 88 | |
| 89 | # Get the options status and build a project summary to show which flags are |
| 90 | # being enabled during the configuration time. |
| 91 | |
| 92 | foreach option_key,option_value : feature_map |
| 93 | if(get_option(option_key).enabled()) |
| 94 | if(option_key == 'mutual-tls-auth' or option_key == 'insecure-disable-ssl') |
| 95 | if(get_option('insecure-disable-ssl').disabled() or get_option('mutual-tls-auth').disabled()) |
| 96 | add_project_arguments(option_value,language:'cpp') |
| 97 | summary(option_key,option_value, section : 'Enabled Features') |
| 98 | endif |
| 99 | else |
| 100 | summary(option_key,option_value, section : 'Enabled Features') |
| 101 | add_project_arguments(option_value,language:'cpp') |
| 102 | endif |
| 103 | else |
| 104 | if(option_key == 'insecure-disable-ssl') |
| 105 | summary('ssl','-DBMCWEB_ENABLE_SSL', section : 'Enabled Features') |
| 106 | add_project_arguments('-DBMCWEB_ENABLE_SSL', language : 'cpp') |
| 107 | endif |
| 108 | endif |
| 109 | endforeach |
| 110 | |
| 111 | if(get_option('tests').enabled()) |
| 112 | summary('unittest','NA', section : 'Enabled Features') |
| 113 | endif |
| 114 | |
Manojkiran Eda | af6298d | 2020-05-27 08:51:32 +0530 | [diff] [blame] | 115 | # Add compiler arguments |
| 116 | |
| 117 | # -Wpedantic, -Wextra comes by default with warning level |
| 118 | add_project_arguments( |
| 119 | cxx.get_supported_arguments([ |
| 120 | '-Wold-style-cast', |
| 121 | '-Wcast-align', |
| 122 | '-Wunused', |
| 123 | '-Woverloaded-virtual', |
| 124 | '-Wconversion', |
| 125 | '-Wsign-conversion', |
| 126 | '-Wno-attributes', |
| 127 | ]), |
| 128 | language: 'cpp' |
| 129 | ) |
| 130 | |
| 131 | if (cxx.get_id() == 'clang' and cxx.version().version_compare('>9.0')) |
| 132 | add_project_arguments( |
| 133 | cxx.get_supported_arguments([ |
| 134 | '-Weverything', |
| 135 | '-Wno-c++98-compat', |
| 136 | '-Wno-c++98-compat-pedantic', |
| 137 | '-Wno-global-constructors', |
| 138 | '-Wno-exit-time-destructors', |
| 139 | '-Wno-shadow', |
| 140 | '-Wno-used-but-marked-unused', |
| 141 | '-Wno-documentation-unknown-command', |
| 142 | '-Wno-weak-vtables', |
| 143 | '-Wno-documentation', |
| 144 | '-Wno-padded', |
| 145 | '-Wunused-parameter', |
| 146 | '-Wcovered-switch-default', |
| 147 | '-Wcomma', |
| 148 | '-Wextra-semi', |
| 149 | '-Wzero-as-null-pointer-constant', |
| 150 | '-Wswitch-enum', |
| 151 | '-Wnull-dereference', |
| 152 | '-Wdouble-promotion', |
| 153 | '-Wformat=2', |
| 154 | ]), |
| 155 | language:'cpp') |
| 156 | endif |
| 157 | |
| 158 | # if compiler is gnu-gcc , and version is > 8.0 then we add few more |
| 159 | # compiler arguments , we know that will pass |
| 160 | |
| 161 | if (cxx.get_id() == 'gcc' and cxx.version().version_compare('>8.0')) |
| 162 | |
| 163 | ## remove once bmcweb/issues/147 is fixed |
| 164 | add_global_link_arguments('-Wno-stringop-overflow',language:['c','cpp']) |
| 165 | add_project_arguments('-Wno-stringop-overflow',language:['c','cpp']) |
| 166 | |
| 167 | add_project_arguments( |
| 168 | cxx.get_supported_arguments([ |
| 169 | '-Wduplicated-cond', |
| 170 | '-Wduplicated-branches', |
| 171 | '-Wlogical-op', |
| 172 | '-Wunused-parameter', |
| 173 | '-Wnull-dereference', |
| 174 | '-Wdouble-promotion', |
| 175 | '-Wformat=2', |
| 176 | ]), |
| 177 | language:'cpp') |
| 178 | |
| 179 | if (get_option('buildtype') != 'plain') |
| 180 | if (get_option('b_lto') == true and get_option('optimization')!='0') |
| 181 | # Reduce the binary size by removing unnecessary |
| 182 | # dynamic symbol table entries |
| 183 | |
| 184 | add_project_arguments( |
| 185 | cxx.get_supported_arguments([ |
| 186 | '-fno-fat-lto-objects', |
| 187 | '-fvisibility=hidden', |
| 188 | '-fvisibility-inlines-hidden' |
| 189 | ]), |
| 190 | language: 'cpp') |
| 191 | |
| 192 | if cxx.has_link_argument('-Wl,--exclude-libs,ALL') |
| 193 | add_project_link_arguments('-Wl,--exclude-libs,ALL', language: 'cpp') |
| 194 | endif |
| 195 | endif |
| 196 | |
Manojkiran Eda | 620a6e1 | 2020-10-04 21:02:02 +0530 | [diff] [blame] | 197 | if( get_option('bmcweb-logging').enabled() or \ |
Manojkiran Eda | af6298d | 2020-05-27 08:51:32 +0530 | [diff] [blame] | 198 | get_option('buildtype').startswith('debug')) |
| 199 | add_project_arguments([ |
| 200 | '-DBMCWEB_ENABLE_LOGGING', |
| 201 | '-DBMCWEB_ENABLE_DEBUG' |
| 202 | ], |
| 203 | language : 'cpp') |
| 204 | |
| 205 | summary({'debug' :'-DBMCWEB_ENABLE_DEBUG', |
| 206 | 'logging' : '-DBMCWEB_ENABLE_LOGGING', |
| 207 | },section : 'Enabled Features') |
| 208 | endif |
| 209 | |
| 210 | endif |
| 211 | endif |
| 212 | |
| 213 | # Set Compiler Security flags |
| 214 | |
| 215 | security_flags = [ |
| 216 | '-fstack-protector-strong', |
| 217 | '-fPIE', |
| 218 | '-fPIC', |
| 219 | '-D_FORTIFY_SOURCE=2', |
| 220 | '-Wformat', |
| 221 | '-Wformat-security' |
| 222 | ] |
| 223 | |
| 224 | ## Add security flags for builds of type 'release','debugoptimized' and 'minsize' |
| 225 | |
| 226 | if not (get_option('buildtype') == 'plain' or get_option('buildtype').startswith('debug')) |
| 227 | add_project_arguments( |
| 228 | cxx.get_supported_arguments([ |
| 229 | security_flags |
| 230 | ]), |
| 231 | language: 'cpp') |
| 232 | endif |
| 233 | |
| 234 | # Boost dependency configuration |
| 235 | |
| 236 | add_project_arguments( |
| 237 | cxx.get_supported_arguments([ |
| 238 | '-DBOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT', |
| 239 | '-DBOOST_ASIO_DISABLE_THREADS', |
| 240 | '-DBOOST_BEAST_USE_STD_STRING_VIEW', |
| 241 | '-DBOOST_ERROR_CODE_HEADER_ONLY', |
| 242 | '-DBOOST_SYSTEM_NO_DEPRECATED', |
| 243 | '-DBOOST_ASIO_NO_DEPRECATED', |
| 244 | '-DBOOST_ALL_NO_LIB', |
| 245 | '-DBOOST_NO_RTTI', |
| 246 | '-DBOOST_NO_TYPEID', |
| 247 | '-DBOOST_COROUTINES_NO_DEPRECATION_WARNING', |
| 248 | '-DBOOST_URL_STANDALONE', |
Ed Tanous | 19a8815 | 2021-01-11 12:50:47 -0800 | [diff] [blame] | 249 | '-DBOOST_URL_HEADER_ONLY', |
| 250 | '-DBOOST_ALLOW_DEPRECATED_HEADERS' |
Manojkiran Eda | af6298d | 2020-05-27 08:51:32 +0530 | [diff] [blame] | 251 | ]), |
| 252 | language : 'cpp') |
| 253 | |
| 254 | # Find the dependency modules, if not found use meson wrap to get them |
| 255 | # automatically during the configure step |
Jason M. Bills | ceb8ddc | 2020-11-23 14:38:39 -0800 | [diff] [blame] | 256 | bmcweb_dependencies = [] |
Manojkiran Eda | af6298d | 2020-05-27 08:51:32 +0530 | [diff] [blame] | 257 | |
| 258 | pam = cxx.find_library('pam', required: get_option('pam')) |
| 259 | atomic = cxx.find_library('atomic', required: true) |
| 260 | openssl = dependency('openssl', required : true) |
Jason M. Bills | ceb8ddc | 2020-11-23 14:38:39 -0800 | [diff] [blame] | 261 | bmcweb_dependencies += [pam, atomic, openssl] |
Manojkiran Eda | af6298d | 2020-05-27 08:51:32 +0530 | [diff] [blame] | 262 | |
Jason M. Bills | ceb8ddc | 2020-11-23 14:38:39 -0800 | [diff] [blame] | 263 | sdbusplus = dependency('sdbusplus',required : false) |
Manojkiran Eda | af6298d | 2020-05-27 08:51:32 +0530 | [diff] [blame] | 264 | if not sdbusplus.found() |
| 265 | sdbusplus_proj = subproject('sdbusplus', required: true) |
| 266 | sdbusplus = sdbusplus_proj.get_variable('sdbusplus_dep') |
| 267 | sdbusplus = sdbusplus.as_system('system') |
| 268 | endif |
Jason M. Bills | ceb8ddc | 2020-11-23 14:38:39 -0800 | [diff] [blame] | 269 | bmcweb_dependencies += sdbusplus |
Manojkiran Eda | af6298d | 2020-05-27 08:51:32 +0530 | [diff] [blame] | 270 | |
| 271 | if get_option('rest').enabled() |
| 272 | tinyxml = dependency('tinyxml2', required: false) |
| 273 | if not tinyxml.found() |
| 274 | tinyxml_proj = subproject('tinyxml2', required: true) |
| 275 | tinyxml = tinyxml_proj.get_variable('tinyxml2_dep') |
| 276 | tinyxml = tinyxml.as_system('system') |
| 277 | endif |
Jason M. Bills | ceb8ddc | 2020-11-23 14:38:39 -0800 | [diff] [blame] | 278 | bmcweb_dependencies += tinyxml |
Manojkiran Eda | af6298d | 2020-05-27 08:51:32 +0530 | [diff] [blame] | 279 | endif |
| 280 | |
| 281 | systemd = dependency('systemd') |
| 282 | zlib = dependency('zlib') |
Jason M. Bills | ceb8ddc | 2020-11-23 14:38:39 -0800 | [diff] [blame] | 283 | bmcweb_dependencies += [systemd, zlib] |
Manojkiran Eda | af6298d | 2020-05-27 08:51:32 +0530 | [diff] [blame] | 284 | |
| 285 | if cxx.has_header('nlohmann/json.hpp') |
| 286 | nlohmann_json = declare_dependency() |
| 287 | else |
| 288 | subproject('nlohmann', required: false) |
| 289 | nlohmann_json = declare_dependency( |
| 290 | include_directories: [ |
| 291 | 'subprojects/nlohmann/single_include', |
| 292 | 'subprojects/nlohmann/single_include/nlohmann', |
| 293 | ] |
| 294 | ) |
| 295 | endif |
Jason M. Bills | ceb8ddc | 2020-11-23 14:38:39 -0800 | [diff] [blame] | 296 | bmcweb_dependencies += nlohmann_json |
Manojkiran Eda | af6298d | 2020-05-27 08:51:32 +0530 | [diff] [blame] | 297 | |
Ed Tanous | 309b083 | 2020-10-06 14:39:08 -0700 | [diff] [blame] | 298 | boost = dependency('boost',version : '>=1.73.0', required : false) |
Manojkiran Eda | af6298d | 2020-05-27 08:51:32 +0530 | [diff] [blame] | 299 | if not boost.found() |
| 300 | subproject('boost', required: false) |
| 301 | boost_inc = include_directories('subprojects/boost_1_73_0/', is_system:true) |
| 302 | boost = declare_dependency(include_directories : boost_inc) |
| 303 | endif |
Jason M. Bills | ceb8ddc | 2020-11-23 14:38:39 -0800 | [diff] [blame] | 304 | bmcweb_dependencies += boost |
Manojkiran Eda | af6298d | 2020-05-27 08:51:32 +0530 | [diff] [blame] | 305 | |
| 306 | if cxx.has_header('boost/url/url_view.hpp') |
| 307 | boost_url = declare_dependency() |
| 308 | else |
| 309 | subproject('boost-url', required: false) |
| 310 | boost_url_inc = include_directories('subprojects/boost-url/include', is_system:true) |
| 311 | boost_url= declare_dependency(include_directories : boost_url_inc) |
| 312 | endif |
Jason M. Bills | ceb8ddc | 2020-11-23 14:38:39 -0800 | [diff] [blame] | 313 | bmcweb_dependencies += boost_url |
Manojkiran Eda | af6298d | 2020-05-27 08:51:32 +0530 | [diff] [blame] | 314 | |
| 315 | if get_option('tests').enabled() |
| 316 | gtest = dependency('gtest', main: true,disabler: true, required : false) |
| 317 | gmock = dependency('gmock', required : false) |
| 318 | if not gtest.found() and get_option('tests').enabled() |
| 319 | gtest_proj = subproject('gtest', required: true) |
| 320 | gtest = gtest_proj.get_variable('gtest_main_dep') |
| 321 | gmock = gtest_proj.get_variable('gmock_dep') |
| 322 | endif |
| 323 | endif |
| 324 | |
| 325 | # Source files |
| 326 | |
| 327 | srcfiles_bmcweb = ['src/webserver_main.cpp','redfish-core/src/error_messages.cpp', |
| 328 | 'redfish-core/src/utils/json_utils.cpp'] |
| 329 | |
Manojkiran Eda | 17a897d | 2020-09-12 15:31:58 +0530 | [diff] [blame] | 330 | srcfiles_unittest = ['include/ut/dbus_utility_test.cpp', |
| 331 | 'redfish-core/ut/privileges_test.cpp', |
Manojkiran Eda | af6298d | 2020-05-27 08:51:32 +0530 | [diff] [blame] | 332 | 'redfish-core/ut/lock_test.cpp', |
| 333 | 'http/ut/utility_test.cpp'] |
| 334 | |
| 335 | # Gather the Configuration data |
| 336 | |
| 337 | conf_data = configuration_data() |
| 338 | conf_data.set('BMCWEB_HTTP_REQ_BODY_LIMIT_MB',get_option('http-body-limit')) |
| 339 | conf_data.set('MESON_INSTALL_PREFIX',get_option('prefix')) |
| 340 | configure_file(output: 'config.h', |
| 341 | configuration: conf_data) |
| 342 | |
| 343 | # Configure and install systemd unit files |
| 344 | |
| 345 | systemd_system_unit_dir = systemd.get_pkgconfig_variable('systemdsystemunitdir') |
| 346 | |
| 347 | bindir = get_option('prefix') + '/' +get_option('bindir') |
| 348 | |
| 349 | summary({ |
| 350 | 'prefix' : get_option('prefix'), |
| 351 | 'bindir' : bindir, |
| 352 | 'systemd unit directory' : systemd_system_unit_dir |
| 353 | }, section : 'Directories') |
| 354 | |
| 355 | configure_file(input : 'bmcweb.socket', |
| 356 | output : 'bmcweb.socket', |
| 357 | copy : true, |
| 358 | install_dir: systemd_system_unit_dir, |
| 359 | install : true) |
| 360 | |
| 361 | configure_file(input : 'bmcweb.service.in', |
| 362 | output : 'bmcweb.service', |
| 363 | install_dir: systemd_system_unit_dir, |
| 364 | configuration: conf_data, |
| 365 | install : true) |
| 366 | |
| 367 | # Copy pam-webserver to etc/pam.d |
| 368 | configure_file(input : 'pam-webserver', |
| 369 | output : 'webserver', |
| 370 | copy : true, |
| 371 | install_dir: '/etc/pam.d', |
| 372 | install : true) |
| 373 | |
| 374 | install_subdir('static', install_dir : 'share/www', strip_directory : true) |
| 375 | |
| 376 | # Generate the bmcweb executable and the test binary |
| 377 | |
| 378 | executable('bmcweb',srcfiles_bmcweb, |
| 379 | include_directories : incdir, |
Jason M. Bills | ceb8ddc | 2020-11-23 14:38:39 -0800 | [diff] [blame] | 380 | dependencies: bmcweb_dependencies, |
Ed Tanous | 5e34b67 | 2021-02-05 14:21:27 -0800 | [diff] [blame] | 381 | link_args: '-Wl,--gc-sections', |
Manojkiran Eda | af6298d | 2020-05-27 08:51:32 +0530 | [diff] [blame] | 382 | install: true, |
| 383 | install_dir:bindir) |
| 384 | |
| 385 | if(get_option('tests').enabled()) |
| 386 | foreach src_test : srcfiles_unittest |
| 387 | testname = src_test.split('/')[-1].split('.')[0] |
| 388 | test(testname,executable(testname,src_test, |
| 389 | include_directories : incdir, |
| 390 | install_dir: bindir, |
| 391 | dependencies: [ |
Sathish V | ae907c7 | 2020-12-02 17:49:34 +0530 | [diff] [blame] | 392 | boost, boost_url, gtest,openssl,gmock,nlohmann_json,sdbusplus |
Manojkiran Eda | af6298d | 2020-05-27 08:51:32 +0530 | [diff] [blame] | 393 | ])) |
| 394 | endforeach |
| 395 | endif |