975bf503827cb703703332584e7bcc187caf1640
[vpp.git] / src / vppinfra / CMakeLists.txt
1 # Copyright (c) 2018 Cisco and/or its affiliates.
2 # Licensed under the Apache License, Version 2.0 (the "License");
3 # you may not use this file except in compliance with the License.
4 # You may obtain a copy of the License at:
5 #
6 #     http://www.apache.org/licenses/LICENSE-2.0
7 #
8 # Unless required by applicable law or agreed to in writing, software
9 # distributed under the License is distributed on an "AS IS" BASIS,
10 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 # See the License for the specific language governing permissions and
12 # limitations under the License.
13
14 enable_language(ASM)
15
16 ##############################################################################
17 # Generate vppinfra/config.h
18 ##############################################################################
19 set(LOG2_CACHE_LINE_BYTES ${VPP_LOG2_CACHE_LINE_SIZE})
20
21 option(VPP_VECTOR_GROW_BY_ONE "Vectors grow by one, instead of 3/2" OFF)
22 if(VPP_VECTOR_GROW_BY_ONE)
23   set(VECTOR_GROW_BY_ONE 1)
24 else(VPP_VECTOR_GROW_BY_ONE)
25   set(VECTOR_GROW_BY_ONE 0)
26 endif(VPP_VECTOR_GROW_BY_ONE)
27
28 configure_file(
29   ${CMAKE_SOURCE_DIR}/vppinfra/config.h.in
30   ${CMAKE_CURRENT_BINARY_DIR}/config.h
31 )
32
33 install(
34   FILES ${CMAKE_CURRENT_BINARY_DIR}/config.h
35   DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/vppinfra
36   COMPONENT vpp-dev
37 )
38
39 add_definitions(-fvisibility=hidden)
40
41 # Ensure symbols from cJSON are exported
42 set_source_files_properties( cJSON.c jsonformat.c PROPERTIES
43   COMPILE_DEFINITIONS " CJSON_API_VISIBILITY " )
44
45
46 ##############################################################################
47 # vppinfra sources
48 ##############################################################################
49 set(VPPINFRA_SRCS
50   backtrace.c
51   bitmap.c
52   bihash_all_vector.c
53   cpu.c
54   dlmalloc.c
55   elf.c
56   elog.c
57   error.c
58   fifo.c
59   format.c
60   format_table.c
61   hash.c
62   heap.c
63   interrupt.c
64   jsonformat.c
65   longjmp.S
66   macros.c
67   maplog.c
68   mem.c
69   mem_bulk.c
70   mem_dlmalloc.c
71   mhash.c
72   mpcap.c
73   pcap.c
74   perfmon/bundle_default.c
75   perfmon/bundle_core_power.c
76   perfmon/perfmon.c
77   pmalloc.c
78   pool.c
79   ptclosure.c
80   random_buffer.c
81   random.c
82   random_isaac.c
83   rbtree.c
84   serialize.c
85   socket.c
86   std-formats.c
87   string.c
88   time.c
89   time_range.c
90   timing_wheel.c
91   tw_timer_2t_2w_512sl.c
92   tw_timer_16t_1w_2048sl.c
93   tw_timer_16t_2w_512sl.c
94   tw_timer_1t_3w_1024sl_ov.c
95   tw_timer_2t_1w_2048sl.c
96   tw_timer_4t_3w_256sl.c
97   unformat.c
98   unix-formats.c
99   unix-misc.c
100   valloc.c
101   vec.c
102   vector.c
103   vector/toeplitz.c
104   cJSON.c
105 )
106
107 set(VPPINFRA_HEADERS
108   bihash_12_4.h
109   bihash_16_8.h
110   bihash_24_8.h
111   bihash_32_8.h
112   bihash_40_8.h
113   bihash_48_8.h
114   bihash_8_8.h
115   bihash_8_16.h
116   bihash_24_16.h
117   bihash_template.c
118   bihash_template.h
119   bihash_vec8_8.h
120   bitmap.h
121   bitops.h
122   byte_order.h
123   cache.h
124   callback.h
125   callback_data.h
126   cJSON.h
127   clib_error.h
128   clib.h
129   cpu.h
130   crc32.h
131   dlist.h
132   dlmalloc.h
133   elf_clib.h
134   elf.h
135   elog.h
136   error_bootstrap.h
137   error.h
138   fifo.h
139   file.h
140   format.h
141   format_table.h
142   hash.h
143   heap.h
144   interrupt.h
145   jsonformat.h
146   lb_hash_hash.h
147   llist.h
148   lock.h
149   longjmp.h
150   macros.h
151   maplog.h
152   math.h
153   memcpy.h
154   memcpy_x86_64.h
155   mem.h
156   mhash.h
157   mpcap.h
158   os.h
159   pcap.h
160   pcap_funcs.h
161   pcg.h
162   perfmon/perfmon.h
163   pmalloc.h
164   pool.h
165   ptclosure.h
166   random_buffer.h
167   random.h
168   random_isaac.h
169   rbtree.h
170   serialize.h
171   sha2.h
172   smp.h
173   socket.h
174   sparse_vec.h
175   string.h
176   time.h
177   time_range.h
178   timing_wheel.h
179   tw_timer_2t_2w_512sl.h
180   tw_timer_16t_1w_2048sl.h
181   tw_timer_16t_2w_512sl.h
182   tw_timer_1t_3w_1024sl_ov.h
183   tw_timer_2t_1w_2048sl.h
184   tw_timer_4t_3w_256sl.h
185   tw_timer_template.c
186   tw_timer_template.h
187   types.h
188   atomics.h
189   unix.h
190   valloc.h
191   vec_bootstrap.h
192   vec.h
193   vector_altivec.h
194   vector_avx2.h
195   vector_avx512.h
196   vector/array_mask.h
197   vector/compress.h
198   vector/count_equal.h
199   vector/index_to_ptr.h
200   vector/ip_csum.h
201   vector/mask_compare.h
202   vector/toeplitz.h
203   vector.h
204   vector_neon.h
205   vector_sse42.h
206   warnings.h
207   xxhash.h
208   linux/sysfs.h
209 )
210
211 if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
212   list(APPEND VPPINFRA_SRCS
213     elf_clib.c
214     linux/mem.c
215     linux/sysfs.c
216     linux/netns.c
217    )
218 endif()
219
220 option(VPP_USE_EXTERNAL_LIBEXECINFO "Use external libexecinfo (useful for non-glibc targets)." OFF)
221 if(VPP_USE_EXTERNAL_LIBEXECINFO)
222   set(EXECINFO_LIB execinfo)
223 endif()
224 add_vpp_library(vppinfra
225   SOURCES ${VPPINFRA_SRCS}
226   LINK_LIBRARIES m ${EXECINFO_LIB}
227   INSTALL_HEADERS ${VPPINFRA_HEADERS}
228   COMPONENT libvppinfra
229   LTO
230 )
231
232 ##############################################################################
233 # vppinfra headers
234 ##############################################################################
235 option(VPP_BUILD_VPPINFRA_TESTS "Build vppinfra tests." OFF)
236 if(VPP_BUILD_VPPINFRA_TESTS)
237   foreach(test
238     bihash_vec88
239     dlist
240     elf
241     elog
242     fifo
243     format
244     fpool
245     hash
246     heap
247     longjmp
248     macros
249     maplog
250     pmalloc
251     pool_alloc
252     pool_iterate
253     ptclosure
254     random
255     random_isaac
256     rwlock
257     serialize
258     socket
259     spinlock
260     time
261     time_range
262     tw_timer
263     valloc
264     vec
265   )
266     add_vpp_executable(test_${test}
267       SOURCES test_${test}.c
268       LINK_LIBRARIES vppinfra pthread
269       )
270   endforeach()
271
272   foreach(test bihash_template)
273     add_vpp_executable(test_${test}
274       SOURCES test_${test}.c
275       LINK_LIBRARIES vppinfra Threads::Threads
276       )
277   endforeach()
278 endif(VPP_BUILD_VPPINFRA_TESTS)
279
280 set(test_files
281   test/array_mask.c
282   test/compress.c
283   test/count_equal.c
284   test/crc32c.c
285   test/index_to_ptr.c
286   test/ip_csum.c
287   test/mask_compare.c
288   test/memcpy_x86_64.c
289   test/sha2.c
290   test/toeplitz.c
291 )
292
293 add_vpp_executable(test_infra
294   SOURCES
295   test/test.c
296   ${test_files}
297   LINK_LIBRARIES vppinfra
298   NO_INSTALL
299 )
300
301 vpp_library_set_multiarch_sources(test_infra
302   SOURCES
303   ${test_files}
304 )
305