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