net/mlx: add static ibverbs linkage with meson
[dpdk.git] / drivers / net / mlx4 / meson.build
1 # SPDX-License-Identifier: BSD-3-Clause
2 # Copyright 2018 6WIND S.A.
3 # Copyright 2018 Mellanox Technologies, Ltd
4
5 if not is_linux
6         build = false
7         reason = 'only supported on Linux'
8         subdir_done()
9 endif
10
11 static_ibverbs = (get_option('ibverbs_link') == 'static')
12 pmd_dlopen = (get_option('ibverbs_link') == 'dlopen')
13 LIB_GLUE_BASE = 'librte_pmd_mlx4_glue.so'
14 LIB_GLUE_VERSION = '18.02.0'
15 LIB_GLUE = LIB_GLUE_BASE + '.' + LIB_GLUE_VERSION
16 if pmd_dlopen
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         ]
22 endif
23
24 libnames = [ 'mlx4', 'ibverbs' ]
25 libs = []
26 foreach 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         else
34                 build = false
35                 reason = 'missing dependency, "' + libname + '"'
36                 subdir_done()
37         endif
38 endforeach
39
40 allow_experimental_apis = true
41 ext_deps += libs
42 sources = files(
43         'mlx4.c',
44         'mlx4_ethdev.c',
45         'mlx4_flow.c',
46         'mlx4_intr.c',
47         'mlx4_mp.c',
48         'mlx4_mr.c',
49         'mlx4_rxq.c',
50         'mlx4_rxtx.c',
51         'mlx4_txq.c',
52         'mlx4_utils.c',
53 )
54 if not pmd_dlopen
55         sources += files('mlx4_glue.c')
56 endif
57 cflags_options = [
58         '-std=c11',
59         '-Wno-strict-prototypes',
60         '-D_BSD_SOURCE',
61         '-D_DEFAULT_SOURCE',
62         '-D_XOPEN_SOURCE=600'
63 ]
64 foreach option:cflags_options
65         if cc.has_argument(option)
66                 cflags += option
67         endif
68 endforeach
69 if get_option('buildtype').contains('debug')
70         cflags += [ '-pedantic', '-DPEDANTIC' ]
71 else
72         cflags += [ '-UPEDANTIC' ]
73 endif
74 # To maintain the compatibility with the make build system
75 # mlx4_autoconf.h file is still generated.
76 # input array for meson member search:
77 # [ "MACRO to define if found", "header for the search",
78 #   "symbol to search", "struct member to search" ]
79 #
80 has_member_args = [
81         [ 'HAVE_IBV_MLX4_WQE_LSO_SEG', 'infiniband/mlx4dv.h',
82         'struct mlx4_wqe_lso_seg', 'mss_hdr_size' ],
83 ]
84 # input array for meson symbol search:
85 # [ "MACRO to define if found", "header for the search",
86 #   "symbol to search" ]
87 has_sym_args = [
88         [ 'HAVE_IBV_MLX4_BUF_ALLOCATORS', 'infiniband/mlx4dv.h',
89         'MLX4DV_SET_CTX_ATTR_BUF_ALLOCATORS' ],
90         [ 'HAVE_IBV_MLX4_UAR_MMAP_OFFSET', 'infiniband/mlx4dv.h',
91         'MLX4DV_QP_MASK_UAR_MMAP_OFFSET' ],
92 ]
93 config = configuration_data()
94 foreach arg:has_sym_args
95         config.set(arg[0], cc.has_header_symbol(arg[1], arg[2],
96                 dependencies: libs))
97 endforeach
98 foreach arg:has_member_args
99         file_prefix = '#include <' + arg[1] + '>'
100         config.set(arg[0], cc.has_member(arg[2], arg[3],
101                 prefix: file_prefix, dependencies: libs))
102 endforeach
103 configure_file(output : 'mlx4_autoconf.h', configuration : config)
104
105 # Build Glue Library
106 if pmd_dlopen
107         dlopen_name = 'mlx4_glue'
108         dlopen_lib_name = driver_name_fmt.format(dlopen_name)
109         dlopen_so_version = LIB_GLUE_VERSION
110         dlopen_sources = files('mlx4_glue.c')
111         dlopen_install_dir = [ eal_pmd_path + '-glue' ]
112         shared_lib = shared_library(
113                 dlopen_lib_name,
114                 dlopen_sources,
115                 include_directories: global_inc,
116                 c_args: cflags,
117                 dependencies: libs,
118                 link_args: [
119                 '-Wl,-export-dynamic',
120                 '-Wl,-h,@0@'.format(LIB_GLUE),
121                 ],
122                 soversion: dlopen_so_version,
123                 install: true,
124                 install_dir: dlopen_install_dir,
125         )
126 endif