42e3a1cbf7492f05d6404299a91396aec4c5221a
[vpp.git] / src / 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 cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
15
16 project(vpp C)
17
18 include(CheckCCompilerFlag)
19
20 include(cmake/message.cmake)
21 include(cmake/cpu.cmake)
22 include(cmake/ccache.cmake)
23
24 ##############################################################################
25 # build config
26 ##############################################################################
27 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
28 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
29 set(CMAKE_C_FLAGS_COMMON "-DFORTIFY_SOURCE=2 -fstack-protector-all -Werror")
30 set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${CMAKE_C_FLAGS_COMMON} -DCLIB_DEBUG")
31 set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${CMAKE_C_FLAGS_COMMON}")
32
33 check_c_compiler_flag("-Wno-address-of-packed-member" compiler_flag_no_address_of_packed_member)
34 if (compiler_flag_no_address_of_packed_member)
35   add_definitions(-Wno-address-of-packed-member)
36 endif()
37
38 ##############################################################################
39 # install config
40 ##############################################################################
41 set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${VPP_LIB_DIR_NAME}")
42 set(CMAKE_INSTALL_MESSAGE NEVER)
43
44 message(STATUS "CMAKE_C_FLAGS: ${CMAKE_C_FLAGS}")
45 message(STATUS "We are on a ${CMAKE_SYSTEM_NAME} system")
46 message(STATUS "The host processor is ${CMAKE_HOST_SYSTEM_PROCESSOR}")
47
48 include_directories (
49         ${CMAKE_SOURCE_DIR}
50         ${CMAKE_BINARY_DIR}
51         ${CMAKE_BINARY_DIR}/include
52 )
53 set(CMAKE_INSTALL_DEFAULT_COMPONENT_NAME "vpp")
54
55 set(THREADS_PREFER_PTHREAD_FLAG ON)
56 find_package(Threads REQUIRED)
57 find_package(OpenSSL REQUIRED)
58
59 include(cmake/memfd.cmake)
60 include(cmake/api.cmake)
61 include(cmake/library.cmake)
62 include(cmake/exec.cmake)
63 include(cmake/plugin.cmake)
64 include(cmake/deb.cmake)
65
66 ##############################################################################
67 # subdirs - order matters
68 ##############################################################################
69 foreach(
70   DIR
71   vppinfra svm vlib vlibmemory vlibapi vnet vpp vat vcl plugins
72   vpp-api tools/vppapigen
73 )
74   add_subdirectory(${DIR})
75 endforeach()
76