# 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-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}")
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
##############################################################################
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)
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)
endif()
endif()
+if(VPP_USE_LTO)
+ check_c_compiler_flag("-Wno-stringop-overflow"
+ compiler_flag_no_stringop_overflow)
+endif()
##############################################################################
# sanitizers
##############################################################################
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)
##############################################################################
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
##############################################################################
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}})
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})