# See the License for the specific language governing permissions and
# limitations under the License.
-cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
-
-set(CMAKE_C_COMPILER_NAMES clang-9 cc)
+cmake_minimum_required(VERSION 3.10)
+
+set(CMAKE_C_COMPILER_NAMES
+ clang-12
+ clang-11
+ clang-10
+ clang-9
+ gcc-10
+ gcc-9
+ cc
+)
project(vpp C)
include(CheckCCompilerFlag)
+include(CheckIPOSupported)
include(cmake/misc.cmake)
include(cmake/cpu.cmake)
include(cmake/ccache.cmake)
##############################################################################
check_c_compiler_flag("-Wno-address-of-packed-member"
compiler_flag_no_address_of_packed_member)
+set(VPP_RUNTIME_DIR "bin" CACHE STRING "Relative runtime directory path")
+set(VPP_LIBRARY_DIR "lib" CACHE STRING "Relative library directory path")
-set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
-set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
+set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${VPP_RUNTIME_DIR})
+set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${VPP_LIBRARY_DIR})
+set(VPP_BINARY_DIR ${CMAKE_BINARY_DIR}/CMakeFiles)
if (CMAKE_BUILD_TYPE)
set(CMAKE_C_FLAGS "-g -fPIC -Werror -Wall ${CMAKE_C_FLAGS}")
# release
list(APPEND BUILD_TYPES "release")
string(CONCAT CMAKE_C_FLAGS_RELEASE
- "-O2 "
+ "-O3 "
"-fstack-protector "
- "-DFORTIFY_SOURCE=2 "
+ "-D_FORTIFY_SOURCE=2 "
"-fno-common "
)
"-O0 "
"-DCLIB_DEBUG "
"-fstack-protector "
- "-DFORTIFY_SOURCE=2 "
"-fno-common "
)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY
HELPSTRING "Build type - valid options are: ${BUILD_TYPES}")
+##############################################################################
+# link time optimizations
+##############################################################################
+if (CMAKE_BUILD_TYPE_UC STREQUAL "RELEASE")
+ check_ipo_supported(RESULT _result)
+ if (_result)
+ option(VPP_USE_LTO "Link time optimization of release binaries" ON)
+ endif()
+endif()
+
##############################################################################
# sanitizers
##############################################################################
-option(ENABLE_SANITIZE_ADDR "Enable Address Sanitizer" OFF)
-if (ENABLE_SANITIZE_ADDR)
- set(CMAKE_C_FLAGS "-fsanitize=address --param asan-stack=0 -DCLIB_SANITIZE_ADDR ${CMAKE_C_FLAGS}")
+option(VPP_ENABLE_SANITIZE_ADDR "Enable Address Sanitizer" OFF)
+set(VPP_SANITIZE_ADDR_OPTIONS
+ "unmap_shadow_on_exit=1:disable_coredump=0:abort_on_error=1:detect_leaks=0"
+ CACHE
+ STRING "Address sanitizer arguments"
+)
+
+if (VPP_ENABLE_SANITIZE_ADDR)
+ set(CMAKE_C_FLAGS "-fsanitize=address -DCLIB_SANITIZE_ADDR ${CMAKE_C_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "-fsanitize=address ${CMAKE_EXE_LINKER_FLAGS}")
set(CMAKE_SHARED_LINKER_FLAGS "-fsanitize=address ${CMAKE_SHARED_LINKER_FLAGS}")
-endif (ENABLE_SANITIZE_ADDR)
+endif (VPP_ENABLE_SANITIZE_ADDR)
##############################################################################
# install config
##############################################################################
-set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
+option(VPP_SET_RPATH "Set rpath for resulting binaries and libraries." ON)
+if(VPP_SET_RPATH)
+ set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
+endif()
set(CMAKE_INSTALL_MESSAGE NEVER)
include_directories (
${CMAKE_SOURCE_DIR}
- ${CMAKE_BINARY_DIR}
- ${CMAKE_BINARY_DIR}/include
+ ${VPP_BINARY_DIR}
)
set(CMAKE_INSTALL_DEFAULT_COMPONENT_NAME "vpp")
##############################################################################
# subdirs - order matters
##############################################################################
-if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
+option(VPP_HOST_TOOLS_ONLY "Build only host tools" OFF)
+if(VPP_HOST_TOOLS_ONLY)
+ set(SUBDIRS tools/vppapigen cmake)
+elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
find_package(OpenSSL REQUIRED)
set(SUBDIRS
- vppinfra svm vlib vlibmemory vlibapi vnet vpp vat vcl plugins
- vpp-api tools/vppapigen tools/g2 tools/elftool tools/perftool cmake pkg
+ vppinfra svm vlib vlibmemory vlibapi vnet vpp vat vat2 vcl plugins
+ vpp-api tools/vppapigen tools/g2 tools/perftool cmake pkg
tools/appimage
)
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
endif()
foreach(DIR ${SUBDIRS})
- add_subdirectory(${DIR})
+ add_subdirectory(${DIR} ${VPP_BINARY_DIR}/${DIR})
endforeach()
##############################################################################
)
endif()
+##############################################################################
+# custom targets
+##############################################################################
+
+add_custom_target(run
+ COMMAND ./${VPP_RUNTIME_DIR}/vpp -c startup.conf
+ COMMENT "Starting VPP..."
+ USES_TERMINAL
+)
+
+add_custom_target(debug
+ COMMAND gdb --args ./${VPP_RUNTIME_DIR}/vpp -c startup.conf
+ COMMENT "Starting VPP in the debugger..."
+ USES_TERMINAL
+)
+
+add_custom_target(menu
+ COMMAND ccmake ${CMAKE_BINARY_DIR}
+ COMMENT "Starting Configuration TUI..."
+ USES_TERMINAL
+)
+
+add_custom_target(compdb
+ COMMAND ninja -C ${CMAKE_BINARY_DIR} -t compdb |
+ ${CMAKE_SOURCE_DIR}/scripts/compdb_cleanup.py >
+ ${CMAKE_BINARY_DIR}/compile_commands.json
+ COMMENT "Generating compile_commands.json"
+ USES_TERMINAL
+)
+
##############################################################################
# print configuration
##############################################################################