Damjan Marion | 612dd6a | 2018-07-30 12:45:07 +0200 | [diff] [blame] | 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) |
Damjan Marion | ff42693 | 2019-01-26 14:12:25 +0100 | [diff] [blame^] | 19 | include(cmake/misc.cmake) |
Damjan Marion | d16004d | 2018-08-26 10:14:52 +0200 | [diff] [blame] | 20 | include(cmake/cpu.cmake) |
| 21 | include(cmake/ccache.cmake) |
Damjan Marion | 612dd6a | 2018-07-30 12:45:07 +0200 | [diff] [blame] | 22 | |
| 23 | ############################################################################## |
Damjan Marion | c6c0246 | 2018-08-31 17:38:57 +0200 | [diff] [blame] | 24 | # VPP Version |
| 25 | ############################################################################## |
| 26 | execute_process( |
| 27 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} |
| 28 | COMMAND scripts/version |
| 29 | OUTPUT_VARIABLE VPP_VERSION |
| 30 | OUTPUT_STRIP_TRAILING_WHITESPACE |
| 31 | ) |
| 32 | string(REPLACE "-" ";" VPP_LIB_VERSION ${VPP_VERSION}) |
| 33 | list(GET VPP_LIB_VERSION 0 VPP_LIB_VERSION) |
| 34 | |
| 35 | ############################################################################## |
Damjan Marion | dd39529 | 2019-01-15 00:36:03 +0100 | [diff] [blame] | 36 | # cross compiling |
| 37 | ############################################################################## |
| 38 | if(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 | ) |
| 43 | endif() |
Damjan Marion | 6491136 | 2019-01-18 17:09:44 +0100 | [diff] [blame] | 44 | set(CMAKE_C_COMPILER_TARGET ${CMAKE_SYSTEM_PROCESSOR}-linux-gnu) |
Damjan Marion | dd39529 | 2019-01-15 00:36:03 +0100 | [diff] [blame] | 45 | |
| 46 | ############################################################################## |
Damjan Marion | 612dd6a | 2018-07-30 12:45:07 +0200 | [diff] [blame] | 47 | # build config |
| 48 | ############################################################################## |
Damjan Marion | 847d528 | 2019-01-17 18:25:11 +0100 | [diff] [blame] | 49 | check_c_compiler_flag("-Wno-address-of-packed-member" |
| 50 | compiler_flag_no_address_of_packed_member) |
| 51 | |
Damjan Marion | 612dd6a | 2018-07-30 12:45:07 +0200 | [diff] [blame] | 52 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) |
| 53 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) |
Damjan Marion | 612dd6a | 2018-07-30 12:45:07 +0200 | [diff] [blame] | 54 | |
Damjan Marion | 847d528 | 2019-01-17 18:25:11 +0100 | [diff] [blame] | 55 | if (CMAKE_BUILD_TYPE) |
| 56 | set(CMAKE_C_FLAGS "-g -fPIC ${CMAKE_C_FLAGS}") |
| 57 | set(CMAKE_C_FLAGS "-fstack-protector-all ${CMAKE_C_FLAGS}") |
| 58 | set(CMAKE_C_FLAGS "-Werror ${CMAKE_C_FLAGS}") |
| 59 | set(CMAKE_C_FLAGS "-DFORTIFY_SOURCE=2 ${CMAKE_C_FLAGS}") |
Damjan Marion | 33ed3e4 | 2018-08-27 15:59:30 +0200 | [diff] [blame] | 60 | endif() |
| 61 | |
Damjan Marion | 847d528 | 2019-01-17 18:25:11 +0100 | [diff] [blame] | 62 | if (compiler_flag_no_address_of_packed_member) |
| 63 | set(CMAKE_C_FLAGS "-Wno-address-of-packed-member ${CMAKE_C_FLAGS}") |
| 64 | endif() |
| 65 | |
| 66 | set(CMAKE_C_FLAGS_RELEASE "-O2 ${CMAKE_C_FLAGS_RELEASE}") |
| 67 | set(CMAKE_C_FLAGS_DEBUG "-O0 -DCLIB_DEBUG ${CMAKE_C_FLAGS_DEBUG}") |
| 68 | set(CMAKE_LINKER_FLAGS_RELEASE "-pie -Wl,-z,now ${CMAKE_LINKER_FLAGS_RELEASE}") |
| 69 | string(TOUPPER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_UC) |
| 70 | |
Damjan Marion | 612dd6a | 2018-07-30 12:45:07 +0200 | [diff] [blame] | 71 | ############################################################################## |
Damjan Marion | 612dd6a | 2018-07-30 12:45:07 +0200 | [diff] [blame] | 72 | # install config |
| 73 | ############################################################################## |
Damjan Marion | 79dcbc7 | 2018-09-12 14:01:10 +0200 | [diff] [blame] | 74 | set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib") |
Damjan Marion | 612dd6a | 2018-07-30 12:45:07 +0200 | [diff] [blame] | 75 | set(CMAKE_INSTALL_MESSAGE NEVER) |
| 76 | |
Damjan Marion | 612dd6a | 2018-07-30 12:45:07 +0200 | [diff] [blame] | 77 | include_directories ( |
| 78 | ${CMAKE_SOURCE_DIR} |
| 79 | ${CMAKE_BINARY_DIR} |
| 80 | ${CMAKE_BINARY_DIR}/include |
| 81 | ) |
| 82 | set(CMAKE_INSTALL_DEFAULT_COMPONENT_NAME "vpp") |
| 83 | |
| 84 | set(THREADS_PREFER_PTHREAD_FLAG ON) |
| 85 | find_package(Threads REQUIRED) |
Damjan Marion | 612dd6a | 2018-07-30 12:45:07 +0200 | [diff] [blame] | 86 | |
Damjan Marion | d16004d | 2018-08-26 10:14:52 +0200 | [diff] [blame] | 87 | include(cmake/memfd.cmake) |
| 88 | include(cmake/api.cmake) |
Damjan Marion | 4553c95 | 2018-08-26 11:04:40 +0200 | [diff] [blame] | 89 | include(cmake/library.cmake) |
| 90 | include(cmake/exec.cmake) |
Damjan Marion | d16004d | 2018-08-26 10:14:52 +0200 | [diff] [blame] | 91 | include(cmake/plugin.cmake) |
Damjan Marion | 612dd6a | 2018-07-30 12:45:07 +0200 | [diff] [blame] | 92 | |
| 93 | ############################################################################## |
Damjan Marion | 0abd4a2 | 2018-08-28 12:57:29 +0200 | [diff] [blame] | 94 | # subdirs - order matters |
Damjan Marion | 612dd6a | 2018-07-30 12:45:07 +0200 | [diff] [blame] | 95 | ############################################################################## |
Damjan Marion | 4dffd1c | 2018-09-03 12:30:36 +0200 | [diff] [blame] | 96 | if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") |
| 97 | find_package(OpenSSL REQUIRED) |
| 98 | set(SUBDIRS |
| 99 | vppinfra svm vlib vlibmemory vlibapi vnet vpp vat vcl plugins |
Damjan Marion | 4d2f86a | 2019-01-18 13:28:22 +0100 | [diff] [blame] | 100 | vpp-api tools/vppapigen tools/g2 tools/elftool tools/perftool cmake pkg |
Damjan Marion | 0fa900e | 2018-09-12 12:12:36 +0200 | [diff] [blame] | 101 | ) |
Damjan Marion | 4dffd1c | 2018-09-03 12:30:36 +0200 | [diff] [blame] | 102 | elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin") |
| 103 | set(SUBDIRS vppinfra) |
| 104 | else() |
| 105 | message(FATAL_ERROR "Unsupported system: ${CMAKE_SYSTEM_NAME}") |
| 106 | endif() |
| 107 | |
| 108 | foreach(DIR ${SUBDIRS}) |
Damjan Marion | 612dd6a | 2018-07-30 12:45:07 +0200 | [diff] [blame] | 109 | add_subdirectory(${DIR}) |
Damjan Marion | 0abd4a2 | 2018-08-28 12:57:29 +0200 | [diff] [blame] | 110 | endforeach() |
Damjan Marion | 612dd6a | 2018-07-30 12:45:07 +0200 | [diff] [blame] | 111 | |
Damjan Marion | eeadc14 | 2018-09-13 20:02:12 +0200 | [diff] [blame] | 112 | ############################################################################## |
| 113 | # packaging |
| 114 | ############################################################################## |
Damjan Marion | 43b0606 | 2018-08-29 22:20:45 +0200 | [diff] [blame] | 115 | include(cmake/pack.cmake) |
Damjan Marion | eeadc14 | 2018-09-13 20:02:12 +0200 | [diff] [blame] | 116 | add_vpp_packaging( |
| 117 | NAME "vpp" |
| 118 | VENDOR "fd.io" |
| 119 | DESCRIPTION "Vector Packet Processor" |
| 120 | ) |
| 121 | |
Damjan Marion | c6c0246 | 2018-08-31 17:38:57 +0200 | [diff] [blame] | 122 | ############################################################################## |
| 123 | # detect if we are inside git repo and add configure dependency |
| 124 | ############################################################################## |
| 125 | execute_process( |
| 126 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} |
| 127 | COMMAND git rev-parse --show-toplevel |
| 128 | OUTPUT_VARIABLE VPP_GIT_TOPLEVEL_DIR |
| 129 | OUTPUT_STRIP_TRAILING_WHITESPACE |
| 130 | ) |
| 131 | |
| 132 | if (VPP_GIT_TOPLEVEL_DIR) |
| 133 | set_property( |
| 134 | DIRECTORY APPEND PROPERTY |
| 135 | CMAKE_CONFIGURE_DEPENDS ${VPP_GIT_TOPLEVEL_DIR}/.git/index |
| 136 | ) |
| 137 | endif() |
| 138 | |
| 139 | ############################################################################## |
| 140 | # print configuration |
| 141 | ############################################################################## |
| 142 | message(STATUS "Configuration:") |
| 143 | pr("VPP version" "${VPP_VERSION}") |
| 144 | pr("VPP library version" "${VPP_LIB_VERSION}") |
| 145 | pr("GIT toplevel dir" "${VPP_GIT_TOPLEVEL_DIR}") |
Damjan Marion | 847d528 | 2019-01-17 18:25:11 +0100 | [diff] [blame] | 146 | pr("Build type" "${CMAKE_BUILD_TYPE}") |
| 147 | pr("C flags" "${CMAKE_C_FLAGS}${CMAKE_C_FLAGS_${CMAKE_BUILD_TYPE_UC}}") |
| 148 | pr("Linker flags" "${CMAKE_LINKER_FLAGS}${CMAKE_LINKER_FLAGS_${CMAKE_BUILD_TYPE_UC}}") |
Damjan Marion | dd39529 | 2019-01-15 00:36:03 +0100 | [diff] [blame] | 149 | pr("Host processor" "${CMAKE_HOST_SYSTEM_PROCESSOR}") |
Damjan Marion | c6c0246 | 2018-08-31 17:38:57 +0200 | [diff] [blame] | 150 | pr("Target processor" "${CMAKE_SYSTEM_PROCESSOR}") |
Damjan Marion | 4a6cb83 | 2018-09-18 18:41:38 +0200 | [diff] [blame] | 151 | pr("Prefix path" "${CMAKE_PREFIX_PATH}") |
Damjan Marion | c6c0246 | 2018-08-31 17:38:57 +0200 | [diff] [blame] | 152 | pr("Install prefix" "${CMAKE_INSTALL_PREFIX}") |
Damjan Marion | 855e268 | 2018-08-24 13:37:45 +0200 | [diff] [blame] | 153 | |