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 | |
Damjan Marion | c30f300 | 2021-12-02 14:03:02 +0100 | [diff] [blame] | 14 | cmake_minimum_required(VERSION 3.13) |
Damjan Marion | 612dd6a | 2018-07-30 12:45:07 +0200 | [diff] [blame] | 15 | |
Damjan Marion | 01fe7ab | 2023-10-23 18:36:18 +0200 | [diff] [blame] | 16 | if(DEFINED VPP_PLATFORM AND VPP_PLATFORM STREQUAL "default") |
| 17 | unset(VPP_PLATFORM) |
BenoƮt Ganne | 9705d84 | 2024-01-19 17:43:44 +0100 | [diff] [blame] | 18 | unset(VPP_PLATFORM CACHE) |
Damjan Marion | 01fe7ab | 2023-10-23 18:36:18 +0200 | [diff] [blame] | 19 | set(VPP_PLATFORM_NAME "default") |
| 20 | elseif(DEFINED VPP_PLATFORM) |
| 21 | set(platform_file ${CMAKE_SOURCE_DIR}/cmake/platform/${VPP_PLATFORM}.cmake) |
| 22 | if(NOT EXISTS ${platform_file}) |
| 23 | message(FATAL_ERROR "unknown platform ${VPP_PLATFORM}") |
| 24 | endif() |
| 25 | include(${platform_file}) |
| 26 | set(VPP_PLATFORM_NAME ${VPP_PLATFORM}) |
| 27 | else() |
| 28 | set(VPP_PLATFORM_NAME "default") |
| 29 | endif() |
| 30 | |
| 31 | if (DEFINED VPP_PLATFORM_C_COMPILER_NAMES) |
| 32 | set(CMAKE_C_COMPILER_NAMES ${VPP_PLATFORM_C_COMPILER_NAME}) |
| 33 | else() |
| 34 | set(CMAKE_C_COMPILER_NAMES clang gcc cc) |
| 35 | endif() |
Damjan Marion | 4ba16a4 | 2020-04-28 13:29:37 +0200 | [diff] [blame] | 36 | |
Damjan Marion | 612dd6a | 2018-07-30 12:45:07 +0200 | [diff] [blame] | 37 | project(vpp C) |
| 38 | |
Damjan Marion | 5546e43 | 2021-09-30 20:04:14 +0200 | [diff] [blame] | 39 | if(NOT DEFINED CMAKE_INSTALL_LIBDIR AND EXISTS "/etc/debian_version") |
| 40 | set(CMAKE_INSTALL_LIBDIR "lib/${CMAKE_LIBRARY_ARCHITECTURE}") |
| 41 | endif() |
| 42 | |
Damjan Marion | 612dd6a | 2018-07-30 12:45:07 +0200 | [diff] [blame] | 43 | include(CheckCCompilerFlag) |
Damjan Marion | af7892c | 2020-10-22 14:23:47 +0200 | [diff] [blame] | 44 | include(CheckIPOSupported) |
Nick Brown | e3cf4d0 | 2021-09-15 14:25:40 +0100 | [diff] [blame] | 45 | include(GNUInstallDirs) |
Damjan Marion | ff42693 | 2019-01-26 14:12:25 +0100 | [diff] [blame] | 46 | include(cmake/misc.cmake) |
Damjan Marion | d16004d | 2018-08-26 10:14:52 +0200 | [diff] [blame] | 47 | include(cmake/cpu.cmake) |
| 48 | include(cmake/ccache.cmake) |
Damjan Marion | 612dd6a | 2018-07-30 12:45:07 +0200 | [diff] [blame] | 49 | |
| 50 | ############################################################################## |
Damjan Marion | c6c0246 | 2018-08-31 17:38:57 +0200 | [diff] [blame] | 51 | # VPP Version |
| 52 | ############################################################################## |
| 53 | execute_process( |
| 54 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} |
| 55 | COMMAND scripts/version |
| 56 | OUTPUT_VARIABLE VPP_VERSION |
| 57 | OUTPUT_STRIP_TRAILING_WHITESPACE |
| 58 | ) |
Damjan Marion | 01fe7ab | 2023-10-23 18:36:18 +0200 | [diff] [blame] | 59 | |
| 60 | if (VPP_PLATFORM) |
| 61 | set(VPP_VERSION ${VPP_VERSION}-${VPP_PLATFORM_NAME}) |
| 62 | endif() |
| 63 | |
Damjan Marion | c6c0246 | 2018-08-31 17:38:57 +0200 | [diff] [blame] | 64 | string(REPLACE "-" ";" VPP_LIB_VERSION ${VPP_VERSION}) |
| 65 | list(GET VPP_LIB_VERSION 0 VPP_LIB_VERSION) |
| 66 | |
| 67 | ############################################################################## |
Damjan Marion | 8cb5d36 | 2022-04-14 22:18:19 +0200 | [diff] [blame] | 68 | # compiler specifics |
| 69 | ############################################################################## |
| 70 | |
| 71 | set(MIN_SUPPORTED_CLANG_C_COMPILER_VERSION 9.0.0) |
| 72 | set(MIN_SUPPORTED_GNU_C_COMPILER_VERSION 9.0.0) |
| 73 | |
| 74 | if(CMAKE_C_COMPILER_ID STREQUAL "Clang") |
| 75 | if (CMAKE_C_COMPILER_VERSION VERSION_LESS MIN_SUPPORTED_CLANG_C_COMPILER_VERSION) |
| 76 | set(COMPILER_TOO_OLD TRUE) |
| 77 | endif() |
| 78 | elseif(CMAKE_C_COMPILER_ID STREQUAL "GNU") |
| 79 | if (CMAKE_C_COMPILER_VERSION VERSION_LESS MIN_SUPPORTED_GNU_C_COMPILER_VERSION) |
| 80 | set(COMPILER_TOO_OLD TRUE) |
| 81 | endif() |
Dave Wallace | 000a4eb | 2022-08-25 17:42:24 -0400 | [diff] [blame] | 82 | set(GCC_STRING_OVERFLOW_WARNING_DISABLE_VERSION 10.0.0) |
| 83 | if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL GCC_STRING_OVERFLOW_WARNING_DISABLE_VERSION) |
| 84 | add_compile_options(-Wno-stringop-overflow) |
| 85 | endif() |
Jieqiang Wang | 92ab407 | 2023-07-24 15:42:22 +0800 | [diff] [blame] | 86 | set(GCC_STRING_OVERREAD_WARNING_DISABLE_VERSION 12.0.0) |
| 87 | if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL GCC_STRING_OVERREAD_WARNING_DISABLE_VERSION) |
| 88 | add_compile_options(-Wno-stringop-overread) |
| 89 | endif() |
| 90 | set(GCC_ARRAY_BOUNDS_WARNING_DISABLE_VERSION 12.0.0) |
| 91 | if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL GCC_ARRAY_BOUNDS_WARNING_DISABLE_VERSION) |
| 92 | add_compile_options(-Wno-array-bounds) |
| 93 | endif() |
Damjan Marion | 8cb5d36 | 2022-04-14 22:18:19 +0200 | [diff] [blame] | 94 | else() |
| 95 | message(WARNING "WARNING: Unsupported C compiler `${CMAKE_C_COMPILER_ID}` is used") |
| 96 | set (PRINT_MIN_C_COMPILER_VER TRUE) |
| 97 | endif() |
| 98 | if (COMPILER_TOO_OLD) |
| 99 | message(WARNING "WARNING: C compiler version is too old and it's usage may result") |
| 100 | message(WARNING " in sub-optimal binaries or lack of support for specific CPU types.") |
| 101 | set (PRINT_MIN_C_COMPILER_VER TRUE) |
| 102 | endif() |
| 103 | |
| 104 | if (PRINT_MIN_C_COMPILER_VER) |
| 105 | string (APPEND _t "Supported C compilers are ") |
| 106 | string (APPEND _t "Clang ${MIN_SUPPORTED_CLANG_C_COMPILER_VERSION} or higher ") |
| 107 | string (APPEND _t "and GNU ${MIN_SUPPORTED_GNU_C_COMPILER_VERSION} or higher.") |
| 108 | message(WARNING " ${_t}") |
| 109 | unset (_t) |
| 110 | endif() |
| 111 | |
| 112 | ############################################################################## |
Damjan Marion | dd39529 | 2019-01-15 00:36:03 +0100 | [diff] [blame] | 113 | # cross compiling |
| 114 | ############################################################################## |
Tom Jones | 2cbbbb6 | 2024-01-24 10:50:14 +0000 | [diff] [blame] | 115 | |
Damjan Marion | dd39529 | 2019-01-15 00:36:03 +0100 | [diff] [blame] | 116 | if(CMAKE_CROSSCOMPILING) |
Renato Botelho do Couto | e69ec9c | 2024-06-20 11:01:40 -0500 | [diff] [blame^] | 117 | if (${CMAKE_SYSTEM_NAME} MATCHES "Linux") |
| 118 | set(COMPILER_SUFFIX "linux-gnu") |
| 119 | elseif (${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD") |
| 120 | set(COMPILER_SUFFIX "freebsd") |
| 121 | endif() |
| 122 | |
Damjan Marion | dd39529 | 2019-01-15 00:36:03 +0100 | [diff] [blame] | 123 | set(CMAKE_IGNORE_PATH |
Tom Jones | 2cbbbb6 | 2024-01-24 10:50:14 +0000 | [diff] [blame] | 124 | /usr/lib/${CMAKE_HOST_SYSTEM_PROCESSOR}-${COMPILER_SUFFIX}/ |
| 125 | /usr/lib/${CMAKE_HOST_SYSTEM_PROCESSOR}-${COMPILER_SUFFIX}/lib/ |
Damjan Marion | dd39529 | 2019-01-15 00:36:03 +0100 | [diff] [blame] | 126 | ) |
Tom Jones | 2cbbbb6 | 2024-01-24 10:50:14 +0000 | [diff] [blame] | 127 | set(CMAKE_C_COMPILER_TARGET ${CMAKE_SYSTEM_PROCESSOR}-${COMPILER_SUFFIX}) |
Renato Botelho do Couto | e69ec9c | 2024-06-20 11:01:40 -0500 | [diff] [blame^] | 128 | endif() |
| 129 | |
Damjan Marion | dd39529 | 2019-01-15 00:36:03 +0100 | [diff] [blame] | 130 | ############################################################################## |
Damjan Marion | 612dd6a | 2018-07-30 12:45:07 +0200 | [diff] [blame] | 131 | # build config |
| 132 | ############################################################################## |
Damjan Marion | 847d528 | 2019-01-17 18:25:11 +0100 | [diff] [blame] | 133 | check_c_compiler_flag("-Wno-address-of-packed-member" |
| 134 | compiler_flag_no_address_of_packed_member) |
Nick Brown | e3cf4d0 | 2021-09-15 14:25:40 +0100 | [diff] [blame] | 135 | set(VPP_RUNTIME_DIR ${CMAKE_INSTALL_BINDIR} CACHE STRING "Relative runtime directory path") |
| 136 | set(VPP_LIBRARY_DIR ${CMAKE_INSTALL_LIBDIR} CACHE STRING "Relative library directory path") |
Damjan Marion | 847d528 | 2019-01-17 18:25:11 +0100 | [diff] [blame] | 137 | |
Damjan Marion | 599efc6 | 2020-05-07 16:49:45 +0200 | [diff] [blame] | 138 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${VPP_RUNTIME_DIR}) |
| 139 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${VPP_LIBRARY_DIR}) |
Damjan Marion | 88b2e36 | 2021-04-29 18:47:25 +0200 | [diff] [blame] | 140 | set(VPP_BINARY_DIR ${CMAKE_BINARY_DIR}/CMakeFiles) |
Damjan Marion | 99704b5 | 2021-12-09 11:34:44 +0100 | [diff] [blame] | 141 | set(PYENV PYTHONPYCACHEPREFIX=${CMAKE_BINARY_DIR}/CMakeFiles/__pycache__) |
Damjan Marion | 612dd6a | 2018-07-30 12:45:07 +0200 | [diff] [blame] | 142 | |
Damjan Marion | 847d528 | 2019-01-17 18:25:11 +0100 | [diff] [blame] | 143 | if (CMAKE_BUILD_TYPE) |
Damjan Marion | 9c412e9 | 2021-12-03 14:07:41 +0100 | [diff] [blame] | 144 | add_compile_options(-g -Werror -Wall) |
Damjan Marion | 33ed3e4 | 2018-08-27 15:59:30 +0200 | [diff] [blame] | 145 | endif() |
| 146 | |
Damjan Marion | 847d528 | 2019-01-17 18:25:11 +0100 | [diff] [blame] | 147 | if (compiler_flag_no_address_of_packed_member) |
Damjan Marion | 0d39cba | 2021-05-10 14:51:44 +0200 | [diff] [blame] | 148 | add_compile_options(-Wno-address-of-packed-member) |
Damjan Marion | 847d528 | 2019-01-17 18:25:11 +0100 | [diff] [blame] | 149 | endif() |
| 150 | |
Damjan Marion | 0d39cba | 2021-05-10 14:51:44 +0200 | [diff] [blame] | 151 | string(TOLOWER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_LC) |
Damjan Marion | 847d528 | 2019-01-17 18:25:11 +0100 | [diff] [blame] | 152 | string(TOUPPER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_UC) |
| 153 | |
Damjan Marion | 0d39cba | 2021-05-10 14:51:44 +0200 | [diff] [blame] | 154 | set(CMAKE_C_FLAGS_RELEASE "") |
| 155 | set(CMAKE_C_FLAGS_DEBUG "") |
Damjan Marion | 952a7b8 | 2019-11-19 17:58:36 +0100 | [diff] [blame] | 156 | |
Damjan Marion | 0d39cba | 2021-05-10 14:51:44 +0200 | [diff] [blame] | 157 | if (${CMAKE_BUILD_TYPE_LC} MATCHES "release") |
| 158 | add_compile_options(-O3 -fstack-protector -fno-common) |
| 159 | add_compile_definitions(_FORTIFY_SOURCE=2) |
Damjan Marion | 0d39cba | 2021-05-10 14:51:44 +0200 | [diff] [blame] | 160 | elseif (${CMAKE_BUILD_TYPE_LC} MATCHES "debug") |
| 161 | add_compile_options(-O0 -fstack-protector -fno-common) |
| 162 | add_compile_definitions(CLIB_DEBUG) |
| 163 | elseif (${CMAKE_BUILD_TYPE_LC} MATCHES "coverity") |
| 164 | add_compile_options(-O0) |
| 165 | add_compile_definitions(__COVERITY__) |
| 166 | elseif (${CMAKE_BUILD_TYPE_LC} MATCHES "gcov") |
| 167 | add_compile_options(-O0 -fprofile-arcs -ftest-coverage) |
| 168 | add_compile_definitions(CLIB_DEBUG CLIB_GCOV) |
Dave Wallace | 1c95e12 | 2023-06-21 23:14:38 -0400 | [diff] [blame] | 169 | link_libraries(gcov) |
Damjan Marion | 0d39cba | 2021-05-10 14:51:44 +0200 | [diff] [blame] | 170 | endif() |
| 171 | |
| 172 | set(BUILD_TYPES release debug coverity gcov) |
Damjan Marion | 3a533cd | 2021-05-03 12:40:27 +0200 | [diff] [blame] | 173 | string(REPLACE ";" " " BUILD_TYPES_STR "${BUILD_TYPES}") |
Damjan Marion | 952a7b8 | 2019-11-19 17:58:36 +0100 | [diff] [blame] | 174 | set_property(CACHE CMAKE_BUILD_TYPE PROPERTY |
Damjan Marion | 3a533cd | 2021-05-03 12:40:27 +0200 | [diff] [blame] | 175 | HELPSTRING "Build type - valid options are: ${BUILD_TYPES_STR}") |
Damjan Marion | 952a7b8 | 2019-11-19 17:58:36 +0100 | [diff] [blame] | 176 | |
Damjan Marion | 612dd6a | 2018-07-30 12:45:07 +0200 | [diff] [blame] | 177 | ############################################################################## |
Damjan Marion | af7892c | 2020-10-22 14:23:47 +0200 | [diff] [blame] | 178 | # link time optimizations |
| 179 | ############################################################################## |
| 180 | if (CMAKE_BUILD_TYPE_UC STREQUAL "RELEASE") |
| 181 | check_ipo_supported(RESULT _result) |
| 182 | if (_result) |
| 183 | option(VPP_USE_LTO "Link time optimization of release binaries" ON) |
| 184 | endif() |
| 185 | endif() |
| 186 | |
Damjan Marion | 1e26724 | 2021-11-06 17:09:37 +0100 | [diff] [blame] | 187 | if(VPP_USE_LTO) |
| 188 | check_c_compiler_flag("-Wno-stringop-overflow" |
| 189 | compiler_flag_no_stringop_overflow) |
| 190 | endif() |
Damjan Marion | af7892c | 2020-10-22 14:23:47 +0200 | [diff] [blame] | 191 | ############################################################################## |
BenoƮt Ganne | 9fb6d40 | 2019-04-15 15:28:21 +0200 | [diff] [blame] | 192 | # sanitizers |
| 193 | ############################################################################## |
| 194 | |
Damjan Marion | 599efc6 | 2020-05-07 16:49:45 +0200 | [diff] [blame] | 195 | option(VPP_ENABLE_SANITIZE_ADDR "Enable Address Sanitizer" OFF) |
BenoƮt Ganne | 173484f | 2020-06-16 12:05:07 +0200 | [diff] [blame] | 196 | set(VPP_SANITIZE_ADDR_OPTIONS |
Damjan Marion | ec3a3f1 | 2020-05-21 19:09:13 +0200 | [diff] [blame] | 197 | "unmap_shadow_on_exit=1:disable_coredump=0:abort_on_error=1:detect_leaks=0" |
| 198 | CACHE |
| 199 | STRING "Address sanitizer arguments" |
| 200 | ) |
| 201 | |
Damjan Marion | 599efc6 | 2020-05-07 16:49:45 +0200 | [diff] [blame] | 202 | if (VPP_ENABLE_SANITIZE_ADDR) |
Damjan Marion | 0d39cba | 2021-05-10 14:51:44 +0200 | [diff] [blame] | 203 | add_compile_options(-fsanitize=address) |
Damjan Marion | c30f300 | 2021-12-02 14:03:02 +0100 | [diff] [blame] | 204 | add_link_options(-fsanitize=address) |
Damjan Marion | 599efc6 | 2020-05-07 16:49:45 +0200 | [diff] [blame] | 205 | endif (VPP_ENABLE_SANITIZE_ADDR) |
BenoƮt Ganne | 9fb6d40 | 2019-04-15 15:28:21 +0200 | [diff] [blame] | 206 | |
| 207 | ############################################################################## |
BenoƮt Ganne | f89bbbe | 2021-03-04 14:31:03 +0100 | [diff] [blame] | 208 | # trajectory trace |
| 209 | ############################################################################## |
| 210 | |
| 211 | option(VPP_ENABLE_TRAJECTORY_TRACE "Build vpp with trajectory tracing enabled" OFF) |
| 212 | if(VPP_ENABLE_TRAJECTORY_TRACE) |
Damjan Marion | 0d39cba | 2021-05-10 14:51:44 +0200 | [diff] [blame] | 213 | add_compile_definitions(VLIB_BUFFER_TRACE_TRAJECTORY=1) |
BenoƮt Ganne | f89bbbe | 2021-03-04 14:31:03 +0100 | [diff] [blame] | 214 | endif() |
| 215 | |
| 216 | ############################################################################## |
Damjan Marion | 01fe7ab | 2023-10-23 18:36:18 +0200 | [diff] [blame] | 217 | # unittest with clang code coverage |
Ole Troan | 9432340 | 2021-11-11 19:22:12 +0100 | [diff] [blame] | 218 | ############################################################################## |
| 219 | |
| 220 | if("${CMAKE_VERSION}" VERSION_GREATER_EQUAL "3.13" AND "${CMAKE_C_COMPILER_ID}" MATCHES "(Apple)?[Cc]lang") |
| 221 | option(VPP_BUILD_TESTS_WITH_COVERAGE "Build unit tests with code coverage" OFF) |
| 222 | endif() |
| 223 | |
| 224 | ############################################################################## |
Damjan Marion | 612dd6a | 2018-07-30 12:45:07 +0200 | [diff] [blame] | 225 | # install config |
| 226 | ############################################################################## |
Nathan Moos | 2c91922 | 2021-01-15 13:28:34 -0800 | [diff] [blame] | 227 | option(VPP_SET_RPATH "Set rpath for resulting binaries and libraries." ON) |
| 228 | if(VPP_SET_RPATH) |
Damjan Marion | 5546e43 | 2021-09-30 20:04:14 +0200 | [diff] [blame] | 229 | set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${VPP_LIBRARY_DIR}") |
Nathan Moos | 2c91922 | 2021-01-15 13:28:34 -0800 | [diff] [blame] | 230 | endif() |
Damjan Marion | 612dd6a | 2018-07-30 12:45:07 +0200 | [diff] [blame] | 231 | set(CMAKE_INSTALL_MESSAGE NEVER) |
| 232 | |
Damjan Marion | 612dd6a | 2018-07-30 12:45:07 +0200 | [diff] [blame] | 233 | include_directories ( |
| 234 | ${CMAKE_SOURCE_DIR} |
Damjan Marion | 88b2e36 | 2021-04-29 18:47:25 +0200 | [diff] [blame] | 235 | ${VPP_BINARY_DIR} |
Damjan Marion | 612dd6a | 2018-07-30 12:45:07 +0200 | [diff] [blame] | 236 | ) |
| 237 | set(CMAKE_INSTALL_DEFAULT_COMPONENT_NAME "vpp") |
| 238 | |
| 239 | set(THREADS_PREFER_PTHREAD_FLAG ON) |
| 240 | find_package(Threads REQUIRED) |
Damjan Marion | 612dd6a | 2018-07-30 12:45:07 +0200 | [diff] [blame] | 241 | |
Damjan Marion | 1ee346a | 2019-03-18 17:06:51 +0100 | [diff] [blame] | 242 | include(cmake/syscall.cmake) |
Damjan Marion | d16004d | 2018-08-26 10:14:52 +0200 | [diff] [blame] | 243 | include(cmake/api.cmake) |
Damjan Marion | 4553c95 | 2018-08-26 11:04:40 +0200 | [diff] [blame] | 244 | include(cmake/library.cmake) |
| 245 | include(cmake/exec.cmake) |
Damjan Marion | d16004d | 2018-08-26 10:14:52 +0200 | [diff] [blame] | 246 | include(cmake/plugin.cmake) |
Damjan Marion | 612dd6a | 2018-07-30 12:45:07 +0200 | [diff] [blame] | 247 | |
| 248 | ############################################################################## |
Tom Jones | 5ed27ef | 2024-01-29 14:38:19 +0000 | [diff] [blame] | 249 | # FreeBSD - use epoll-shim |
| 250 | ############################################################################## |
| 251 | set(EPOLL_LIB "") |
| 252 | if("${CMAKE_SYSTEM_NAME}" STREQUAL "FreeBSD") |
| 253 | find_path(EPOLL_SHIM_INCLUDE_DIR NAMES sys/epoll.h HINTS /usr/local/include/libepoll-shim) |
| 254 | find_library(EPOLL_SHIM_LIB NAMES epoll-shim HINTS /usr/local/lib) |
| 255 | |
| 256 | if(EPOLL_SHIM_INCLUDE_DIR AND EPOLL_SHIM_LIB) |
| 257 | message(STATUS "Found epoll-shim in ${EPOLL_SHIM_INCLUDE_DIR}") |
| 258 | include_directories(${EPOLL_SHIM_INCLUDE_DIR}) |
| 259 | string(JOIN " " EPOLL_LIB "${EPOLL_SHIM_LIB}") |
| 260 | endif() |
| 261 | endif() |
| 262 | |
| 263 | ############################################################################## |
Damjan Marion | 0abd4a2 | 2018-08-28 12:57:29 +0200 | [diff] [blame] | 264 | # subdirs - order matters |
Damjan Marion | 612dd6a | 2018-07-30 12:45:07 +0200 | [diff] [blame] | 265 | ############################################################################## |
Damjan Marion | 599efc6 | 2020-05-07 16:49:45 +0200 | [diff] [blame] | 266 | option(VPP_HOST_TOOLS_ONLY "Build only host tools" OFF) |
| 267 | if(VPP_HOST_TOOLS_ONLY) |
| 268 | set(SUBDIRS tools/vppapigen cmake) |
Guillaume Solignac | de04e02 | 2024-01-11 13:39:11 +0100 | [diff] [blame] | 269 | install( |
| 270 | PROGRAMS |
| 271 | vpp-api/vapi/vapi_c_gen.py |
| 272 | vpp-api/vapi/vapi_cpp_gen.py |
| 273 | vpp-api/vapi/vapi_json_parser.py |
| 274 | DESTINATION ${VPP_RUNTIME_DIR} |
| 275 | COMPONENT vpp-dev |
| 276 | ) |
Tom Jones | 2cbbbb6 | 2024-01-24 10:50:14 +0000 | [diff] [blame] | 277 | elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux|FreeBSD") |
Klement Sekera | efd4d70 | 2021-04-20 19:21:36 +0200 | [diff] [blame] | 278 | find_package(OpenSSL) |
Damjan Marion | 4dffd1c | 2018-09-03 12:30:36 +0200 | [diff] [blame] | 279 | set(SUBDIRS |
Arthur de Kerhor | b2819dd | 2021-09-20 14:47:47 +0200 | [diff] [blame] | 280 | vppinfra svm vlib vlibmemory vlibapi vnet vpp vat vat2 vcl vpp-api |
| 281 | plugins tools/vppapigen tools/g2 tools/perftool cmake pkg |
Dave Barach | 0729f64 | 2019-03-24 16:25:03 -0400 | [diff] [blame] | 282 | tools/appimage |
Damjan Marion | 0fa900e | 2018-09-12 12:12:36 +0200 | [diff] [blame] | 283 | ) |
Damjan Marion | 4dffd1c | 2018-09-03 12:30:36 +0200 | [diff] [blame] | 284 | elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin") |
| 285 | set(SUBDIRS vppinfra) |
| 286 | else() |
| 287 | message(FATAL_ERROR "Unsupported system: ${CMAKE_SYSTEM_NAME}") |
| 288 | endif() |
| 289 | |
| 290 | foreach(DIR ${SUBDIRS}) |
Damjan Marion | 88b2e36 | 2021-04-29 18:47:25 +0200 | [diff] [blame] | 291 | add_subdirectory(${DIR} ${VPP_BINARY_DIR}/${DIR}) |
Damjan Marion | 0abd4a2 | 2018-08-28 12:57:29 +0200 | [diff] [blame] | 292 | endforeach() |
Damjan Marion | 612dd6a | 2018-07-30 12:45:07 +0200 | [diff] [blame] | 293 | |
Damjan Marion | eeadc14 | 2018-09-13 20:02:12 +0200 | [diff] [blame] | 294 | ############################################################################## |
Damjan Marion | c6c0246 | 2018-08-31 17:38:57 +0200 | [diff] [blame] | 295 | # detect if we are inside git repo and add configure dependency |
| 296 | ############################################################################## |
| 297 | execute_process( |
| 298 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} |
| 299 | COMMAND git rev-parse --show-toplevel |
| 300 | OUTPUT_VARIABLE VPP_GIT_TOPLEVEL_DIR |
| 301 | OUTPUT_STRIP_TRAILING_WHITESPACE |
Damjan Marion | 6077c97 | 2019-01-28 17:55:59 +0100 | [diff] [blame] | 302 | ERROR_QUIET |
Damjan Marion | c6c0246 | 2018-08-31 17:38:57 +0200 | [diff] [blame] | 303 | ) |
| 304 | |
| 305 | if (VPP_GIT_TOPLEVEL_DIR) |
| 306 | set_property( |
| 307 | DIRECTORY APPEND PROPERTY |
| 308 | CMAKE_CONFIGURE_DEPENDS ${VPP_GIT_TOPLEVEL_DIR}/.git/index |
| 309 | ) |
| 310 | endif() |
| 311 | |
| 312 | ############################################################################## |
Damjan Marion | 88b2e36 | 2021-04-29 18:47:25 +0200 | [diff] [blame] | 313 | # custom targets |
| 314 | ############################################################################## |
| 315 | |
| 316 | add_custom_target(run |
| 317 | COMMAND ./${VPP_RUNTIME_DIR}/vpp -c startup.conf |
| 318 | COMMENT "Starting VPP..." |
| 319 | USES_TERMINAL |
| 320 | ) |
| 321 | |
| 322 | add_custom_target(debug |
| 323 | COMMAND gdb --args ./${VPP_RUNTIME_DIR}/vpp -c startup.conf |
| 324 | COMMENT "Starting VPP in the debugger..." |
| 325 | USES_TERMINAL |
| 326 | ) |
| 327 | |
Damjan Marion | c898324 | 2021-04-30 19:31:09 +0200 | [diff] [blame] | 328 | add_custom_target(config |
Damjan Marion | 88b2e36 | 2021-04-29 18:47:25 +0200 | [diff] [blame] | 329 | COMMAND ccmake ${CMAKE_BINARY_DIR} |
| 330 | COMMENT "Starting Configuration TUI..." |
| 331 | USES_TERMINAL |
| 332 | ) |
| 333 | |
Damjan Marion | 3a533cd | 2021-05-03 12:40:27 +0200 | [diff] [blame] | 334 | foreach(bt ${BUILD_TYPES}) |
| 335 | add_custom_target(set-build-type-${bt} |
| 336 | COMMAND cmake -DCMAKE_BUILD_TYPE:STRING=${bt} . |
| 337 | COMMENT "Changing build type to ${bt}" |
| 338 | USES_TERMINAL |
| 339 | ) |
| 340 | endforeach() |
| 341 | |
Damjan Marion | 0d39cba | 2021-05-10 14:51:44 +0200 | [diff] [blame] | 342 | mark_as_advanced(CLEAR |
| 343 | CMAKE_C_FLAGS |
| 344 | CMAKE_C_COMPILER |
| 345 | CMAKE_EXPORT_COMPILE_COMMANDS |
| 346 | CMAKE_INSTALL_PREFIX |
| 347 | CMAKE_LINKER |
| 348 | CMAKE_SHARED_LINKER_FLAGS |
| 349 | CMAKE_VERBOSE_MAKEFILE |
| 350 | ) |
| 351 | |
Damjan Marion | 88b2e36 | 2021-04-29 18:47:25 +0200 | [diff] [blame] | 352 | ############################################################################## |
Damjan Marion | c6c0246 | 2018-08-31 17:38:57 +0200 | [diff] [blame] | 353 | # print configuration |
| 354 | ############################################################################## |
| 355 | message(STATUS "Configuration:") |
Damjan Marion | 01fe7ab | 2023-10-23 18:36:18 +0200 | [diff] [blame] | 356 | pr("VPP platform" ${VPP_PLATFORM_NAME}) |
Damjan Marion | f2912e0 | 2021-07-16 12:44:22 +0200 | [diff] [blame] | 357 | pr("VPP version" ${VPP_VERSION}) |
| 358 | pr("VPP library version" ${VPP_LIB_VERSION}) |
| 359 | pr("GIT toplevel dir" ${VPP_GIT_TOPLEVEL_DIR}) |
| 360 | pr("Build type" ${CMAKE_BUILD_TYPE}) |
Damjan Marion | d545f04 | 2022-03-25 00:05:53 +0100 | [diff] [blame] | 361 | pr("C compiler" "${CMAKE_C_COMPILER} (${CMAKE_C_COMPILER_ID} ${CMAKE_C_COMPILER_VERSION})") |
Damjan Marion | f2912e0 | 2021-07-16 12:44:22 +0200 | [diff] [blame] | 362 | pr("C flags" ${CMAKE_C_FLAGS}${CMAKE_C_FLAGS_${CMAKE_BUILD_TYPE_UC}}) |
| 363 | pr("Linker flags (apps)" ${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_EXE_LINKER_FLAGS_${CMAKE_BUILD_TYPE_UC}}) |
| 364 | pr("Linker flags (libs)" ${CMAKE_SHARED_LINKER_FLAGS} ${CMAKE_SHARED_LINKER_FLAGS_${CMAKE_BUILD_TYPE_UC}}) |
| 365 | pr("Host processor" ${CMAKE_HOST_SYSTEM_PROCESSOR}) |
| 366 | pr("Target processor" ${CMAKE_SYSTEM_PROCESSOR}) |
| 367 | pr("Prefix path" ${CMAKE_PREFIX_PATH}) |
| 368 | pr("Install prefix" ${CMAKE_INSTALL_PREFIX}) |
Damjan Marion | 2e3a79f | 2021-11-05 20:08:05 +0100 | [diff] [blame] | 369 | pr("Library dir" ${VPP_LIBRARY_DIR}) |
Damjan Marion | 45e0539 | 2022-04-25 12:38:40 +0200 | [diff] [blame] | 370 | pr("Multiarch variants" ${MARCH_VARIANTS_NAMES}) |