blob: 53cb185f1aef544b7d7155d34a14f425727ee8ce [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)
Damjan Marion612dd6a2018-07-30 12:45:07 +020064
Damjan Mariond16004d2018-08-26 10:14:52 +020065include(cmake/memfd.cmake)
66include(cmake/api.cmake)
Damjan Marion4553c952018-08-26 11:04:40 +020067include(cmake/library.cmake)
68include(cmake/exec.cmake)
Damjan Mariond16004d2018-08-26 10:14:52 +020069include(cmake/plugin.cmake)
Damjan Marion612dd6a2018-07-30 12:45:07 +020070
71##############################################################################
Damjan Marion0abd4a22018-08-28 12:57:29 +020072# subdirs - order matters
Damjan Marion612dd6a2018-07-30 12:45:07 +020073##############################################################################
Damjan Marion4dffd1c2018-09-03 12:30:36 +020074if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
75 find_package(OpenSSL REQUIRED)
76 set(SUBDIRS
77 vppinfra svm vlib vlibmemory vlibapi vnet vpp vat vcl plugins
78 vpp-api tools/vppapigen tools/g2 tools/elftool tools/perftool)
79elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
80 set(SUBDIRS vppinfra)
81else()
82 message(FATAL_ERROR "Unsupported system: ${CMAKE_SYSTEM_NAME}")
83endif()
84
85foreach(DIR ${SUBDIRS})
Damjan Marion612dd6a2018-07-30 12:45:07 +020086 add_subdirectory(${DIR})
Damjan Marion0abd4a22018-08-28 12:57:29 +020087endforeach()
Damjan Marion612dd6a2018-07-30 12:45:07 +020088
Damjan Marion43b06062018-08-29 22:20:45 +020089include(cmake/pack.cmake)
Damjan Marionc6c02462018-08-31 17:38:57 +020090##############################################################################
91# detect if we are inside git repo and add configure dependency
92##############################################################################
93execute_process(
94 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
95 COMMAND git rev-parse --show-toplevel
96 OUTPUT_VARIABLE VPP_GIT_TOPLEVEL_DIR
97 OUTPUT_STRIP_TRAILING_WHITESPACE
98)
99
100if (VPP_GIT_TOPLEVEL_DIR)
101 set_property(
102 DIRECTORY APPEND PROPERTY
103 CMAKE_CONFIGURE_DEPENDS ${VPP_GIT_TOPLEVEL_DIR}/.git/index
104 )
105endif()
106
107##############################################################################
108# print configuration
109##############################################################################
110message(STATUS "Configuration:")
111pr("VPP version" "${VPP_VERSION}")
112pr("VPP library version" "${VPP_LIB_VERSION}")
113pr("GIT toplevel dir" "${VPP_GIT_TOPLEVEL_DIR}")
114pr("C flags" "${CMAKE_C_FLAGS}")
115pr("Linker flags" "${CMAKE_LINKER_FLAGS}")
116pr("Target processor" "${CMAKE_SYSTEM_PROCESSOR}")
117pr("Build type" "${CMAKE_BUILD_TYPE}")
118pr("Install prefix" "${CMAKE_INSTALL_PREFIX}")
Damjan Marion855e2682018-08-24 13:37:45 +0200119