cmake: fix -DVPP_USE_DLMALLOC=OFF
[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 if(VPP_USE_DLMALLOC)
92   list(APPEND VPPINFRA_SRCS
93     dlmalloc.c
94     mem_dlmalloc.c
95   )
96 else(VPP_USE_DLMALLOC)
97   list(APPEND VPPINFRA_SRCS
98     mheap.c
99     mem_mheap.c
100   )
101 endif(VPP_USE_DLMALLOC)
102
103 add_library(vppinfra SHARED ${VPPINFRA_SRCS})
104 target_link_libraries(vppinfra m)
105 install(TARGETS vppinfra DESTINATION lib)
106
107 ##############################################################################
108 # vppinfra headers
109 ##############################################################################
110 vpp_add_header_files(vppinfra
111   asm_mips.h
112   asm_x86.h
113   bihash_16_8.h
114   bihash_24_8.h
115   bihash_40_8.h
116   bihash_48_8.h
117   bihash_8_8.h
118   bihash_template.c
119   bihash_template.h
120   bihash_vec8_8.h
121   bitmap.h
122   bitops.h
123   byte_order.h
124   cache.h
125   clib_error.h
126   clib.h
127   cpu.h
128   crc32.h
129   dlist.h
130   dlmalloc.h
131   elf_clib.h
132   elf.h
133   elog.h
134   error_bootstrap.h
135   error.h
136   fheap.h
137   fifo.h
138   file.h
139   flowhash_24_16.h
140   flowhash_8_8.h
141   flowhash_template.h
142   format.h
143   graph.h
144   hash.h
145   heap.h
146   lb_hash_hash.h
147   lock.h
148   longjmp.h
149   macros.h
150   maplog.h
151   math.h
152   memcpy_avx2.h
153   memcpy_avx512.h
154   memcpy_sse3.h
155   mem.h
156   mhash.h
157   mheap_bootstrap.h
158   mheap.h
159   os.h
160   pipeline.h
161   pool.h
162   ptclosure.h
163   random_buffer.h
164   random.h
165   random_isaac.h
166   serialize.h
167   slist.h
168   smp.h
169   socket.h
170   sparse_vec.h
171   string.h
172   time.h
173   time_range.h
174   timer.h
175   timing_wheel.h
176   tw_timer_16t_1w_2048sl.h
177   tw_timer_16t_2w_512sl.h
178   tw_timer_1t_3w_1024sl_ov.h
179   tw_timer_2t_1w_2048sl.h
180   tw_timer_4t_3w_256sl.h
181   tw_timer_template.c
182   tw_timer_template.h
183   types.h
184   unix.h
185   valgrind.h
186   valloc.h
187   vec_bootstrap.h
188   vec.h
189   vector_altivec.h
190   vector_avx2.h
191   vector_avx512.h
192   vector_funcs.h
193   vector.h
194   vector_neon.h
195   vector_sse42.h
196   xxhash.h
197   xy.h
198   zvec.h
199   linux/syscall.h
200   linux/sysfs.h
201 )
202
203 option(VPP_BUILD_VPPINFRA_TESTS "Build vppinfra tests." OFF)
204 if(VPP_BUILD_VPPINFRA_TESTS)
205   set(VPPINFRA_TESTS
206     bihash_template
207     bihash_vec88
208     cuckoo_bihash
209     cuckoo_template
210     dlist
211     elf
212     elog
213     fifo
214     flowhash_template
215     format
216     fpool
217     hash
218     heap
219     longjmp
220     macros
221     maplog
222     pool_iterate
223     ptclosure
224     random
225     random_isaac
226     serialize
227     slist
228     socket
229     time
230     time_range
231     timing_wheel
232     tw_timer
233     valloc
234     vec
235     vhash
236     zvec
237   )
238   foreach(test ${VPPINFRA_TESTS})
239     add_executable(test_${test} test_${test}.c)
240     target_link_libraries(test_${test} vppinfra)
241   endforeach()
242
243   target_link_libraries(test_bihash_template Threads::Threads)
244   target_link_libraries(test_cuckoo_bihash Threads::Threads)
245 endif(VPP_BUILD_VPPINFRA_TESTS)