blob: b8ffc0783db4a91b4c4e358e60da6be388621981 [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 Marionff426932019-01-26 14:12:25 +010019include(cmake/misc.cmake)
Damjan Mariond16004d2018-08-26 10:14:52 +020020include(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 Mariondd395292019-01-15 00:36:03 +010036# cross compiling
37##############################################################################
38if(CMAKE_CROSSCOMPILING)
39 set(CMAKE_IGNORE_PATH
40 /usr/lib/${CMAKE_HOST_SYSTEM_PROCESSOR}-linux-gnu/
41 /usr/lib/${CMAKE_HOST_SYSTEM_PROCESSOR}-linux-gnu/lib/
42 )
43endif()
Damjan Marion64911362019-01-18 17:09:44 +010044set(CMAKE_C_COMPILER_TARGET ${CMAKE_SYSTEM_PROCESSOR}-linux-gnu)
Damjan Mariondd395292019-01-15 00:36:03 +010045
46##############################################################################
Damjan Marion612dd6a2018-07-30 12:45:07 +020047# build config
48##############################################################################
Damjan Marion847d5282019-01-17 18:25:11 +010049check_c_compiler_flag("-Wno-address-of-packed-member"
50 compiler_flag_no_address_of_packed_member)
51
Damjan Marion612dd6a2018-07-30 12:45:07 +020052set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
53set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
Damjan Marion612dd6a2018-07-30 12:45:07 +020054
Damjan Marion847d5282019-01-17 18:25:11 +010055if (CMAKE_BUILD_TYPE)
Damjan Marion2baa1152019-11-07 11:32:16 +010056 set(CMAKE_C_FLAGS "-g -fPIC -Werror -Wall ${CMAKE_C_FLAGS}")
Damjan Marion33ed3e42018-08-27 15:59:30 +020057endif()
58
Damjan Marion847d5282019-01-17 18:25:11 +010059if (compiler_flag_no_address_of_packed_member)
60 set(CMAKE_C_FLAGS "-Wno-address-of-packed-member ${CMAKE_C_FLAGS}")
61endif()
62
Damjan Marion2baa1152019-11-07 11:32:16 +010063# release
64string(CONCAT CMAKE_C_FLAGS_RELEASE
65 "-O2 "
66 "-fstack-protector "
67 "-DFORTIFY_SOURCE=2 "
68 "-fno-common "
69)
70
71string(CONCAT CMAKE_EXE_LINKER_FLAGS_RELEASE "-pie")
72
73# debug
74string(CONCAT CMAKE_C_FLAGS_DEBUG
75 "-O0 "
76 "-DCLIB_DEBUG "
77 "-fstack-protector "
78 "-DFORTIFY_SOURCE=2 "
79 "-fno-common "
80)
81
82# coverity
83string(CONCAT CMAKE_C_FLAGS_COVERITY "-O2 -D__COVERITY__")
84
85# gcov
86string(CONCAT CMAKE_C_FLAGS_GCOV
87 "-O0 "
88 "-DCLIB_DEBUG "
89 "-DCLIB_GCOV "
90 "-fprofile-arcs "
91 "-ftest-coverage ")
92
Damjan Marion847d5282019-01-17 18:25:11 +010093string(TOUPPER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_UC)
94
Damjan Marion612dd6a2018-07-30 12:45:07 +020095##############################################################################
Damjan Marion612dd6a2018-07-30 12:45:07 +020096# install config
97##############################################################################
Damjan Marion79dcbc72018-09-12 14:01:10 +020098set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
Damjan Marion612dd6a2018-07-30 12:45:07 +020099set(CMAKE_INSTALL_MESSAGE NEVER)
100
Damjan Marion612dd6a2018-07-30 12:45:07 +0200101include_directories (
102 ${CMAKE_SOURCE_DIR}
103 ${CMAKE_BINARY_DIR}
104 ${CMAKE_BINARY_DIR}/include
105)
106set(CMAKE_INSTALL_DEFAULT_COMPONENT_NAME "vpp")
107
108set(THREADS_PREFER_PTHREAD_FLAG ON)
109find_package(Threads REQUIRED)
Damjan Marion612dd6a2018-07-30 12:45:07 +0200110
Damjan Marion1ee346a2019-03-18 17:06:51 +0100111include(cmake/syscall.cmake)
Damjan Mariond16004d2018-08-26 10:14:52 +0200112include(cmake/api.cmake)
Damjan Marion4553c952018-08-26 11:04:40 +0200113include(cmake/library.cmake)
114include(cmake/exec.cmake)
Damjan Mariond16004d2018-08-26 10:14:52 +0200115include(cmake/plugin.cmake)
Damjan Marion612dd6a2018-07-30 12:45:07 +0200116
117##############################################################################
Damjan Marion0abd4a22018-08-28 12:57:29 +0200118# subdirs - order matters
Damjan Marion612dd6a2018-07-30 12:45:07 +0200119##############################################################################
Damjan Marion4dffd1c2018-09-03 12:30:36 +0200120if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
121 find_package(OpenSSL REQUIRED)
122 set(SUBDIRS
123 vppinfra svm vlib vlibmemory vlibapi vnet vpp vat vcl plugins
Damjan Marion4d2f86a2019-01-18 13:28:22 +0100124 vpp-api tools/vppapigen tools/g2 tools/elftool tools/perftool cmake pkg
Dave Barach0729f642019-03-24 16:25:03 -0400125 tools/appimage
Damjan Marion0fa900e2018-09-12 12:12:36 +0200126 )
Damjan Marion4dffd1c2018-09-03 12:30:36 +0200127elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
128 set(SUBDIRS vppinfra)
129else()
130 message(FATAL_ERROR "Unsupported system: ${CMAKE_SYSTEM_NAME}")
131endif()
132
133foreach(DIR ${SUBDIRS})
Damjan Marion612dd6a2018-07-30 12:45:07 +0200134 add_subdirectory(${DIR})
Damjan Marion0abd4a22018-08-28 12:57:29 +0200135endforeach()
Damjan Marion612dd6a2018-07-30 12:45:07 +0200136
Damjan Marioneeadc142018-09-13 20:02:12 +0200137##############################################################################
Damjan Marionc6c02462018-08-31 17:38:57 +0200138# detect if we are inside git repo and add configure dependency
139##############################################################################
140execute_process(
141 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
142 COMMAND git rev-parse --show-toplevel
143 OUTPUT_VARIABLE VPP_GIT_TOPLEVEL_DIR
144 OUTPUT_STRIP_TRAILING_WHITESPACE
Damjan Marion6077c972019-01-28 17:55:59 +0100145 ERROR_QUIET
Damjan Marionc6c02462018-08-31 17:38:57 +0200146)
147
148if (VPP_GIT_TOPLEVEL_DIR)
149 set_property(
150 DIRECTORY APPEND PROPERTY
151 CMAKE_CONFIGURE_DEPENDS ${VPP_GIT_TOPLEVEL_DIR}/.git/index
152 )
153endif()
154
155##############################################################################
156# print configuration
157##############################################################################
158message(STATUS "Configuration:")
159pr("VPP version" "${VPP_VERSION}")
160pr("VPP library version" "${VPP_LIB_VERSION}")
161pr("GIT toplevel dir" "${VPP_GIT_TOPLEVEL_DIR}")
Damjan Marion847d5282019-01-17 18:25:11 +0100162pr("Build type" "${CMAKE_BUILD_TYPE}")
163pr("C flags" "${CMAKE_C_FLAGS}${CMAKE_C_FLAGS_${CMAKE_BUILD_TYPE_UC}}")
Damjan Marion2baa1152019-11-07 11:32:16 +0100164pr("Linker flags (apps)" "${CMAKE_EXE_LINKER_FLAGS}${CMAKE_EXE_LINKER_FLAGS_${CMAKE_BUILD_TYPE_UC}}")
165pr("Linker flags (libs)" "${CMAKE_SHARED_LINKER_FLAGS}${CMAKE_SHARED_LINKER_FLAGS_${CMAKE_BUILD_TYPE_UC}}")
Damjan Mariondd395292019-01-15 00:36:03 +0100166pr("Host processor" "${CMAKE_HOST_SYSTEM_PROCESSOR}")
Damjan Marionc6c02462018-08-31 17:38:57 +0200167pr("Target processor" "${CMAKE_SYSTEM_PROCESSOR}")
Damjan Marion4a6cb832018-09-18 18:41:38 +0200168pr("Prefix path" "${CMAKE_PREFIX_PATH}")
Damjan Marionc6c02462018-08-31 17:38:57 +0200169pr("Install prefix" "${CMAKE_INSTALL_PREFIX}")