X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2FCMakeLists.txt;h=ebf03bdad6179ec5b7544b6b45412dfe2824a833;hb=92a8d761c412590f5112239be4c511091b2b2d5a;hp=e2937c99db62aeb94f01c9a463b04684b74ccb40;hpb=ec3a3f16e4cd3b33e2a409fb01b8d8826e05f9fa;p=vpp.git diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e2937c99db6..ebf03bdad61 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -11,13 +11,30 @@ # See the License for the specific language governing permissions and # limitations under the License. -cmake_minimum_required(VERSION 3.5 FATAL_ERROR) +cmake_minimum_required(VERSION 3.10) -set(CMAKE_C_COMPILER_NAMES clang-10 clang-9 gcc-9 cc) +set(CMAKE_C_COMPILER_NAMES + clang-12 + clang-11 + clang-10 + clang-9 + gcc-10 + gcc-9 + cc +) project(vpp C) +if(CMAKE_VERSION VERSION_LESS 3.12) + macro(add_compile_definitions defs) + foreach(d ${defs}) + add_compile_options(-D${d}) + endforeach() + endmacro() +endif() + include(CheckCCompilerFlag) +include(CheckIPOSupported) include(cmake/misc.cmake) include(cmake/cpu.cmake) include(cmake/ccache.cmake) @@ -55,83 +72,91 @@ set(VPP_LIBRARY_DIR "lib" CACHE STRING "Relative library directory path") 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}") + add_compile_options(-g -fPIC -Werror -Wall) endif() if (compiler_flag_no_address_of_packed_member) - set(CMAKE_C_FLAGS "-Wno-address-of-packed-member ${CMAKE_C_FLAGS}") + add_compile_options(-Wno-address-of-packed-member) endif() -# release -list(APPEND BUILD_TYPES "release") -string(CONCAT CMAKE_C_FLAGS_RELEASE - "-O2 " - "-fstack-protector " - "-DFORTIFY_SOURCE=2 " - "-fno-common " -) - -string(CONCAT CMAKE_EXE_LINKER_FLAGS_RELEASE "-pie") - -# debug -list(APPEND BUILD_TYPES "debug") -string(CONCAT CMAKE_C_FLAGS_DEBUG - "-O0 " - "-DCLIB_DEBUG " - "-fstack-protector " - "-DFORTIFY_SOURCE=2 " - "-fno-common " -) - -# coverity -list(APPEND BUILD_TYPES "coverity") -string(CONCAT CMAKE_C_FLAGS_COVERITY "-O2 -D__COVERITY__") - -# gcov -list(APPEND BUILD_TYPES "gcov") -string(CONCAT CMAKE_C_FLAGS_GCOV - "-O0 " - "-DCLIB_DEBUG " - "-DCLIB_GCOV " - "-fprofile-arcs " - "-ftest-coverage ") - +string(TOLOWER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_LC) string(TOUPPER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_UC) +set(CMAKE_C_FLAGS_RELEASE "") +set(CMAKE_C_FLAGS_DEBUG "") + +if (${CMAKE_BUILD_TYPE_LC} MATCHES "release") + add_compile_options(-O3 -fstack-protector -fno-common) + add_compile_definitions(_FORTIFY_SOURCE=2) + string(CONCAT CMAKE_EXE_LINKER_FLAGS_RELEASE "-pie") +elseif (${CMAKE_BUILD_TYPE_LC} MATCHES "debug") + add_compile_options(-O0 -fstack-protector -fno-common) + add_compile_definitions(CLIB_DEBUG) +elseif (${CMAKE_BUILD_TYPE_LC} MATCHES "coverity") + add_compile_options(-O0) + add_compile_definitions(__COVERITY__) +elseif (${CMAKE_BUILD_TYPE_LC} MATCHES "gcov") + add_compile_options(-O0 -fprofile-arcs -ftest-coverage) + add_compile_definitions(CLIB_DEBUG CLIB_GCOV) +endif() -string(REPLACE ";" " " BUILD_TYPES "${BUILD_TYPES}") +set(BUILD_TYPES release debug coverity gcov) +string(REPLACE ";" " " BUILD_TYPES_STR "${BUILD_TYPES}") set_property(CACHE CMAKE_BUILD_TYPE PROPERTY - HELPSTRING "Build type - valid options are: ${BUILD_TYPES}") + HELPSTRING "Build type - valid options are: ${BUILD_TYPES_STR}") + +############################################################################## +# 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(VPP_ENABLE_SANITIZE_ADDR "Enable Address Sanitizer" OFF) -set(VPP_SANITIZE_ADDR_ARGS +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 --param asan-stack=0 -DCLIB_SANITIZE_ADDR ${CMAKE_C_FLAGS}") + add_compile_options(-fsanitize=address) + add_compile_definitions(CLIB_SANITIZE_ADDR) set(CMAKE_EXE_LINKER_FLAGS "-fsanitize=address ${CMAKE_EXE_LINKER_FLAGS}") set(CMAKE_SHARED_LINKER_FLAGS "-fsanitize=address ${CMAKE_SHARED_LINKER_FLAGS}") endif (VPP_ENABLE_SANITIZE_ADDR) +############################################################################## +# trajectory trace +############################################################################## + +option(VPP_ENABLE_TRAJECTORY_TRACE "Build vpp with trajectory tracing enabled" OFF) +if(VPP_ENABLE_TRAJECTORY_TRACE) + add_compile_definitions(VLIB_BUFFER_TRACE_TRAJECTORY=1) +endif() + ############################################################################## # 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") @@ -153,7 +178,7 @@ if(VPP_HOST_TOOLS_ONLY) elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") find_package(OpenSSL REQUIRED) set(SUBDIRS - vppinfra svm vlib vlibmemory vlibapi vnet vpp vat vcl plugins + vppinfra svm vlib vlibmemory vlibapi vnet vpp vat vat2 vcl plugins vpp-api tools/vppapigen tools/g2 tools/perftool cmake pkg tools/appimage ) @@ -164,7 +189,7 @@ else() endif() foreach(DIR ${SUBDIRS}) - add_subdirectory(${DIR}) + add_subdirectory(${DIR} ${VPP_BINARY_DIR}/${DIR}) endforeach() ############################################################################## @@ -185,6 +210,46 @@ if (VPP_GIT_TOPLEVEL_DIR) ) 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(config + COMMAND ccmake ${CMAKE_BINARY_DIR} + COMMENT "Starting Configuration TUI..." + USES_TERMINAL +) + +foreach(bt ${BUILD_TYPES}) + add_custom_target(set-build-type-${bt} + COMMAND cmake -DCMAKE_BUILD_TYPE:STRING=${bt} . + COMMENT "Changing build type to ${bt}" + USES_TERMINAL + ) +endforeach() + +mark_as_advanced(CLEAR + CMAKE_C_FLAGS + CMAKE_C_COMPILER + CMAKE_EXPORT_COMPILE_COMMANDS + CMAKE_INSTALL_PREFIX + CMAKE_LINKER + CMAKE_SHARED_LINKER_FLAGS + CMAKE_VERBOSE_MAKEFILE +) + ############################################################################## # print configuration ##############################################################################