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