cmake: add add_vpp_library and add_vpp_executable macros
[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 6)
20 option(VPP_USE_DLMALLOC "Use dlmalloc memory allocator." ON)
21 if(VPP_USE_DLMALLOC)
22   set(DLMALLOC 1)
23 else(VPP_USE_DLMALLOC)
24   set(DLMALLOC 0)
25 endif(VPP_USE_DLMALLOC)
26
27 configure_file(
28   ${CMAKE_SOURCE_DIR}/vppinfra/config.h.in
29   ${CMAKE_BINARY_DIR}/vppinfra/config.h
30 )
31
32 install(
33   FILES ${CMAKE_BINARY_DIR}/vppinfra/config.h
34   DESTINATION include/vppinfra
35   COMPONENT dev
36 )
37
38 ##############################################################################
39 # vppinfra sources
40 ##############################################################################
41 set(VPPINFRA_SRCS
42   asm_x86.c
43   backtrace.c
44   cpu.c
45   cuckoo_template.c
46   elf.c
47   elf_clib.c
48   elog.c
49   error.c
50   fheap.c
51   fifo.c
52   format.c
53   graph.c
54   hash.c
55   heap.c
56   longjmp.S
57   macros.c
58   maplog.c
59   mhash.c
60   pool.c
61   ptclosure.c
62   qsort.c
63   random.c
64   random_buffer.c
65   random_isaac.c
66   serialize.c
67   slist.c
68   socket.c
69   std-formats.c
70   string.c
71   time.c
72   time_range.c
73   timer.c
74   timing_wheel.c
75   tw_timer_2t_1w_2048sl.c
76   tw_timer_16t_2w_512sl.c
77   tw_timer_16t_1w_2048sl.c
78   tw_timer_4t_3w_256sl.c
79   tw_timer_1t_3w_1024sl_ov.c
80   unformat.c
81   unix-formats.c
82   unix-misc.c
83   valloc.c
84   vec.c
85   vector.c
86   zvec.c
87   linux/mem.c
88   linux/sysfs.c
89 )
90
91 set(VPPINFRA_HEADERS
92   asm_mips.h
93   asm_x86.h
94   bihash_16_8.h
95   bihash_24_8.h
96   bihash_40_8.h
97   bihash_48_8.h
98   bihash_8_8.h
99   bihash_template.c
100   bihash_template.h
101   bihash_vec8_8.h
102   bitmap.h
103   bitops.h
104   byte_order.h
105   cache.h
106   clib_error.h
107   clib.h
108   cpu.h
109   crc32.h
110   dlist.h
111   dlmalloc.h
112   elf_clib.h
113   elf.h
114   elog.h
115   error_bootstrap.h
116   error.h
117   fheap.h
118   fifo.h
119   file.h
120   flowhash_24_16.h
121   flowhash_8_8.h
122   flowhash_template.h
123   format.h
124   graph.h
125   hash.h
126   heap.h
127   lb_hash_hash.h
128   lock.h
129   longjmp.h
130   macros.h
131   maplog.h
132   math.h
133   memcpy_avx2.h
134   memcpy_avx512.h
135   memcpy_sse3.h
136   mem.h
137   mhash.h
138   mheap_bootstrap.h
139   mheap.h
140   os.h
141   pipeline.h
142   pool.h
143   ptclosure.h
144   random_buffer.h
145   random.h
146   random_isaac.h
147   serialize.h
148   slist.h
149   smp.h
150   socket.h
151   sparse_vec.h
152   string.h
153   time.h
154   time_range.h
155   timer.h
156   timing_wheel.h
157   tw_timer_16t_1w_2048sl.h
158   tw_timer_16t_2w_512sl.h
159   tw_timer_1t_3w_1024sl_ov.h
160   tw_timer_2t_1w_2048sl.h
161   tw_timer_4t_3w_256sl.h
162   tw_timer_template.c
163   tw_timer_template.h
164   types.h
165   unix.h
166   valgrind.h
167   valloc.h
168   vec_bootstrap.h
169   vec.h
170   vector_altivec.h
171   vector_avx2.h
172   vector_avx512.h
173   vector_funcs.h
174   vector.h
175   vector_neon.h
176   vector_sse42.h
177   xxhash.h
178   xy.h
179   zvec.h
180   linux/syscall.h
181   linux/sysfs.h
182 )
183
184
185 if(VPP_USE_DLMALLOC)
186   list(APPEND VPPINFRA_SRCS
187     dlmalloc.c
188     mem_dlmalloc.c
189   )
190 else(VPP_USE_DLMALLOC)
191   list(APPEND VPPINFRA_SRCS
192     mheap.c
193     mem_mheap.c
194   )
195 endif(VPP_USE_DLMALLOC)
196
197 add_vpp_library(vppinfra
198   SOURCES ${VPPINFRA_SRCS}
199   LINK_LIBRARIES m
200   INSTALL_HEADERS ${VPPINFRA_HEADERS}
201 )
202
203 ##############################################################################
204 # vppinfra headers
205 ##############################################################################
206 option(VPP_BUILD_VPPINFRA_TESTS "Build vppinfra tests." OFF)
207 if(VPP_BUILD_VPPINFRA_TESTS)
208   foreach(test
209     bihash_vec88
210     cuckoo_template
211     dlist
212     elf
213     elog
214     fifo
215     flowhash_template
216     format
217     fpool
218     hash
219     heap
220     longjmp
221     macros
222     maplog
223     pool_iterate
224     ptclosure
225     random
226     random_isaac
227     serialize
228     slist
229     socket
230     time
231     time_range
232     timing_wheel
233     tw_timer
234     valloc
235     vec
236     zvec
237   )
238     add_vpp_executable(test_${test}
239       SOURCES test_${test}.c
240       LINK_LIBRARIES vppinfra
241       )
242   endforeach()
243
244   foreach(test bihash_template cuckoo_bihash)
245     add_vpp_executable(test_${test}
246       SOURCES test_${test}.c
247       LINK_LIBRARIES vppinfra Threads::Threads
248       )
249   endforeach()
250 endif(VPP_BUILD_VPPINFRA_TESTS)