hash: 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', 'mbuf', 'net', 'meter', 'ethdev', 'pci', # core
18         'cmdline',
19         'metrics', # bitrate/latency stats depends on this
20         'hash',    # efd depends on this
21         'timer',   # eventdev depends on this
22         'acl', 'bbdev', 'bitratestats', 'cfgfile',
23         'compressdev', 'cryptodev',
24         'distributor', 'efd', 'eventdev',
25         'gro', 'gso', 'ip_frag', 'jobstats',
26         'kni', 'latencystats', 'lpm', 'member',
27         'power', 'pdump', 'rawdev', 'regexdev',
28         'rib', 'reorder', 'sched', 'security', 'stack', 'vhost',
29         # ipsec lib depends on net, crypto and security
30         'ipsec',
31         #fib lib depends on rib
32         'fib',
33         # add pkt framework libs which use other libs from above
34         'port', 'table', 'pipeline',
35         # flow_classify lib depends on pkt framework table lib
36         'flow_classify', 'bpf', 'graph', 'node']
37
38 if is_windows
39         libraries = [
40                 'kvargs',
41                 'telemetry',
42                 'eal',
43                 'ring',
44                 'mempool', 'mbuf', 'net', 'meter', 'ethdev', 'pci',
45                 'hash',
46         ] # only supported libraries for windows
47 endif
48
49 default_cflags = machine_args
50 default_cflags += ['-DALLOW_EXPERIMENTAL_API']
51 default_cflags += ['-DALLOW_INTERNAL_API']
52
53 if cc.has_argument('-Wno-format-truncation')
54         default_cflags += '-Wno-format-truncation'
55 endif
56
57 enabled_libs = [] # used to print summary at the end
58
59 foreach l:libraries
60         build = true
61         reason = '<unknown reason>' # set if build == false to explain why
62         name = l
63         use_function_versioning = false
64         sources = []
65         headers = []
66         includes = []
67         cflags = default_cflags
68         objs = [] # other object files to link against, used e.g. for
69                   # instruction-set optimized versions of code
70
71         # use "deps" for internal DPDK dependencies, and "ext_deps" for
72         # external package/library requirements
73         ext_deps = []
74         deps = []
75         # eal is standard dependency once built
76         if dpdk_conf.has('RTE_LIBRTE_EAL')
77                 deps += ['eal']
78         endif
79
80         dir_name = 'librte_' + l
81         subdir(dir_name)
82
83         if build
84                 shared_deps = ext_deps
85                 static_deps = ext_deps
86                 foreach d:deps
87                         if not is_variable('shared_rte_' + d)
88                                 error('Missing internal dependency "@0@" for @1@ [@2@]'
89                                                 .format(d, name, 'lib/' + dir_name))
90                         endif
91                         shared_deps += [get_variable('shared_rte_' + d)]
92                         static_deps += [get_variable('static_rte_' + d)]
93                 endforeach
94         endif
95
96         if not build
97                 dpdk_libs_disabled += name
98                 set_variable(name.underscorify() + '_disable_reason', reason)
99         else
100                 enabled_libs += name
101                 dpdk_conf.set('RTE_LIBRTE_' + name.to_upper(), 1)
102                 install_headers(headers)
103
104                 libname = 'rte_' + name
105                 includes += include_directories(dir_name)
106
107                 if sources.length() == 0
108                         # if no C files, just set a dependency on header path
109                         shared_dep = declare_dependency(include_directories: includes)
110                         static_dep = shared_dep
111                 else
112                         if is_windows and use_function_versioning
113                                 message('@0@: Function versioning is not supported by Windows.'
114                                 .format(name))
115                         endif
116
117                         if use_function_versioning
118                                 cflags += '-DRTE_USE_FUNCTION_VERSIONING'
119                         endif
120
121                         # first build static lib
122                         static_lib = static_library(libname,
123                                         sources,
124                                         objects: objs,
125                                         c_args: cflags,
126                                         dependencies: static_deps,
127                                         include_directories: includes,
128                                         install: true)
129                         static_dep = declare_dependency(
130                                         include_directories: includes,
131                                         dependencies: static_deps)
132
133                         if not use_function_versioning or is_windows
134                                 # use pre-build objects to build shared lib
135                                 sources = []
136                                 objs += static_lib.extract_all_objects(recursive: false)
137                         else
138                                 # for compat we need to rebuild with
139                                 # RTE_BUILD_SHARED_LIB defined
140                                 cflags += '-DRTE_BUILD_SHARED_LIB'
141                         endif
142                         version_map = '@0@/@1@/rte_@2@_version.map'.format(
143                                         meson.current_source_dir(), dir_name, name)
144                         implib = dir_name + '.dll.a'
145
146                         def_file = custom_target(libname + '_def',
147                                 command: [map_to_win_cmd, '@INPUT@', '@OUTPUT@'],
148                                 input: version_map,
149                                 output: '@0@_exports.def'.format(libname))
150
151                         mingw_map = custom_target(libname + '_mingw',
152                                 command: [map_to_win_cmd, '@INPUT@', '@OUTPUT@'],
153                                 input: version_map,
154                                 output: '@0@_mingw.map'.format(libname))
155
156                         if is_ms_linker
157                                 lk_args = ['-Wl,/def:' + def_file.full_path(),
158                                         '-Wl,/implib:lib\\' + implib]
159                         else
160                                 if is_windows
161                                         lk_args = ['-Wl,--version-script=' + mingw_map.full_path()]
162                                 else
163                                         lk_args = ['-Wl,--version-script=' + version_map]
164                                 endif
165                         endif
166
167                         lk_deps = [version_map, def_file, mingw_map]
168                         if not is_windows
169                                 # on unix systems check the output of the
170                                 # check-symbols.sh script, using it as a
171                                 # dependency of the .so build
172                                 lk_deps += custom_target(name + '.sym_chk',
173                                         command: [check_symbols,
174                                                 version_map, '@INPUT@'],
175                                         capture: true,
176                                         input: static_lib,
177                                         output: name + '.sym_chk')
178                         endif
179
180                         shared_lib = shared_library(libname,
181                                         sources,
182                                         objects: objs,
183                                         c_args: cflags,
184                                         dependencies: shared_deps,
185                                         include_directories: includes,
186                                         link_args: lk_args,
187                                         link_depends: lk_deps,
188                                         version: abi_version,
189                                         soversion: so_version,
190                                         install: true)
191                         shared_dep = declare_dependency(link_with: shared_lib,
192                                         include_directories: includes,
193                                         dependencies: shared_deps)
194
195                         dpdk_libraries = [shared_lib] + dpdk_libraries
196                         dpdk_static_libraries = [static_lib] + dpdk_static_libraries
197                 endif # sources.length() > 0
198
199                 set_variable('shared_rte_' + name, shared_dep)
200                 set_variable('static_rte_' + name, static_dep)
201                 message('lib/@0@: Defining dependency "@1@"'.format(
202                                 dir_name, name))
203         endif # if build
204 endforeach