if (NOT DEFINED TARGET_TOOLCHAIN)
    SET (TARGET_TOOLCHAIN "mcc-linux-x86")
    include ("lib/${EDGE_SOURCES_DIR_NAME}/cmake/toolchains/${TARGET_TOOLCHAIN}.cmake")
endif()

# PT Client V2
if (DEFINED EDGE_CLIENT_TIMEOUT_CHECK_INTERVAL_MS)
    error("EDGE_CLIENT_TIMEOUT_CHECK_INTERVAL_MS is defined in multiple places!")
endif ()
SET (EDGE_CLIENT_TIMEOUT_CHECK_INTERVAL_MS 5000)     # 5 seconds

if (DEFINED EDGE_CLIENT_REQUEST_TIMEOUT_THRESHOLD_MS)
    error("EDGE_CLIENT_REQUEST_TIMEOUT_THRESHOLD_MS is defined in multiple places!")
endif ()
SET (EDGE_CLIENT_REQUEST_TIMEOUT_THRESHOLD_MS 60000) # one minute

if (NOT (CMAKE_BUILD_TYPE STREQUAL release))
    SET (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0")
    SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0")
endif ()

option (ENABLE_THREAD_SANITIZE "Compile and link with thread sanitizer" OFF)
if (ENABLE_THREAD_SANITIZE)
    message ("Enabling thread sanitizer")
    SET (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=thread")
    SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=thread")
    SET (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=thread")
endif ()

if (DEFINED TRACE_LEVEL)
    if (${TRACE_LEVEL} STREQUAL "DEBUG")
        add_definitions ("-DMBED_TRACE_MAX_LEVEL=TRACE_LEVEL_DEBUG")
    elseif (${TRACE_LEVEL} STREQUAL "INFO")
        add_definitions ("-DMBED_TRACE_MAX_LEVEL=TRACE_LEVEL_INFO")
    elseif (${TRACE_LEVEL} STREQUAL "WARN")
        add_definitions ("-DMBED_TRACE_MAX_LEVEL=TRACE_LEVEL_WARN")
    elseif (${TRACE_LEVEL} STREQUAL "ERROR")
        add_definitions ("-DMBED_TRACE_MAX_LEVEL=TRACE_LEVEL_ERROR")
    else ()
        MESSAGE (FATAL_ERROR "Unknown trace level '${TRACE_LEVEL}'")
    endif()
else()
    add_definitions ("-DMBED_TRACE_MAX_LEVEL=TRACE_LEVEL_ERROR")
endif()
if (ENABLE_COVERAGE EQUAL 1)
    message ("Enabling coverage")
    SET (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
    SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
    SET (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -lgcov")
endif ()
