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