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