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