blob: 11f2be90d9f6d83d28f59132c89a232d186fb225 [file] [log] [blame]
Damjan Marion612dd6a2018-07-30 12:45:07 +02001# 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
14cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
15
16project(vpp C)
17
18include(CheckCCompilerFlag)
Damjan Mariond16004d2018-08-26 10:14:52 +020019include(cmake/message.cmake)
20include(cmake/cpu.cmake)
21include(cmake/ccache.cmake)
Damjan Marion612dd6a2018-07-30 12:45:07 +020022
23##############################################################################
Damjan Marionc6c02462018-08-31 17:38:57 +020024# VPP Version
25##############################################################################
26execute_process(
27 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
28 COMMAND scripts/version
29 OUTPUT_VARIABLE VPP_VERSION
30 OUTPUT_STRIP_TRAILING_WHITESPACE
31)
32string(REPLACE "-" ";" VPP_LIB_VERSION ${VPP_VERSION})
33list(GET VPP_LIB_VERSION 0 VPP_LIB_VERSION)
34
35##############################################################################
Damjan Marion612dd6a2018-07-30 12:45:07 +020036# build config
37##############################################################################
38set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
39set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
40set(CMAKE_C_FLAGS_COMMON "-DFORTIFY_SOURCE=2 -fstack-protector-all -Werror")
41set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${CMAKE_C_FLAGS_COMMON} -DCLIB_DEBUG")
42set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${CMAKE_C_FLAGS_COMMON}")
43
Damjan Marion33ed3e42018-08-27 15:59:30 +020044check_c_compiler_flag("-Wno-address-of-packed-member" compiler_flag_no_address_of_packed_member)
45if (compiler_flag_no_address_of_packed_member)
46 add_definitions(-Wno-address-of-packed-member)
47endif()
48
Damjan Marion612dd6a2018-07-30 12:45:07 +020049##############################################################################
Damjan Marion612dd6a2018-07-30 12:45:07 +020050# install config
51##############################################################################
Neale Ranns917dc3b2018-08-27 08:35:25 -040052set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${VPP_LIB_DIR_NAME}")
Damjan Marion612dd6a2018-07-30 12:45:07 +020053set(CMAKE_INSTALL_MESSAGE NEVER)
54
Damjan Marion612dd6a2018-07-30 12:45:07 +020055include_directories (
56 ${CMAKE_SOURCE_DIR}
57 ${CMAKE_BINARY_DIR}
58 ${CMAKE_BINARY_DIR}/include
59)
60set(CMAKE_INSTALL_DEFAULT_COMPONENT_NAME "vpp")
61
62set(THREADS_PREFER_PTHREAD_FLAG ON)
63find_package(Threads REQUIRED)
64find_package(OpenSSL REQUIRED)
Damjan Marion612dd6a2018-07-30 12:45:07 +020065
Damjan Mariond16004d2018-08-26 10:14:52 +020066include(cmake/memfd.cmake)
67include(cmake/api.cmake)
Damjan Marion4553c952018-08-26 11:04:40 +020068include(cmake/library.cmake)
69include(cmake/exec.cmake)
Damjan Mariond16004d2018-08-26 10:14:52 +020070include(cmake/plugin.cmake)
Damjan Marion612dd6a2018-07-30 12:45:07 +020071
72##############################################################################
Damjan Marion0abd4a22018-08-28 12:57:29 +020073# subdirs - order matters
Damjan Marion612dd6a2018-07-30 12:45:07 +020074##############################################################################
Damjan Marion0abd4a22018-08-28 12:57:29 +020075foreach(
76 DIR
77 vppinfra svm vlib vlibmemory vlibapi vnet vpp vat vcl plugins
Mohsin Kazmie04ffa42018-08-28 11:58:20 +020078 vpp-api tools/vppapigen tools/g2 tools/elftool tools/perftool
Damjan Marion0abd4a22018-08-28 12:57:29 +020079)
Damjan Marion612dd6a2018-07-30 12:45:07 +020080 add_subdirectory(${DIR})
Damjan Marion0abd4a22018-08-28 12:57:29 +020081endforeach()
Damjan Marion612dd6a2018-07-30 12:45:07 +020082
Damjan Marion43b06062018-08-29 22:20:45 +020083include(cmake/pack.cmake)
Damjan Marionc6c02462018-08-31 17:38:57 +020084##############################################################################
85# detect if we are inside git repo and add configure dependency
86##############################################################################
87execute_process(
88 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
89 COMMAND git rev-parse --show-toplevel
90 OUTPUT_VARIABLE VPP_GIT_TOPLEVEL_DIR
91 OUTPUT_STRIP_TRAILING_WHITESPACE
92)
93
94if (VPP_GIT_TOPLEVEL_DIR)
95 set_property(
96 DIRECTORY APPEND PROPERTY
97 CMAKE_CONFIGURE_DEPENDS ${VPP_GIT_TOPLEVEL_DIR}/.git/index
98 )
99endif()
100
101##############################################################################
102# print configuration
103##############################################################################
104message(STATUS "Configuration:")
105pr("VPP version" "${VPP_VERSION}")
106pr("VPP library version" "${VPP_LIB_VERSION}")
107pr("GIT toplevel dir" "${VPP_GIT_TOPLEVEL_DIR}")
108pr("C flags" "${CMAKE_C_FLAGS}")
109pr("Linker flags" "${CMAKE_LINKER_FLAGS}")
110pr("Target processor" "${CMAKE_SYSTEM_PROCESSOR}")
111pr("Build type" "${CMAKE_BUILD_TYPE}")
112pr("Install prefix" "${CMAKE_INSTALL_PREFIX}")
Damjan Marion855e2682018-08-24 13:37:45 +0200113