cbcb985beb56785120cd46b28c1c49ab3d404848
[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',
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 = ['kvargs','eal'] # only supported libraries for windows
40 endif
41
42 default_cflags = machine_args
43 default_cflags += ['-DALLOW_EXPERIMENTAL_API']
44 default_cflags += ['-DALLOW_INTERNAL_API']
45
46 if cc.has_argument('-Wno-format-truncation')
47         default_cflags += '-Wno-format-truncation'
48 endif
49
50 enabled_libs = [] # used to print summary at the end
51
52 foreach l:libraries
53         build = true
54         reason = '<unknown reason>' # set if build == false to explain why
55         name = l
56         use_function_versioning = false
57         sources = []
58         headers = []
59         includes = []
60         cflags = default_cflags
61         objs = [] # other object files to link against, used e.g. for
62                   # instruction-set optimized versions of code
63
64         # use "deps" for internal DPDK dependencies, and "ext_deps" for
65         # external package/library requirements
66         ext_deps = []
67         deps = []
68         # eal is standard dependency once built
69         if dpdk_conf.has('RTE_LIBRTE_EAL')
70                 deps += ['eal']
71         endif
72
73         dir_name = 'librte_' + l
74         subdir(dir_name)
75
76         if build
77                 shared_deps = ext_deps
78                 static_deps = ext_deps
79                 foreach d:deps
80                         if not is_variable('shared_rte_' + d)
81                                 error('Missing internal dependency "@0@" for @1@ [@2@]'
82                                                 .format(d, name, 'lib/' + dir_name))
83                         endif
84                         shared_deps += [get_variable('shared_rte_' + d)]
85                         static_deps += [get_variable('static_rte_' + d)]
86                 endforeach
87         endif
88
89         if not build
90                 dpdk_libs_disabled += name
91                 set_variable(name.underscorify() + '_disable_reason', reason)
92         else
93                 enabled_libs += name
94                 dpdk_conf.set('RTE_LIBRTE_' + name.to_upper(), 1)
95                 install_headers(headers)
96
97                 libname = 'rte_' + name
98                 includes += include_directories(dir_name)
99
100                 if sources.length() == 0
101                         # if no C files, just set a dependency on header path
102                         shared_dep = declare_dependency(include_directories: includes)
103                         static_dep = shared_dep
104                 else
105
106                         if use_function_versioning
107                                 cflags += '-DRTE_USE_FUNCTION_VERSIONING'
108                         endif
109
110                         version_map = '@0@/@1@/rte_@2@_version.map'.format(
111                                         meson.current_source_dir(), dir_name, name)
112
113                         is_stable = run_command(is_stable_cmd,
114                                         files(version_map)).returncode() == 0
115
116                         if is_stable
117                                 lib_version = abi_version
118                                 so_version = stable_so_version
119                         else
120                                 lib_version = experimental_abi_version
121                                 so_version = experimental_so_version
122                         endif
123
124                         # first build static lib
125                         static_lib = static_library(libname,
126                                         sources,
127                                         objects: objs,
128                                         c_args: cflags,
129                                         dependencies: static_deps,
130                                         include_directories: includes,
131                                         install: true)
132                         static_dep = declare_dependency(link_with: static_lib,
133                                         include_directories: includes,
134                                         dependencies: static_deps)
135
136                         if not use_function_versioning
137                                 # use pre-build objects to build shared lib
138                                 sources = []
139                                 objs += static_lib.extract_all_objects(recursive: false)
140                         else
141                                 # for compat we need to rebuild with
142                                 # RTE_BUILD_SHARED_LIB defined
143                                 cflags += '-DRTE_BUILD_SHARED_LIB'
144                         endif
145                         version_map = '@0@/@1@/rte_@2@_version.map'.format(
146                                         meson.current_source_dir(), dir_name, name)
147                         implib = dir_name + '.dll.a'
148
149                         def_file = custom_target(libname + '_def',
150                                 command: [map_to_win_cmd, '@INPUT@', '@OUTPUT@'],
151                                 input: version_map,
152                                 output: '@0@_exports.def'.format(libname))
153
154                         mingw_map = custom_target(libname + '_mingw',
155                                 command: [map_to_win_cmd, '@INPUT@', '@OUTPUT@'],
156                                 input: version_map,
157                                 output: '@0@_mingw.map'.format(libname))
158
159                         if is_ms_linker
160                                 lk_args = ['-Wl,/def:' + def_file.full_path(),
161                                         '-Wl,/implib:lib\\' + implib]
162                         else
163                                 if is_windows
164                                         lk_args = ['-Wl,--version-script=' + mingw_map.full_path()]
165                                 else
166                                         lk_args = ['-Wl,--version-script=' + version_map]
167                                 endif
168                         endif
169
170                         lk_deps = [version_map, def_file, mingw_map]
171                         if not is_windows
172                                 # on unix systems check the output of the
173                                 # check-symbols.sh script, using it as a
174                                 # dependency of the .so build
175                                 lk_deps += custom_target(name + '.sym_chk',
176                                         command: [check_symbols,
177                                                 version_map, '@INPUT@'],
178                                         capture: true,
179                                         input: static_lib,
180                                         output: name + '.sym_chk')
181                         endif
182
183                         shared_lib = shared_library(libname,
184                                         sources,
185                                         objects: objs,
186                                         c_args: cflags,
187                                         dependencies: shared_deps,
188                                         include_directories: includes,
189                                         link_args: lk_args,
190                                         link_depends: lk_deps,
191                                         version: lib_version,
192                                         soversion: so_version,
193                                         install: true)
194                         shared_dep = declare_dependency(link_with: shared_lib,
195                                         include_directories: includes,
196                                         dependencies: shared_deps)
197
198                         dpdk_libraries = [shared_lib] + dpdk_libraries
199                         dpdk_static_libraries = [static_lib] + dpdk_static_libraries
200                         if libname == 'rte_node'
201                                 dpdk_graph_nodes = [static_lib]
202                         endif
203                 endif # sources.length() > 0
204
205                 set_variable('shared_rte_' + name, shared_dep)
206                 set_variable('static_rte_' + name, static_dep)
207                 message('lib/@0@: Defining dependency "@1@"'.format(
208                                 dir_name, name))
209         endif # if build
210 endforeach