X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2FCMakeLists.txt;h=fb4463e332e58801b43a71aff5612442023a0495;hb=a923ce5915b69da86d0f4b2457c38cabe62a2e65;hp=75e4253245bac669ee68333825494d5ccb3ecdd4;hpb=21feecf71da8b1f63c37f4bd684834699c04da7d;p=vpp.git diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 75e4253245b..fb4463e332e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -11,28 +11,11 @@ # See the License for the specific language governing permissions and # limitations under the License. -cmake_minimum_required(VERSION 3.10) - -set(CMAKE_C_COMPILER_NAMES - clang-13 - clang-12 - clang-11 - clang-10 - clang-9 - gcc-10 - gcc-9 - cc -) +cmake_minimum_required(VERSION 3.13) -project(vpp C) +set(CMAKE_C_COMPILER_NAMES clang gcc cc) -if(CMAKE_VERSION VERSION_LESS 3.12) - macro(add_compile_definitions defs) - foreach(d ${defs}) - add_compile_options(-D${d}) - endforeach() - endmacro() -endif() +project(vpp C) if(NOT DEFINED CMAKE_INSTALL_LIBDIR AND EXISTS "/etc/debian_version") set(CMAKE_INSTALL_LIBDIR "lib/${CMAKE_LIBRARY_ARCHITECTURE}") @@ -57,6 +40,43 @@ execute_process( string(REPLACE "-" ";" VPP_LIB_VERSION ${VPP_VERSION}) list(GET VPP_LIB_VERSION 0 VPP_LIB_VERSION) +############################################################################## +# compiler specifics +############################################################################## + +set(MIN_SUPPORTED_CLANG_C_COMPILER_VERSION 9.0.0) +set(MIN_SUPPORTED_GNU_C_COMPILER_VERSION 9.0.0) + +if(CMAKE_C_COMPILER_ID STREQUAL "Clang") + if (CMAKE_C_COMPILER_VERSION VERSION_LESS MIN_SUPPORTED_CLANG_C_COMPILER_VERSION) + set(COMPILER_TOO_OLD TRUE) + endif() +elseif(CMAKE_C_COMPILER_ID STREQUAL "GNU") + if (CMAKE_C_COMPILER_VERSION VERSION_LESS MIN_SUPPORTED_GNU_C_COMPILER_VERSION) + set(COMPILER_TOO_OLD TRUE) + endif() + set(GCC_STRING_OVERFLOW_WARNING_DISABLE_VERSION 10.0.0) + if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL GCC_STRING_OVERFLOW_WARNING_DISABLE_VERSION) + add_compile_options(-Wno-stringop-overflow) + endif() +else() + message(WARNING "WARNING: Unsupported C compiler `${CMAKE_C_COMPILER_ID}` is used") + set (PRINT_MIN_C_COMPILER_VER TRUE) +endif() +if (COMPILER_TOO_OLD) + message(WARNING "WARNING: C compiler version is too old and it's usage may result") + message(WARNING " in sub-optimal binaries or lack of support for specific CPU types.") + set (PRINT_MIN_C_COMPILER_VER TRUE) +endif() + +if (PRINT_MIN_C_COMPILER_VER) + string (APPEND _t "Supported C compilers are ") + string (APPEND _t "Clang ${MIN_SUPPORTED_CLANG_C_COMPILER_VERSION} or higher ") + string (APPEND _t "and GNU ${MIN_SUPPORTED_GNU_C_COMPILER_VERSION} or higher.") + message(WARNING " ${_t}") + unset (_t) +endif() + ############################################################################## # cross compiling ############################################################################## @@ -79,10 +99,10 @@ set(VPP_LIBRARY_DIR ${CMAKE_INSTALL_LIBDIR} CACHE STRING "Relative library direc 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) -set(PYENV PYTHONPYCACHEPREFIX=${CMAKE_BINARY_DIR}/CMakeFile/__pycache__) +set(PYENV PYTHONPYCACHEPREFIX=${CMAKE_BINARY_DIR}/CMakeFiles/__pycache__) if (CMAKE_BUILD_TYPE) - add_compile_options(-g -fPIC -Werror -Wall) + add_compile_options(-g -Werror -Wall) endif() if (compiler_flag_no_address_of_packed_member) @@ -98,7 +118,6 @@ 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) - set(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) @@ -125,6 +144,10 @@ if (CMAKE_BUILD_TYPE_UC STREQUAL "RELEASE") endif() endif() +if(VPP_USE_LTO) + check_c_compiler_flag("-Wno-stringop-overflow" + compiler_flag_no_stringop_overflow) +endif() ############################################################################## # sanitizers ############################################################################## @@ -138,9 +161,7 @@ set(VPP_SANITIZE_ADDR_OPTIONS if (VPP_ENABLE_SANITIZE_ADDR) 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}") + add_link_options(-fsanitize=address) endif (VPP_ENABLE_SANITIZE_ADDR) ############################################################################## @@ -152,6 +173,14 @@ if(VPP_ENABLE_TRAJECTORY_TRACE) add_compile_definitions(VLIB_BUFFER_TRACE_TRAJECTORY=1) endif() +############################################################################## +# unittest with clang ode coverage +############################################################################## + +if("${CMAKE_VERSION}" VERSION_GREATER_EQUAL "3.13" AND "${CMAKE_C_COMPILER_ID}" MATCHES "(Apple)?[Cc]lang") + option(VPP_BUILD_TESTS_WITH_COVERAGE "Build unit tests with code coverage" OFF) +endif() + ############################################################################## # install config ############################################################################## @@ -265,6 +294,7 @@ pr("VPP version" ${VPP_VERSION}) pr("VPP library version" ${VPP_LIB_VERSION}) pr("GIT toplevel dir" ${VPP_GIT_TOPLEVEL_DIR}) pr("Build type" ${CMAKE_BUILD_TYPE}) +pr("C compiler" "${CMAKE_C_COMPILER} (${CMAKE_C_COMPILER_ID} ${CMAKE_C_COMPILER_VERSION})") pr("C flags" ${CMAKE_C_FLAGS}${CMAKE_C_FLAGS_${CMAKE_BUILD_TYPE_UC}}) pr("Linker flags (apps)" ${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_EXE_LINKER_FLAGS_${CMAKE_BUILD_TYPE_UC}}) pr("Linker flags (libs)" ${CMAKE_SHARED_LINKER_FLAGS} ${CMAKE_SHARED_LINKER_FLAGS_${CMAKE_BUILD_TYPE_UC}}) @@ -272,3 +302,5 @@ pr("Host processor" ${CMAKE_HOST_SYSTEM_PROCESSOR}) pr("Target processor" ${CMAKE_SYSTEM_PROCESSOR}) pr("Prefix path" ${CMAKE_PREFIX_PATH}) pr("Install prefix" ${CMAKE_INSTALL_PREFIX}) +pr("Library dir" ${VPP_LIBRARY_DIR}) +pr("Multiarch variants" ${MARCH_VARIANTS_NAMES})