mempool/stack: build on Windows
[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             'metrics',
80             'hash',
81             'timer',
82             'bitratestats',
83             'cfgfile',
84             'gro',
85             'gso',
86             'latencystats',
87             'pdump',
88             'stack',
89     ] # only supported libraries for windows
90 endif
91
92 optional_libs = [
93         'kni',
94         'power',
95         'vhost',
96 ]
97
98 disabled_libs = []
99 opt_disabled_libs = run_command(list_dir_globs, get_option('disable_libs'),
100         check: true).stdout().split()
101 foreach l:opt_disabled_libs
102     if not optional_libs.contains(l)
103         warning('Cannot disable mandatory library "@0@"'.format(l))
104         continue
105     endif
106     disabled_libs += l
107 endforeach
108
109
110 default_cflags = machine_args
111 default_cflags += ['-DALLOW_EXPERIMENTAL_API']
112 default_cflags += ['-DALLOW_INTERNAL_API']
113
114 if cc.has_argument('-Wno-format-truncation')
115     default_cflags += '-Wno-format-truncation'
116 endif
117
118 enabled_libs = [] # used to print summary at the end
119
120 foreach l:libraries
121     build = true
122     reason = '<unknown reason>' # set if build == false to explain why
123     name = l
124     use_function_versioning = false
125     sources = []
126     headers = []
127     indirect_headers = [] # public headers not directly included by apps
128     driver_sdk_headers = [] # public headers included by drivers
129     includes = []
130     cflags = default_cflags
131     objs = [] # other object files to link against, used e.g. for
132               # instruction-set optimized versions of code
133
134     # use "deps" for internal DPDK dependencies, and "ext_deps" for
135     # external package/library requirements
136     ext_deps = []
137     deps = []
138     # eal is standard dependency once built
139     if dpdk_conf.has('RTE_LIB_EAL')
140         deps += ['eal']
141     endif
142
143     if disabled_libs.contains(l)
144         build = false
145         reason = 'explicitly disabled via build config'
146     else
147         subdir(l)
148     endif
149     if name != l
150         warning('Library name, "@0@", and directory name, "@1@", do not match'.format(name, l))
151     endif
152
153     if not build
154         dpdk_libs_disabled += name
155         set_variable(name.underscorify() + '_disable_reason', reason)
156         continue
157     endif
158
159     shared_deps = ext_deps
160     static_deps = ext_deps
161     foreach d:deps
162         if not is_variable('shared_rte_' + d)
163             error('Missing internal dependency "@0@" for @1@ [@2@]'
164                     .format(d, name, 'lib/' + l))
165         endif
166         shared_deps += [get_variable('shared_rte_' + d)]
167         static_deps += [get_variable('static_rte_' + d)]
168     endforeach
169
170     enabled_libs += name
171     dpdk_conf.set('RTE_LIB_' + name.to_upper(), 1)
172     install_headers(headers)
173     install_headers(indirect_headers)
174     if get_option('enable_driver_sdk')
175         install_headers(driver_sdk_headers)
176     endif
177     dpdk_chkinc_headers += headers
178
179     libname = 'rte_' + name
180     includes += include_directories(l)
181
182     if developer_mode and is_windows and use_function_versioning
183         message('@0@: Function versioning is not supported by Windows.'.format(name))
184     endif
185
186     if use_function_versioning
187         cflags += '-DRTE_USE_FUNCTION_VERSIONING'
188     endif
189     cflags += '-DRTE_LOG_DEFAULT_LOGTYPE=lib.' + l
190
191     # first build static lib
192     static_lib = static_library(libname,
193             sources,
194             objects: objs,
195             c_args: cflags,
196             dependencies: static_deps,
197             include_directories: includes,
198             install: true)
199     static_dep = declare_dependency(
200             include_directories: includes,
201             dependencies: static_deps)
202
203     if not use_function_versioning or is_windows
204         # use pre-build objects to build shared lib
205         sources = []
206         objs += static_lib.extract_all_objects(recursive: false)
207     else
208         # for compat we need to rebuild with
209         # RTE_BUILD_SHARED_LIB defined
210         cflags += '-DRTE_BUILD_SHARED_LIB'
211     endif
212     version_map = '@0@/@1@/version.map'.format(
213             meson.current_source_dir(), l)
214     implib = 'librte_' + l + '.dll.a'
215
216     def_file = custom_target(libname + '_def',
217             command: [map_to_win_cmd, '@INPUT@', '@OUTPUT@'],
218             input: version_map,
219             output: '@0@_exports.def'.format(libname))
220
221     mingw_map = custom_target(libname + '_mingw',
222             command: [map_to_win_cmd, '@INPUT@', '@OUTPUT@'],
223             input: version_map,
224             output: '@0@_mingw.map'.format(libname))
225
226     if is_ms_linker
227         lk_args = ['-Wl,/def:' + def_file.full_path()]
228         if meson.version().version_compare('<0.54.0')
229             lk_args += ['-Wl,/implib:lib\\' + implib]
230         endif
231     else
232         if is_windows
233             lk_args = ['-Wl,--version-script=' + mingw_map.full_path()]
234         else
235             lk_args = ['-Wl,--version-script=' + version_map]
236         endif
237     endif
238
239     lk_deps = [version_map, def_file, mingw_map]
240     if developer_mode and not is_windows
241         # on unix systems check the output of the
242         # check-symbols.sh script, using it as a
243         # dependency of the .so build
244         lk_deps += custom_target(name + '.sym_chk',
245                 command: [check_symbols,
246                     version_map, '@INPUT@'],
247                 capture: true,
248                 input: static_lib,
249                 output: name + '.sym_chk')
250     endif
251
252     shared_lib = shared_library(libname,
253             sources,
254             objects: objs,
255             c_args: cflags,
256             dependencies: shared_deps,
257             include_directories: includes,
258             link_args: lk_args,
259             link_depends: lk_deps,
260             version: abi_version,
261             soversion: so_version,
262             install: true)
263     shared_dep = declare_dependency(link_with: shared_lib,
264             include_directories: includes,
265             dependencies: shared_deps)
266
267     dpdk_libraries = [shared_lib] + dpdk_libraries
268     dpdk_static_libraries = [static_lib] + dpdk_static_libraries
269
270     set_variable('shared_rte_' + name, shared_dep)
271     set_variable('static_rte_' + name, static_dep)
272     if developer_mode
273         message('lib/@0@: Defining dependency "@1@"'.format(l, name))
274     endif
275 endforeach