3a9a6c3be4cb88ef2d79fc442e31049e9f9d4cb2
[dpdk.git] / lib / meson.build
1 # SPDX-License-Identifier: BSD-3-Clause
2 # Copyright(c) 2017-2019 Intel Corporation
3
4
5 # process all libraries equally, as far as possible
6 # "core" libs first, then others alphebetically as far as possible
7 # NOTE: for speed of meson runs, the dependencies in the subdirectories
8 # sometimes skip deps that would be implied by others, e.g. if mempool is
9 # given as a dep, no need to mention ring. This is especially true for the
10 # core libs which are widely reused, so their deps are kept to a minimum.
11 libraries = [
12         'kvargs', # eal depends on kvargs
13         'telemetry', # basic info querying
14         'eal', # everything depends on eal
15         'ring',
16         'rcu', # rcu depends on ring
17         'mempool',
18         'mbuf',
19         'net',
20         'meter',
21         'ethdev',
22         'pci', # core
23         'cmdline',
24         'metrics', # bitrate/latency stats depends on this
25         'hash',    # efd depends on this
26         'timer',   # eventdev depends on this
27         'acl',
28         'bbdev',
29         'bitratestats',
30         'cfgfile',
31         'compressdev',
32         'cryptodev',
33         'distributor',
34         'efd',
35         'eventdev',
36         'gro',
37         'gso',
38         'ip_frag',
39         'jobstats',
40         'kni',
41         'latencystats',
42         'lpm',
43         'member',
44         'power',
45         'pdump',
46         'rawdev',
47         'regexdev',
48         'rib',
49         'reorder',
50         'sched',
51         'security',
52         'stack',
53         'vhost',
54         'ipsec', # ipsec lib depends on net, crypto and security
55         'fib', #fib lib depends on rib
56         'port', # pkt framework libs which use other libs from above
57         'table',
58         'pipeline',
59         'flow_classify', # flow_classify lib depends on pkt framework table lib
60         'bpf',
61         'graph',
62         'node',
63 ]
64
65 if is_windows
66     libraries = [
67             'kvargs',
68             'telemetry',
69             'eal',
70             'ring',
71             'rcu',
72             'mempool',
73             'mbuf',
74             'net',
75             'meter',
76             'ethdev',
77             'pci',
78             'cmdline',
79             'hash',
80             'cfgfile',
81     ] # only supported libraries for windows
82 endif
83
84 default_cflags = machine_args
85 default_cflags += ['-DALLOW_EXPERIMENTAL_API']
86 default_cflags += ['-DALLOW_INTERNAL_API']
87
88 if cc.has_argument('-Wno-format-truncation')
89     default_cflags += '-Wno-format-truncation'
90 endif
91
92 enabled_libs = [] # used to print summary at the end
93
94 foreach l:libraries
95     build = true
96     reason = '<unknown reason>' # set if build == false to explain why
97     name = l
98     use_function_versioning = false
99     sources = []
100     headers = []
101     indirect_headers = [] # public headers not directly included by apps
102     driver_sdk_headers = [] # public headers included by drivers
103     includes = []
104     cflags = default_cflags
105     objs = [] # other object files to link against, used e.g. for
106               # instruction-set optimized versions of code
107
108     # use "deps" for internal DPDK dependencies, and "ext_deps" for
109     # external package/library requirements
110     ext_deps = []
111     deps = []
112     # eal is standard dependency once built
113     if dpdk_conf.has('RTE_LIB_EAL')
114         deps += ['eal']
115     endif
116
117     subdir(l)
118     if name != l
119         warning('Library name, "@0@", and directory name, "@1@", do not match'.format(name, l))
120     endif
121
122     if not build
123         dpdk_libs_disabled += name
124         set_variable(name.underscorify() + '_disable_reason', reason)
125         continue
126     endif
127
128     shared_deps = ext_deps
129     static_deps = ext_deps
130     foreach d:deps
131         if not is_variable('shared_rte_' + d)
132             error('Missing internal dependency "@0@" for @1@ [@2@]'
133                     .format(d, name, 'lib/' + l))
134         endif
135         shared_deps += [get_variable('shared_rte_' + d)]
136         static_deps += [get_variable('static_rte_' + d)]
137     endforeach
138
139     enabled_libs += name
140     dpdk_conf.set('RTE_LIB_' + name.to_upper(), 1)
141     install_headers(headers)
142     install_headers(indirect_headers)
143     if get_option('enable_driver_sdk')
144         install_headers(driver_sdk_headers)
145     endif
146     dpdk_chkinc_headers += headers
147
148     libname = 'rte_' + name
149     includes += include_directories(l)
150
151     if is_windows and use_function_versioning
152         message('@0@: Function versioning is not supported by Windows.'.format(name))
153     endif
154
155     if use_function_versioning
156         cflags += '-DRTE_USE_FUNCTION_VERSIONING'
157     endif
158
159     # first build static lib
160     static_lib = static_library(libname,
161             sources,
162             objects: objs,
163             c_args: cflags,
164             dependencies: static_deps,
165             include_directories: includes,
166             install: true)
167     static_dep = declare_dependency(
168             include_directories: includes,
169             dependencies: static_deps)
170
171     if not use_function_versioning or is_windows
172         # use pre-build objects to build shared lib
173         sources = []
174         objs += static_lib.extract_all_objects(recursive: false)
175     else
176         # for compat we need to rebuild with
177         # RTE_BUILD_SHARED_LIB defined
178         cflags += '-DRTE_BUILD_SHARED_LIB'
179     endif
180     version_map = '@0@/@1@/version.map'.format(
181             meson.current_source_dir(), l)
182     implib = 'librte_' + l + '.dll.a'
183
184     def_file = custom_target(libname + '_def',
185             command: [map_to_win_cmd, '@INPUT@', '@OUTPUT@'],
186             input: version_map,
187             output: '@0@_exports.def'.format(libname))
188
189     mingw_map = custom_target(libname + '_mingw',
190             command: [map_to_win_cmd, '@INPUT@', '@OUTPUT@'],
191             input: version_map,
192             output: '@0@_mingw.map'.format(libname))
193
194     if is_ms_linker
195         lk_args = ['-Wl,/def:' + def_file.full_path()]
196         if meson.version().version_compare('<0.54.0')
197             lk_args += ['-Wl,/implib:lib\\' + implib]
198         endif
199     else
200         if is_windows
201             lk_args = ['-Wl,--version-script=' + mingw_map.full_path()]
202         else
203             lk_args = ['-Wl,--version-script=' + version_map]
204         endif
205     endif
206
207     lk_deps = [version_map, def_file, mingw_map]
208     if not is_windows
209         # on unix systems check the output of the
210         # check-symbols.sh script, using it as a
211         # dependency of the .so build
212         lk_deps += custom_target(name + '.sym_chk',
213                 command: [check_symbols,
214                     version_map, '@INPUT@'],
215                 capture: true,
216                 input: static_lib,
217                 output: name + '.sym_chk')
218     endif
219
220     shared_lib = shared_library(libname,
221             sources,
222             objects: objs,
223             c_args: cflags,
224             dependencies: shared_deps,
225             include_directories: includes,
226             link_args: lk_args,
227             link_depends: lk_deps,
228             version: abi_version,
229             soversion: so_version,
230             install: true)
231     shared_dep = declare_dependency(link_with: shared_lib,
232             include_directories: includes,
233             dependencies: shared_deps)
234
235     dpdk_libraries = [shared_lib] + dpdk_libraries
236     dpdk_static_libraries = [static_lib] + dpdk_static_libraries
237
238     set_variable('shared_rte_' + name, shared_dep)
239     set_variable('static_rte_' + name, static_dep)
240     if developer_mode
241         message('lib/@0@: Defining dependency "@1@"'.format(l, name))
242     endif
243 endforeach