+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)
+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()
+
+if(VPP_USE_LTO)
+ check_c_compiler_flag("-Wno-stringop-overflow"
+ compiler_flag_no_stringop_overflow)
+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)
+ add_link_options(-fsanitize=address)
+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()
+
+##############################################################################
+# 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()
+