net/mlx: allow build only on Linux
[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 build = true
11
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 = [ 'mnl', 'mlx4', 'ibverbs' ]
25 libs = []
26 foreach libname:libnames
27         lib = dependency('lib' + libname, required:false)
28         if not lib.found()
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         endif
37 endforeach
38
39 if build
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                 '-Wextra',
59                 '-std=c11',
60                 '-Wno-strict-prototypes',
61                 '-D_BSD_SOURCE',
62                 '-D_DEFAULT_SOURCE',
63                 '-D_XOPEN_SOURCE=600'
64         ]
65         foreach option:cflags_options
66                 if cc.has_argument(option)
67                         cflags += option
68                 endif
69         endforeach
70         if get_option('buildtype').contains('debug')
71                 cflags += [ '-pedantic', '-UNDEBUG', '-DPEDANTIC' ]
72         else
73                 cflags += [ '-DNDEBUG', '-UPEDANTIC' ]
74         endif
75         # To maintain the compatibility with the make build system
76         # mlx4_autoconf.h file is still generated.
77         # input array for meson member search:
78         # [ "MACRO to define if found", "header for the search",
79         #   "symbol to search","struct member to search" ]
80         #
81         has_member_args = [
82                 [ 'HAVE_IBV_MLX4_WQE_LSO_SEG', 'infiniband/mlx4dv.h',
83                 'struct mlx4_wqe_lso_seg', 'mss_hdr_size' ],
84         ]
85         # input array for meson symbol search:
86         # [ "MACRO to define if found", "header for the search",
87         #   "symbol to search" ]
88         has_sym_args = [
89                 [ 'HAVE_IBV_MLX4_BUF_ALLOCATORS', 'infiniband/mlx4dv.h',
90                 'MLX4DV_SET_CTX_ATTR_BUF_ALLOCATORS' ],
91                 [ 'HAVE_IBV_MLX4_UAR_MMAP_OFFSET', 'infiniband/mlx4dv.h',
92                 'MLX4DV_QP_MASK_UAR_MMAP_OFFSET' ],
93         ]
94         config = configuration_data()
95         foreach arg:has_sym_args
96                 config.set(arg[0], cc.has_header_symbol(arg[1], arg[2]))
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))
102         endforeach
103         configure_file(output : 'mlx4_autoconf.h', configuration : config)
104 endif
105 # Build Glue Library
106 if pmd_dlopen and build
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