xref: /f-stack/dpdk/drivers/net/mlx4/meson.build (revision 2d9fd380)
1# SPDX-License-Identifier: BSD-3-Clause
2# Copyright 2018 6WIND S.A.
3# Copyright 2018 Mellanox Technologies, Ltd
4
5if not is_linux
6	build = false
7	reason = 'only supported on Linux'
8	subdir_done()
9endif
10
11static_ibverbs = (get_option('ibverbs_link') == 'static')
12dlopen_ibverbs = (get_option('ibverbs_link') == 'dlopen')
13LIB_GLUE_BASE = 'librte_net_mlx4_glue.so'
14LIB_GLUE_VERSION = abi_version
15LIB_GLUE = LIB_GLUE_BASE + '.' + LIB_GLUE_VERSION
16if dlopen_ibverbs
17	dpdk_conf.set('RTE_IBVERBS_LINK_DLOPEN', 1)
18	cflags += [
19		'-DMLX4_GLUE="@0@"'.format(LIB_GLUE),
20		'-DMLX4_GLUE_VERSION="@0@"'.format(LIB_GLUE_VERSION),
21	]
22endif
23
24libnames = [ 'mlx4', 'ibverbs' ]
25libs = []
26foreach libname:libnames
27	lib = dependency('lib' + libname, static:static_ibverbs, required:false)
28	if not lib.found() and not static_ibverbs
29		lib = cc.find_library(libname, required:false)
30	endif
31	if lib.found()
32		libs += lib
33		if not static_ibverbs and not dlopen_ibverbs
34			ext_deps += lib
35		endif
36	else
37		build = false
38		reason = 'missing dependency, "' + libname + '"'
39		subdir_done()
40	endif
41endforeach
42if static_ibverbs or dlopen_ibverbs
43	# Build without adding shared libs to Requires.private
44	ibv_cflags = run_command(pkgconf, '--cflags', 'libibverbs').stdout()
45	ext_deps += declare_dependency(compile_args: ibv_cflags.split())
46endif
47if static_ibverbs
48	# Add static deps ldflags to internal apps and Libs.private
49	ibv_ldflags = run_command(ldflags_ibverbs_static, check:true).stdout()
50	ext_deps += declare_dependency(link_args:ibv_ldflags.split())
51endif
52
53sources = files(
54	'mlx4.c',
55	'mlx4_ethdev.c',
56	'mlx4_flow.c',
57	'mlx4_intr.c',
58	'mlx4_mp.c',
59	'mlx4_mr.c',
60	'mlx4_rxq.c',
61	'mlx4_rxtx.c',
62	'mlx4_txq.c',
63	'mlx4_utils.c',
64)
65if not dlopen_ibverbs
66	sources += files('mlx4_glue.c')
67endif
68cflags_options = [
69	'-std=c11',
70	'-Wno-strict-prototypes',
71	'-D_BSD_SOURCE',
72	'-D_DEFAULT_SOURCE',
73	'-D_XOPEN_SOURCE=600'
74]
75foreach option:cflags_options
76	if cc.has_argument(option)
77		cflags += option
78	endif
79endforeach
80if get_option('buildtype').contains('debug')
81	cflags += [ '-pedantic', '-DPEDANTIC' ]
82else
83	cflags += [ '-UPEDANTIC' ]
84endif
85# To maintain the compatibility with the make build system
86# mlx4_autoconf.h file is still generated.
87# input array for meson member search:
88# [ "MACRO to define if found", "header for the search",
89#   "symbol to search", "struct member to search" ]
90#
91has_member_args = [
92	[ 'HAVE_IBV_MLX4_WQE_LSO_SEG', 'infiniband/mlx4dv.h',
93	'struct mlx4_wqe_lso_seg', 'mss_hdr_size' ],
94]
95# input array for meson symbol search:
96# [ "MACRO to define if found", "header for the search",
97#   "symbol to search" ]
98has_sym_args = [
99	[ 'HAVE_IBV_MLX4_BUF_ALLOCATORS', 'infiniband/mlx4dv.h',
100	'MLX4DV_SET_CTX_ATTR_BUF_ALLOCATORS' ],
101	[ 'HAVE_IBV_MLX4_UAR_MMAP_OFFSET', 'infiniband/mlx4dv.h',
102	'MLX4DV_QP_MASK_UAR_MMAP_OFFSET' ],
103]
104config = configuration_data()
105foreach arg:has_sym_args
106	config.set(arg[0], cc.has_header_symbol(arg[1], arg[2],
107		dependencies: libs))
108endforeach
109foreach arg:has_member_args
110	file_prefix = '#include <' + arg[1] + '>'
111	config.set(arg[0], cc.has_member(arg[2], arg[3],
112		prefix: file_prefix, dependencies: libs))
113endforeach
114configure_file(output : 'mlx4_autoconf.h', configuration : config)
115
116# Build Glue Library
117if dlopen_ibverbs
118	dlopen_name = 'mlx4_glue'
119	dlopen_lib_name = 'rte_net_' + dlopen_name
120	dlopen_so_version = LIB_GLUE_VERSION
121	dlopen_sources = files('mlx4_glue.c')
122	dlopen_install_dir = [ eal_pmd_path + '-glue' ]
123	shared_lib = shared_library(
124		dlopen_lib_name,
125		dlopen_sources,
126		include_directories: global_inc,
127		c_args: cflags,
128		dependencies: libs,
129		link_args: [
130		'-Wl,-export-dynamic',
131		'-Wl,-h,@0@'.format(LIB_GLUE),
132		],
133		soversion: dlopen_so_version,
134		install: true,
135		install_dir: dlopen_install_dir,
136	)
137endif
138