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 | d16004d | 2018-08-26 10:14:52 +0200 | [diff] [blame] | 19 | include(cmake/message.cmake) |
| 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 | 612dd6a | 2018-07-30 12:45:07 +0200 | [diff] [blame] | 36 | # build config |
| 37 | ############################################################################## |
| 38 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) |
| 39 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) |
| 40 | set(CMAKE_C_FLAGS_COMMON "-DFORTIFY_SOURCE=2 -fstack-protector-all -Werror") |
| 41 | set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${CMAKE_C_FLAGS_COMMON} -DCLIB_DEBUG") |
| 42 | set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${CMAKE_C_FLAGS_COMMON}") |
| 43 | |
Damjan Marion | 33ed3e4 | 2018-08-27 15:59:30 +0200 | [diff] [blame] | 44 | check_c_compiler_flag("-Wno-address-of-packed-member" compiler_flag_no_address_of_packed_member) |
| 45 | if (compiler_flag_no_address_of_packed_member) |
| 46 | add_definitions(-Wno-address-of-packed-member) |
| 47 | endif() |
| 48 | |
Damjan Marion | 612dd6a | 2018-07-30 12:45:07 +0200 | [diff] [blame] | 49 | ############################################################################## |
Damjan Marion | 612dd6a | 2018-07-30 12:45:07 +0200 | [diff] [blame] | 50 | # install config |
| 51 | ############################################################################## |
Damjan Marion | 79dcbc7 | 2018-09-12 14:01:10 +0200 | [diff] [blame^] | 52 | set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib") |
Damjan Marion | 612dd6a | 2018-07-30 12:45:07 +0200 | [diff] [blame] | 53 | set(CMAKE_INSTALL_MESSAGE NEVER) |
| 54 | |
Damjan Marion | 612dd6a | 2018-07-30 12:45:07 +0200 | [diff] [blame] | 55 | include_directories ( |
| 56 | ${CMAKE_SOURCE_DIR} |
| 57 | ${CMAKE_BINARY_DIR} |
| 58 | ${CMAKE_BINARY_DIR}/include |
| 59 | ) |
| 60 | set(CMAKE_INSTALL_DEFAULT_COMPONENT_NAME "vpp") |
| 61 | |
| 62 | set(THREADS_PREFER_PTHREAD_FLAG ON) |
| 63 | find_package(Threads REQUIRED) |
Damjan Marion | 612dd6a | 2018-07-30 12:45:07 +0200 | [diff] [blame] | 64 | |
Damjan Marion | d16004d | 2018-08-26 10:14:52 +0200 | [diff] [blame] | 65 | include(cmake/memfd.cmake) |
| 66 | include(cmake/api.cmake) |
Damjan Marion | 4553c95 | 2018-08-26 11:04:40 +0200 | [diff] [blame] | 67 | include(cmake/library.cmake) |
| 68 | include(cmake/exec.cmake) |
Damjan Marion | d16004d | 2018-08-26 10:14:52 +0200 | [diff] [blame] | 69 | include(cmake/plugin.cmake) |
Damjan Marion | 612dd6a | 2018-07-30 12:45:07 +0200 | [diff] [blame] | 70 | |
| 71 | ############################################################################## |
Damjan Marion | 0abd4a2 | 2018-08-28 12:57:29 +0200 | [diff] [blame] | 72 | # subdirs - order matters |
Damjan Marion | 612dd6a | 2018-07-30 12:45:07 +0200 | [diff] [blame] | 73 | ############################################################################## |
Damjan Marion | 4dffd1c | 2018-09-03 12:30:36 +0200 | [diff] [blame] | 74 | if("${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) |
| 79 | elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin") |
| 80 | set(SUBDIRS vppinfra) |
| 81 | else() |
| 82 | message(FATAL_ERROR "Unsupported system: ${CMAKE_SYSTEM_NAME}") |
| 83 | endif() |
| 84 | |
| 85 | foreach(DIR ${SUBDIRS}) |
Damjan Marion | 612dd6a | 2018-07-30 12:45:07 +0200 | [diff] [blame] | 86 | add_subdirectory(${DIR}) |
Damjan Marion | 0abd4a2 | 2018-08-28 12:57:29 +0200 | [diff] [blame] | 87 | endforeach() |
Damjan Marion | 612dd6a | 2018-07-30 12:45:07 +0200 | [diff] [blame] | 88 | |
Damjan Marion | 43b0606 | 2018-08-29 22:20:45 +0200 | [diff] [blame] | 89 | include(cmake/pack.cmake) |
Damjan Marion | c6c0246 | 2018-08-31 17:38:57 +0200 | [diff] [blame] | 90 | ############################################################################## |
| 91 | # detect if we are inside git repo and add configure dependency |
| 92 | ############################################################################## |
| 93 | execute_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 | |
| 100 | if (VPP_GIT_TOPLEVEL_DIR) |
| 101 | set_property( |
| 102 | DIRECTORY APPEND PROPERTY |
| 103 | CMAKE_CONFIGURE_DEPENDS ${VPP_GIT_TOPLEVEL_DIR}/.git/index |
| 104 | ) |
| 105 | endif() |
| 106 | |
| 107 | ############################################################################## |
| 108 | # print configuration |
| 109 | ############################################################################## |
| 110 | message(STATUS "Configuration:") |
| 111 | pr("VPP version" "${VPP_VERSION}") |
| 112 | pr("VPP library version" "${VPP_LIB_VERSION}") |
| 113 | pr("GIT toplevel dir" "${VPP_GIT_TOPLEVEL_DIR}") |
| 114 | pr("C flags" "${CMAKE_C_FLAGS}") |
| 115 | pr("Linker flags" "${CMAKE_LINKER_FLAGS}") |
| 116 | pr("Target processor" "${CMAKE_SYSTEM_PROCESSOR}") |
| 117 | pr("Build type" "${CMAKE_BUILD_TYPE}") |
| 118 | pr("Install prefix" "${CMAKE_INSTALL_PREFIX}") |
Damjan Marion | 855e268 | 2018-08-24 13:37:45 +0200 | [diff] [blame] | 119 | |