+ add_compile_options(-Wno-address-of-packed-member)
+endif()
+
+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()
+
+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_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_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)
+ 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)