include(${CMAKE_CURRENT_LIST_DIR}/colors.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/prefix.cmake)

macro(SetOptionNames)
    set(prefix "")
    GetProjectPrefix(prefix)
    set(opt_werror           ${prefix}_WERROR)
    set(opt_tests            ${prefix}_TESTS)
    set(opt_coverage         ${prefix}_COVERAGE)
    set(opt_sanitize_address ${prefix}_SANITIZE_ADDRESS)
    set(opt_sanitize_leak    ${prefix}_SANITIZE_LEAK)
    set(opt_sanitize_thread  ${prefix}_SANITIZE_THREAD)
    set(opt_sanitize_ub      ${prefix}_SANITIZE_UDEFINED_BEHAVIOR)
    message(STATUS "${ColorYellow}${opt_werror}          ${ColorReset}")
    message(STATUS "${ColorYellow}${opt_tests}           ${ColorReset}")
    message(STATUS "${ColorYellow}${opt_coverage}        ${ColorReset}")
    message(STATUS "${ColorYellow}${opt_sanitize_address}${ColorReset}")
    message(STATUS "${ColorYellow}${opt_sanitize_leak}   ${ColorReset}")
    message(STATUS "${ColorYellow}${opt_sanitize_thread} ${ColorReset}")
    message(STATUS "${ColorYellow}${opt_sanitize_ub}     ${ColorReset}")
endmacro()

macro(SetOptions)
    SetOptionNames()
    option(${opt_werror} "Enable warning as errors for ${CMAKE_PROJECT_NAME}" ON)
    option(${opt_tests} "Build ${CMAKE_PROJECT_NAME} tests" ON)
    option(${opt_coverage} "Generate ${CMAKE_PROJECT_NAME} code coverage" OFF)
    option(${opt_sanitize_address} "Enable address-sanitizer for ${CMAKE_PROJECT_NAME}" OFF)
    option(${opt_sanitize_leak} "Enable leak-sanitizer for ${CMAKE_PROJECT_NAME}" OFF)
    option(${opt_sanitize_thread} "Enable thread-sanitizer for ${CMAKE_PROJECT_NAME}" OFF)
    option(${opt_sanitize_ub} "Enable undefined-behavior-sanitizer for ${CMAKE_PROJECT_NAME}" OFF)

    if (NOT CMAKE_BUILD_TYPE STREQUAL Debug)
        if (${${opt_coverage}})
            message(FATAL_ERROR
                "${ColorBoldRed}${${opt_coverage}}=ON valid only for CMAKE_BUILD_TYPE=Debug${ColorReset}"
            )
        endif()
        if (${opt_sanitize_address} OR ${opt_sanitize_leak} OR ${opt_sanitize_thread} OR ${opt_sanitize_ub})
            message(FATAL_ERROR
                "${ColorBoldRed}Sanitizers can be used only with CMAKE_BUILD_TYPE=Debug${ColorReset}"
            )
        endif()
    endif()
endmacro()
