xref: /dpdk/lib/meson.build (revision 2d0c29a37a9c080c1cccb1ad7941aba2ccf5437e)
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	'eal', # everything depends on eal
14	'cmdline', # ethdev depends on cmdline for parsing functions
15	'ring', 'mempool', 'mbuf', 'net', 'meter', 'ethdev', 'pci', # core
16	'metrics', # bitrate/latency stats depends on this
17	'hash',    # efd depends on this
18	'timer',   # eventdev depends on this
19	'acl', 'bbdev', 'bitratestats', 'cfgfile',
20	'compressdev', 'cryptodev',
21	'distributor', 'efd', 'eventdev',
22	'gro', 'gso', 'ip_frag', 'jobstats',
23	'kni', 'latencystats', 'lpm', 'member',
24	'power', 'pdump', 'rawdev',
25	'reorder', 'sched', 'security', 'vhost',
26	#ipsec lib depends on crypto and security
27	'ipsec',
28	# add pkt framework libs which use other libs from above
29	'port', 'table', 'pipeline',
30	# flow_classify lib depends on pkt framework table lib
31	'flow_classify', 'bpf', 'telemetry']
32
33if host_machine.system() == 'windows'
34	libraries = ['kvargs','eal'] # only supported libraries for windows
35endif
36
37default_cflags = machine_args
38if cc.has_argument('-Wno-format-truncation')
39	default_cflags += '-Wno-format-truncation'
40endif
41
42enabled_libs = [] # used to print summary at the end
43
44# -D_GNU_SOURCE unconditionally
45default_cflags += '-D_GNU_SOURCE'
46
47foreach l:libraries
48	build = true
49	name = l
50	version = 1
51	allow_experimental_apis = false
52	sources = []
53	headers = []
54	includes = []
55	cflags = default_cflags
56	objs = [] # other object files to link against, used e.g. for
57	          # instruction-set optimized versions of code
58
59	# use "deps" for internal DPDK dependencies, and "ext_deps" for
60	# external package/library requirements
61	ext_deps = []
62	deps = []
63	# eal is standard dependency once built
64	if dpdk_conf.has('RTE_LIBRTE_EAL')
65		deps += ['eal']
66	endif
67
68	dir_name = 'librte_' + l
69	subdir(dir_name)
70
71	if build
72		enabled_libs += name
73		dpdk_conf.set('RTE_LIBRTE_' + name.to_upper(), 1)
74		install_headers(headers)
75
76		libname = 'rte_' + name
77		includes += include_directories(dir_name)
78
79		if sources.length() == 0
80			# if no C files, just set a dependency on header path
81			shared_dep = declare_dependency(include_directories: includes)
82			static_dep = shared_dep
83		else
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 dependency ' + d +
89						' for library ' + libname)
90				endif
91				shared_deps += [get_variable('shared_rte_' + d)]
92				static_deps += [get_variable('static_rte_' + d)]
93			endforeach
94
95			if allow_experimental_apis
96				cflags += '-DALLOW_EXPERIMENTAL_API'
97			endif
98
99			if get_option('per_library_versions')
100				lib_version = '@0@.1'.format(version)
101				so_version = '@0@'.format(version)
102			else
103				lib_version = major_version
104				so_version = major_version
105			endif
106
107			# first build static lib
108			static_lib = static_library(libname,
109					sources,
110					objects: objs,
111					c_args: cflags,
112					dependencies: static_deps,
113					include_directories: includes,
114					install: true)
115			static_dep = declare_dependency(link_with: static_lib,
116					include_directories: includes,
117					dependencies: static_deps)
118
119			# then use pre-build objects to build shared lib
120			sources = []
121			objs += static_lib.extract_all_objects(recursive: false)
122			version_map = '@0@/@1@/rte_@2@_version.map'.format(
123					meson.current_source_dir(), dir_name, name)
124			exports = []
125			implib = dir_name + '.dll.a'
126			if host_machine.system() == 'windows'
127				exports = '@0@/@1@/rte_@2@_exports.def'.format(
128					meson.current_source_dir(), dir_name, name)
129				lk_args = ['-Wl,/def:' + exports, '-Wl,/implib:lib\\' + implib]
130			else
131				lk_args = ['-Wl,--version-script=' + version_map]
132			endif
133			shared_lib = shared_library(libname,
134					sources,
135					objects: objs,
136					c_args: cflags,
137					dependencies: shared_deps,
138					include_directories: includes,
139					link_args: lk_args,
140					link_depends: [version_map, exports],
141					version: lib_version,
142					soversion: so_version,
143					install: true)
144			shared_dep = declare_dependency(link_with: shared_lib,
145					include_directories: includes,
146					dependencies: shared_deps)
147
148			dpdk_libraries = [shared_lib] + dpdk_libraries
149			dpdk_static_libraries = [static_lib] + dpdk_static_libraries
150		endif # sources.length() > 0
151
152		set_variable('shared_' + libname, shared_dep)
153		set_variable('static_' + libname, static_dep)
154	endif # if build
155endforeach
156