1# SPDX-License-Identifier: BSD-3-Clause 2# Copyright(c) 2017-2019 Intel Corporation 3 4# check the OS is supported, rather than going any further 5supported_exec_envs = ['freebsd', 'linux', 'windows'] 6exec_env = host_machine.system() 7if not supported_exec_envs.contains(exec_env) 8 error('unsupported system type "@0@"'.format(exec_env)) 9endif 10 11# define a handy variable for checking which OS we have. 12# gives us "is_windows", "is_freebsd" and "is_linux" 13foreach env:supported_exec_envs 14 set_variable('is_' + env, exec_env == env) 15endforeach 16 17# MS linker requires special treatment. 18# TODO: use cc.get_linker_id() with Meson >= 0.54 19is_ms_linker = is_windows and (cc.get_id() == 'clang') 20 21# set the major version, which might be used by drivers and libraries 22# depending on the configuration options 23pver = meson.project_version().split('.') 24major_version = '@0@.@1@'.format(pver.get(0), pver.get(1)) 25abi_version = run_command(find_program('cat', 'more'), abi_version_file).stdout().strip() 26 27# Libraries have the abi_version as the filename extension 28# and have the soname be all but the final part of the abi_version. 29# e.g. v20.1 => librte_foo.so.20.1 30# sonames => librte_foo.so.20 31so_version = abi_version.split('.')[0] 32 33# extract all version information into the build configuration 34dpdk_conf.set('RTE_VER_YEAR', pver.get(0).to_int()) 35dpdk_conf.set('RTE_VER_MONTH', pver.get(1).to_int()) 36if pver.get(2).contains('-rc') 37 rc_ver = pver.get(2).split('-rc') 38 dpdk_conf.set('RTE_VER_MINOR', rc_ver.get(0).to_int()) 39 dpdk_conf.set_quoted('RTE_VER_SUFFIX', '-rc') 40 dpdk_conf.set('RTE_VER_RELEASE', rc_ver.get(1).to_int()) 41else 42 dpdk_conf.set('RTE_VER_MINOR', pver.get(2).to_int()) 43 dpdk_conf.set_quoted('RTE_VER_SUFFIX', '') 44# for actual, non-rc releases, set the release value to 99 to ensure releases 45# have higher version numbers than their respective release candidates 46 dpdk_conf.set('RTE_VER_RELEASE', 99) 47endif 48 49pmd_subdir_opt = get_option('drivers_install_subdir') 50if pmd_subdir_opt.contains('<VERSION>') 51 pmd_subdir_opt = abi_version.join(pmd_subdir_opt.split('<VERSION>')) 52endif 53driver_install_path = join_paths(get_option('libdir'), pmd_subdir_opt) 54eal_pmd_path = join_paths(get_option('prefix'), driver_install_path) 55 56# driver .so files often depend upon the bus drivers for their connect bus, 57# e.g. ixgbe depends on librte_bus_pci. This means that the bus drivers need 58# to be in the library path, so symlink the drivers from the main lib directory. 59if not is_windows 60 meson.add_install_script('../buildtools/symlink-drivers-solibs.sh', 61 get_option('libdir'), pmd_subdir_opt) 62elif meson.version().version_compare('>=0.55.0') 63 # 0.55.0 is required to use external program with add_install_script 64 meson.add_install_script(py3, '../buildtools/symlink-drivers-solibs.py', 65 get_option('libdir'), pmd_subdir_opt, get_option('bindir')) 66endif 67 68# init disable/enable driver lists that will be populated in different places 69disable_drivers = '' 70enable_drivers = '' 71 72platform = get_option('platform') 73 74# set the cpu_instruction_set and cflags for it 75if meson.is_cross_build() 76 cpu_instruction_set = host_machine.cpu() 77else 78 cpu_instruction_set = get_option('cpu_instruction_set') 79 machine = get_option('machine') 80 if machine != 'auto' 81 warning('The "machine" option is deprecated. ' + 82 'Please use "cpu_instruction_set" instead.') 83 if cpu_instruction_set != 'auto' 84 error('Setting both "machine" and ' + 85 '"cpu_instruction_set" is unsupported.') 86 endif 87 cpu_instruction_set = machine 88 if cpu_instruction_set == 'default' 89 cpu_instruction_set = 'generic' 90 endif 91 endif 92endif 93 94if platform == 'native' 95 if cpu_instruction_set == 'auto' 96 cpu_instruction_set = 'native' 97 endif 98elif platform == 'generic' 99 if cpu_instruction_set == 'auto' 100 cpu_instruction_set = 'generic' 101 endif 102endif 103 104# cpu_instruction_set 'generic' is special, it selects the per arch agreed 105# common minimal baseline needed for DPDK. cpu_instruction_set 'default' is 106# also supported with the same meaning for backwards compatibility. 107# That might not be the most optimized, but the most portable version while 108# still being able to support the CPU features required for DPDK. 109# This can be bumped up by the DPDK project, but it can never be an 110# invariant like 'native' 111if cpu_instruction_set == 'generic' 112 if host_machine.cpu_family().startswith('x86') 113 # matches the old pre-meson build systems generic cpu_instruction_set 114 cpu_instruction_set = 'corei7' 115 elif host_machine.cpu_family().startswith('arm') 116 cpu_instruction_set = 'armv7-a' 117 elif host_machine.cpu_family().startswith('aarch') 118 # arm64 manages generic config in config/arm/meson.build 119 cpu_instruction_set = 'generic' 120 elif host_machine.cpu_family().startswith('ppc') 121 cpu_instruction_set = 'power8' 122 endif 123endif 124 125dpdk_conf.set('RTE_MACHINE', cpu_instruction_set) 126machine_args = [] 127 128# ppc64 does not support -march= at all, use -mcpu and -mtune for that 129if host_machine.cpu_family().startswith('ppc') 130 machine_args += '-mcpu=' + cpu_instruction_set 131 machine_args += '-mtune=' + cpu_instruction_set 132else 133 machine_args += '-march=' + cpu_instruction_set 134endif 135 136toolchain = cc.get_id() 137dpdk_conf.set_quoted('RTE_TOOLCHAIN', toolchain) 138dpdk_conf.set('RTE_TOOLCHAIN_' + toolchain.to_upper(), 1) 139 140dpdk_conf.set('RTE_ARCH_64', cc.sizeof('void *') == 8) 141dpdk_conf.set('RTE_ARCH_32', cc.sizeof('void *') == 4) 142 143if not is_windows 144 add_project_link_arguments('-Wl,--no-as-needed', language: 'c') 145endif 146 147# use pthreads if available for the platform 148if not is_windows 149 add_project_link_arguments('-pthread', language: 'c') 150 dpdk_extra_ldflags += '-pthread' 151endif 152 153# on some OS, maths functions are in a separate library 154if cc.find_library('m', required : false).found() 155 # some libs depend on maths lib 156 add_project_link_arguments('-lm', language: 'c') 157 dpdk_extra_ldflags += '-lm' 158endif 159 160if is_linux 161 link_lib = 'dl' 162else 163 link_lib = '' 164endif 165 166# if link_lib is empty, do not add it to project properties 167if link_lib != '' 168 add_project_link_arguments('-l' + link_lib, language: 'c') 169 dpdk_extra_ldflags += '-l' + link_lib 170endif 171 172# check for libraries used in multiple places in DPDK 173has_libnuma = 0 174find_libnuma = true 175if meson.is_cross_build() and not meson.get_cross_property('numa', true) 176 # don't look for libnuma if explicitly disabled in cross build 177 find_libnuma = false 178endif 179if find_libnuma 180 numa_dep = cc.find_library('numa', required: false) 181 if numa_dep.found() and cc.has_header('numaif.h') 182 dpdk_conf.set10('RTE_HAS_LIBNUMA', true) 183 has_libnuma = 1 184 add_project_link_arguments('-lnuma', language: 'c') 185 dpdk_extra_ldflags += '-lnuma' 186 endif 187endif 188 189has_libfdt = 0 190fdt_dep = cc.find_library('libfdt', required: false) 191if fdt_dep.found() and cc.has_header('fdt.h') 192 dpdk_conf.set10('RTE_HAS_LIBFDT', true) 193 has_libfdt = 1 194 add_project_link_arguments('-lfdt', language: 'c') 195 dpdk_extra_ldflags += '-lfdt' 196endif 197 198libexecinfo = cc.find_library('libexecinfo', required: false) 199if libexecinfo.found() and cc.has_header('execinfo.h') 200 add_project_link_arguments('-lexecinfo', language: 'c') 201 dpdk_extra_ldflags += '-lexecinfo' 202endif 203 204libarchive = dependency('libarchive', required: false, method: 'pkg-config') 205if libarchive.found() 206 dpdk_conf.set('RTE_HAS_LIBARCHIVE', 1) 207 # Push libarchive link dependency at the project level to support 208 # statically linking dpdk apps. Details at: 209 # https://inbox.dpdk.org/dev/20210605004024.660267a1@sovereign/ 210 add_project_link_arguments('-larchive', language: 'c') 211 dpdk_extra_ldflags += '-larchive' 212endif 213 214# check for libbsd 215libbsd = dependency('libbsd', required: false, method: 'pkg-config') 216if libbsd.found() 217 dpdk_conf.set('RTE_USE_LIBBSD', 1) 218endif 219 220# check for pcap 221pcap_dep = dependency('libpcap', required: false, method: 'pkg-config') 222pcap_lib = is_windows ? 'wpcap' : 'pcap' 223if not pcap_dep.found() 224 # pcap got a pkg-config file only in 1.9.0 225 pcap_dep = cc.find_library(pcap_lib, required: false) 226endif 227if pcap_dep.found() and cc.has_header('pcap.h', dependencies: pcap_dep) 228 dpdk_conf.set('RTE_PORT_PCAP', 1) 229 dpdk_extra_ldflags += '-l@0@'.format(pcap_lib) 230endif 231 232# for clang 32-bit compiles we need libatomic for 64-bit atomic ops 233if cc.get_id() == 'clang' and dpdk_conf.get('RTE_ARCH_64') == false 234 atomic_dep = cc.find_library('atomic', required: true) 235 add_project_link_arguments('-latomic', language: 'c') 236 dpdk_extra_ldflags += '-latomic' 237endif 238 239# add -include rte_config to cflags 240add_project_arguments('-include', 'rte_config.h', language: 'c') 241 242# enable extra warnings and disable any unwanted warnings 243warning_flags = [ 244 # -Wall is added by meson by default, so add -Wextra only 245 '-Wextra', 246 247 # additional warnings in alphabetical order 248 '-Wcast-qual', 249 '-Wdeprecated', 250 '-Wformat', 251 '-Wformat-nonliteral', 252 '-Wformat-security', 253 '-Wmissing-declarations', 254 '-Wmissing-prototypes', 255 '-Wnested-externs', 256 '-Wold-style-definition', 257 '-Wpointer-arith', 258 '-Wsign-compare', 259 '-Wstrict-prototypes', 260 '-Wundef', 261 '-Wwrite-strings', 262 263 # globally disabled warnings 264 '-Wno-address-of-packed-member', 265 '-Wno-packed-not-aligned', 266 '-Wno-missing-field-initializers', 267] 268if cc.get_id() == 'gcc' and cc.version().version_compare('>=10.0') 269# FIXME: Bugzilla 396 270 warning_flags += '-Wno-zero-length-bounds' 271endif 272if not dpdk_conf.get('RTE_ARCH_64') 273# for 32-bit, don't warn about casting a 32-bit pointer to 64-bit int - it's fine!! 274 warning_flags += '-Wno-pointer-to-int-cast' 275endif 276if cc.get_id() == 'intel' 277 warning_ids = [181, 188, 2203, 2279, 2557, 3179, 3656] 278 foreach i:warning_ids 279 warning_flags += '-diag-disable=@0@'.format(i) 280 endforeach 281endif 282foreach arg: warning_flags 283 if cc.has_argument(arg) 284 add_project_arguments(arg, language: 'c') 285 endif 286endforeach 287 288# set other values pulled from the build options 289dpdk_conf.set('RTE_MAX_LCORE', get_option('max_lcores')) 290dpdk_conf.set('RTE_MAX_NUMA_NODES', get_option('max_numa_nodes')) 291dpdk_conf.set('RTE_MAX_ETHPORTS', get_option('max_ethports')) 292dpdk_conf.set('RTE_LIBEAL_USE_HPET', get_option('use_hpet')) 293dpdk_conf.set('RTE_ENABLE_TRACE_FP', get_option('enable_trace_fp')) 294# values which have defaults which may be overridden 295dpdk_conf.set('RTE_MAX_VFIO_GROUPS', 64) 296dpdk_conf.set('RTE_DRIVER_MEMPOOL_BUCKET_SIZE_KB', 64) 297dpdk_conf.set('RTE_LIBRTE_DPAA2_USE_PHYS_IOVA', true) 298if dpdk_conf.get('RTE_ARCH_64') 299 dpdk_conf.set('RTE_MAX_MEM_MB', 524288) 300else # for 32-bit we need smaller reserved memory areas 301 dpdk_conf.set('RTE_MAX_MEM_MB', 2048) 302endif 303 304 305compile_time_cpuflags = [] 306subdir(arch_subdir) 307dpdk_conf.set('RTE_COMPILE_TIME_CPUFLAGS', ','.join(compile_time_cpuflags)) 308 309# apply cross-specific options 310if meson.is_cross_build() 311 # configure RTE_MAX_LCORE and RTE_MAX_NUMA_NODES from cross file 312 cross_max_lcores = meson.get_cross_property('max_lcores', 0) 313 if cross_max_lcores != 0 314 message('Setting RTE_MAX_LCORE from cross file') 315 dpdk_conf.set('RTE_MAX_LCORE', cross_max_lcores) 316 endif 317 cross_max_numa_nodes = meson.get_cross_property('max_numa_nodes', 0) 318 if cross_max_numa_nodes != 0 319 message('Setting RTE_MAX_NUMA_NODES from cross file') 320 dpdk_conf.set('RTE_MAX_NUMA_NODES', cross_max_numa_nodes) 321 endif 322endif 323 324# set the install path for the drivers 325dpdk_conf.set_quoted('RTE_EAL_PMD_PATH', eal_pmd_path) 326 327install_headers(['rte_config.h'], 328 subdir: get_option('include_subdir_arch')) 329 330# enable VFIO only if it is linux OS 331dpdk_conf.set('RTE_EAL_VFIO', is_linux) 332 333# specify -D_GNU_SOURCE unconditionally 334add_project_arguments('-D_GNU_SOURCE', language: 'c') 335 336# specify -D__BSD_VISIBLE for FreeBSD 337if is_freebsd 338 add_project_arguments('-D__BSD_VISIBLE', language: 'c') 339endif 340 341if is_windows 342 # VirtualAlloc2() is available since Windows 10 / Server 2016. 343 add_project_arguments('-D_WIN32_WINNT=0x0A00', language: 'c') 344 345 # Use MinGW-w64 stdio, because DPDK assumes ANSI-compliant formatting. 346 if cc.get_id() == 'gcc' 347 add_project_arguments('-D__USE_MINGW_ANSI_STDIO', language: 'c') 348 endif 349 350 # Disable secure CRT deprecated warnings for clang 351 if cc.get_id() == 'clang' 352 add_project_arguments('-D_CRT_SECURE_NO_WARNINGS', language: 'c') 353 endif 354 355 add_project_link_arguments('-lws2_32', language: 'c') 356 357 # Contrary to docs, VirtualAlloc2() is exported by mincore.lib 358 # in Windows SDK, while MinGW exports it by advapi32.a. 359 if is_ms_linker 360 add_project_link_arguments('-lmincore', language: 'c') 361 endif 362 363 add_project_link_arguments('-ladvapi32', '-lsetupapi', language: 'c') 364 add_project_link_arguments('-ldbghelp', language: 'c') 365endif 366 367if get_option('b_lto') 368 if cc.has_argument('-ffat-lto-objects') 369 add_project_arguments('-ffat-lto-objects', language: 'c') 370 else 371 error('compiler does not support fat LTO objects - please turn LTO off') 372 endif 373 # workaround for gcc bug 81440 374 if cc.get_id() == 'gcc' and cc.version().version_compare('<8.0') 375 add_project_arguments('-Wno-lto-type-mismatch', language: 'c') 376 add_project_link_arguments('-Wno-lto-type-mismatch', language: 'c') 377 endif 378endif 379 380if get_option('default_library') == 'both' 381 error( ''' 382 Unsupported value "both" for "default_library" option. 383 384 NOTE: DPDK always builds both shared and static libraries. Please set 385 "default_library" to either "static" or "shared" to select default linkage 386 for apps and any examples.''') 387endif 388