net/mlx: fix library search in meson build
[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 pmd_dlopen = (get_option('ibverbs_link') == 'dlopen')
6 LIB_GLUE_BASE = 'librte_pmd_mlx4_glue.so'
7 LIB_GLUE_VERSION = '18.02.0'
8 LIB_GLUE = LIB_GLUE_BASE + '.' + LIB_GLUE_VERSION
9 if pmd_dlopen
10         dpdk_conf.set('RTE_IBVERBS_LINK_DLOPEN', 1)
11         cflags += [
12                 '-DMLX4_GLUE="@0@"'.format(LIB_GLUE),
13                 '-DMLX4_GLUE_VERSION="@0@"'.format(LIB_GLUE_VERSION),
14         ]
15 endif
16 libnames = [ 'mnl', 'mlx4', 'ibverbs' ]
17 libs = []
18 build = true
19 foreach libname:libnames
20         lib = dependency('lib' + libname, required:false)
21         if not lib.found()
22                 lib = cc.find_library(libname, required:false)
23         endif
24         if lib.found()
25                 libs += [ lib ]
26         else
27                 build = false
28         endif
29 endforeach
30 # Compile PMD
31 if build
32         allow_experimental_apis = true
33         ext_deps += libs
34         sources = files(
35                 'mlx4.c',
36                 'mlx4_ethdev.c',
37                 'mlx4_flow.c',
38                 'mlx4_intr.c',
39                 'mlx4_mp.c',
40                 'mlx4_mr.c',
41                 'mlx4_rxq.c',
42                 'mlx4_rxtx.c',
43                 'mlx4_txq.c',
44                 'mlx4_utils.c',
45         )
46         if not pmd_dlopen
47                 sources += files('mlx4_glue.c')
48         endif
49         cflags_options = [
50                 '-Wextra',
51                 '-std=c11',
52                 '-Wno-strict-prototypes',
53                 '-D_BSD_SOURCE',
54                 '-D_DEFAULT_SOURCE',
55                 '-D_XOPEN_SOURCE=600'
56         ]
57         foreach option:cflags_options
58                 if cc.has_argument(option)
59                         cflags += option
60                 endif
61         endforeach
62         if get_option('buildtype').contains('debug')
63                 cflags += [ '-pedantic', '-UNDEBUG', '-DPEDANTIC' ]
64         else
65                 cflags += [ '-DNDEBUG', '-UPEDANTIC' ]
66         endif
67         # To maintain the compatibility with the make build system
68         # mlx4_autoconf.h file is still generated.
69         # input array for meson member search:
70         # [ "MACRO to define if found", "header for the search",
71         #   "symbol to search","struct member to search" ]
72         #
73         has_member_args = [
74                 [ 'HAVE_IBV_MLX4_WQE_LSO_SEG', 'infiniband/mlx4dv.h',
75                 'struct mlx4_wqe_lso_seg', 'mss_hdr_size' ],
76         ]
77         # input array for meson symbol search:
78         # [ "MACRO to define if found", "header for the search",
79         #   "symbol to search" ]
80         has_sym_args = [
81                 [ 'HAVE_IBV_MLX4_BUF_ALLOCATORS', 'infiniband/mlx4dv.h',
82                 'MLX4DV_SET_CTX_ATTR_BUF_ALLOCATORS' ],
83                 [ 'HAVE_IBV_MLX4_UAR_MMAP_OFFSET', 'infiniband/mlx4dv.h',
84                 'MLX4DV_QP_MASK_UAR_MMAP_OFFSET' ],
85         ]
86         config = configuration_data()
87         foreach arg:has_sym_args
88                 config.set(arg[0], cc.has_header_symbol(arg[1], arg[2]))
89         endforeach
90         foreach arg:has_member_args
91                 file_prefix = '#include<' + arg[1] + '>'
92                 config.set(arg[0], cc.has_member(arg[2], arg[3],
93                         prefix : file_prefix))
94         endforeach
95         configure_file(output : 'mlx4_autoconf.h', configuration : config)
96 endif
97 # Build Glue Library
98 if pmd_dlopen and build
99         dlopen_name = 'mlx4_glue'
100         dlopen_lib_name = driver_name_fmt.format(dlopen_name)
101         dlopen_so_version = LIB_GLUE_VERSION
102         dlopen_sources = files('mlx4_glue.c')
103         dlopen_install_dir = [ eal_pmd_path + '-glue' ]
104         shared_lib = shared_library(
105                 dlopen_lib_name,
106                 dlopen_sources,
107                 include_directories: global_inc,
108                 c_args: cflags,
109                 dependencies: libs,
110                 link_args: [
111                 '-Wl,-export-dynamic',
112                 '-Wl,-h,@0@'.format(LIB_GLUE),
113                 ],
114                 soversion: dlopen_so_version,
115                 install: true,
116                 install_dir: dlopen_install_dir,
117         )
118 endif