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