vppinfra: add abstract socket & netns fns
[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 include/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 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   graph.c
61   hash.c
62   heap.c
63   interrupt.c
64   longjmp.S
65   macros.c
66   maplog.c
67   mem.c
68   mem_bulk.c
69   mem_dlmalloc.c
70   mhash.c
71   mpcap.c
72   pcap.c
73   pmalloc.c
74   pool.c
75   ptclosure.c
76   random_buffer.c
77   random.c
78   random_isaac.c
79   rbtree.c
80   sanitizer.c
81   serialize.c
82   socket.c
83   std-formats.c
84   string.c
85   time.c
86   time_range.c
87   timing_wheel.c
88   tw_timer_2t_2w_512sl.c
89   tw_timer_16t_1w_2048sl.c
90   tw_timer_16t_2w_512sl.c
91   tw_timer_1t_3w_1024sl_ov.c
92   tw_timer_2t_1w_2048sl.c
93   tw_timer_4t_3w_256sl.c
94   unformat.c
95   unix-formats.c
96   unix-misc.c
97   valloc.c
98   vec.c
99   vector.c
100   cJSON.c
101 )
102
103 set(VPPINFRA_HEADERS
104   sanitizer.h
105   bihash_16_8.h
106   bihash_24_8.h
107   bihash_32_8.h
108   bihash_40_8.h
109   bihash_48_8.h
110   bihash_8_8.h
111   bihash_8_16.h
112   bihash_24_16.h
113   bihash_template.c
114   bihash_template.h
115   bihash_vec8_8.h
116   bitmap.h
117   bitops.h
118   byte_order.h
119   cache.h
120   callback.h
121   callback_data.h
122   cJSON.h
123   clib_error.h
124   clib.h
125   cpu.h
126   crc32.h
127   dlist.h
128   dlmalloc.h
129   elf_clib.h
130   elf.h
131   elog.h
132   error_bootstrap.h
133   error.h
134   fifo.h
135   file.h
136   format.h
137   graph.h
138   hash.h
139   heap.h
140   interrupt.h
141   lb_hash_hash.h
142   llist.h
143   lock.h
144   longjmp.h
145   macros.h
146   maplog.h
147   math.h
148   memcpy.h
149   memcpy_avx2.h
150   memcpy_avx512.h
151   memcpy_sse3.h
152   mem.h
153   mhash.h
154   mpcap.h
155   os.h
156   pcap.h
157   pcap_funcs.h
158   pmalloc.h
159   pool.h
160   ptclosure.h
161   random_buffer.h
162   random.h
163   random_isaac.h
164   rbtree.h
165   serialize.h
166   sha2.h
167   smp.h
168   socket.h
169   sparse_vec.h
170   string.h
171   time.h
172   time_range.h
173   timing_wheel.h
174   tw_timer_2t_2w_512sl.h
175   tw_timer_16t_1w_2048sl.h
176   tw_timer_16t_2w_512sl.h
177   tw_timer_1t_3w_1024sl_ov.h
178   tw_timer_2t_1w_2048sl.h
179   tw_timer_4t_3w_256sl.h
180   tw_timer_template.c
181   tw_timer_template.h
182   types.h
183   atomics.h
184   unix.h
185   valloc.h
186   vec_bootstrap.h
187   vec.h
188   vector_altivec.h
189   vector_avx2.h
190   vector_avx512.h
191   vector/mask_compare.h
192   vector/compress.h
193   vector/array_mask.h
194   vector.h
195   vector_neon.h
196   vector_sse42.h
197   warnings.h
198   xxhash.h
199   linux/sysfs.h
200 )
201
202 if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
203   list(APPEND VPPINFRA_SRCS
204     elf_clib.c
205     linux/mem.c
206     linux/sysfs.c
207     linux/netns.c
208    )
209 endif()
210
211 option(VPP_USE_EXTERNAL_LIBEXECINFO "Use external libexecinfo (useful for non-glibc targets)." OFF)
212 if(VPP_USE_EXTERNAL_LIBEXECINFO)
213   set(EXECINFO_LIB execinfo)
214 endif()
215 add_vpp_library(vppinfra
216   SOURCES ${VPPINFRA_SRCS}
217   LINK_LIBRARIES m ${EXECINFO_LIB}
218   INSTALL_HEADERS ${VPPINFRA_HEADERS}
219   COMPONENT libvppinfra
220   LTO
221 )
222
223 ##############################################################################
224 # vppinfra headers
225 ##############################################################################
226 option(VPP_BUILD_VPPINFRA_TESTS "Build vppinfra tests." OFF)
227 if(VPP_BUILD_VPPINFRA_TESTS)
228   foreach(test
229     bihash_vec88
230     dlist
231     elf
232     elog
233     fifo
234     format
235     fpool
236     hash
237     heap
238     longjmp
239     macros
240     maplog
241     pmalloc
242     pool_iterate
243     ptclosure
244     random
245     random_isaac
246     rwlock
247     serialize
248     socket
249     spinlock
250     time
251     time_range
252     tw_timer
253     valloc
254     vec
255   )
256     add_vpp_executable(test_${test}
257       SOURCES test_${test}.c
258       LINK_LIBRARIES vppinfra pthread
259       )
260   endforeach()
261
262   foreach(test bihash_template)
263     add_vpp_executable(test_${test}
264       SOURCES test_${test}.c
265       LINK_LIBRARIES vppinfra Threads::Threads
266       )
267   endforeach()
268
269 set(test_files
270   vector/test/compress.c
271   vector/test/mask_compare.c
272   vector/test/array_mask.c
273 )
274
275 add_vpp_executable(test_vector_funcs
276   SOURCES
277   vector/test/test.c
278   ${test_files}
279   LINK_LIBRARIES vppinfra
280 )
281
282 vpp_library_set_multiarch_sources(test_vector_funcs
283   SOURCES
284   ${test_files}
285 )
286
287 endif(VPP_BUILD_VPPINFRA_TESTS)