#**********************************************************************************#
# Copyright by @bkozdras <b.kozdras@gmail.com>                                     #
# Version: 1.0                                                                     #
# Licence: MIT                                                                     #
#**********************************************************************************#

message(STATUS "Processing: ${CMAKE_CURRENT_LIST_FILE}")

option(AVR_FRAMEWORK_BUILD_FOR_TARGET OFF, "Build library for AVR target")
option(AVR_FRAMEWORK_BUILD_TEST_EXECUTABLE_FOR_TARGET OFF, "Create example executable with linked library for target")
option(AVR_FRAMEWORK_BUILD_LIBRARY_STATIC OFF "Build avrframework static library")
option(AVR_FRAMEWORK_BUILD_LIBRARY_SHARED OFF "Build libavrframework shared library")
option(AVR_FRAMEWORK_BUILD_STUB_LIBRARY_STATIC OFF "Build avrframeworkstub static library")
option(AVR_FRAMEWORK_BUILD_STUB_LIBRARY_SHARED OFF "Build libavrframeworkstub shared library")
option(AVR_FRAMEWORK_UNIT_TESTING_ENABLED OFF "Enabled unit tests building and running")
option(AVR_FRAMEWORK_GENERATE_CODE_COVERAGE OFF "Generate code coverage with the use of lcov")
option(AVR_FRAMEWORK_USE_ADDRESS_SANITIZER OFF "Use address sanitizer in UT running")
option(AVR_FRAMEWORK_AVR_MCU_FREQ 16000000UL "F_CPU - clock for desired CPU")

set(BUILD_LIBRARY OFF)
if (AVR_FRAMEWORK_BUILD_LIBRARY_STATIC OR AVR_FRAMEWORK_BUILD_LIBRARY_SHARED)
    set(BUILD_LIBRARY ON)
endif (AVR_FRAMEWORK_BUILD_LIBRARY_STATIC OR AVR_FRAMEWORK_BUILD_LIBRARY_SHARED)
set(BUILD_STATIC_LIBRARY OFF)
set(BUILD_SHARED_LIBRARY OFF)
if (BUILD_LIBRARY)
    if (AVR_FRAMEWORK_BUILD_LIBRARY_STATIC)
        set(BUILD_STATIC_LIBRARY ON)
    endif (AVR_FRAMEWORK_BUILD_LIBRARY_STATIC)
    if (AVR_FRAMEWORK_BUILD_LIBRARY_SHARED)
        set(BUILD_SHARED_LIBRARY ON)
    endif (AVR_FRAMEWORK_BUILD_LIBRARY_SHARED)
endif (BUILD_LIBRARY)

set(BUILD_STUB_LIBRARY OFF)
if (AVR_FRAMEWORK_BUILD_STUB_LIBRARY_STATIC OR AVR_FRAMEWORK_BUILD_STUB_LIBRARY_SHARED)
    set(BUILD_STUB_LIBRARY ON)
endif (AVR_FRAMEWORK_BUILD_STUB_LIBRARY_STATIC OR AVR_FRAMEWORK_BUILD_STUB_LIBRARY_SHARED)
set(BUILD_STATIC_STUB_LIBRARY OFF)
set(BUILD_SHARED_STUB_LIBRARY OFF)
if (BUILD_STUB_LIBRARY)
    if (AVR_FRAMEWORK_BUILD_STUB_LIBRARY_STATIC)
        set(BUILD_STATIC_STUB_LIBRARY ON)
    endif (AVR_FRAMEWORK_BUILD_STUB_LIBRARY_STATIC)
    if (AVR_FRAMEWORK_BUILD_STUB_LIBRARY_SHARED)
        set(BUILD_SHARED_STUB_LIBRARY ON)
    endif (AVR_FRAMEWORK_BUILD_STUB_LIBRARY_SHARED)
endif (BUILD_STUB_LIBRARY)

set(BUILD_UNIT_TESTS OFF)
set(GENERATE_CODE_COVERAGE OFF)
set(USE_ADDRESS_SANITIZER OFF)
if (AVR_FRAMEWORK_UNIT_TESTING_ENABLED)
    set(BUILD_UNIT_TESTS ON)
    if (NOT AVR_FRAMEWORK_BUILD_LIBRARY_STATIC)
        message(FATAL_ERROR "Building unit tests is enabled. AVR_FRAMEWORK_BUILD_LIBRARY_STATIC should be set to ON!")
    endif (NOT AVR_FRAMEWORK_BUILD_LIBRARY_STATIC)
    if (AVR_FRAMEWORK_GENERATE_CODE_COVERAGE)
        set(GENERATE_CODE_COVERAGE ON)
    endif (AVR_FRAMEWORK_GENERATE_CODE_COVERAGE)
    if (AVR_FRAMEWORK_USE_ADDRESS_SANITIZER)
        set(USE_ADDRESS_SANITIZER ON)
    endif (AVR_FRAMEWORK_USE_ADDRESS_SANITIZER)
endif (AVR_FRAMEWORK_UNIT_TESTING_ENABLED)

set(BUILD_FOR_TARGET OFF)
if (AVR_FRAMEWORK_BUILD_FOR_TARGET)
    set(BUILD_FOR_TARGET ON)
    set(BUILD_LIBRARY OFF)
    set(BUILD_STATIC_LIBRARY OFF)
    set(BUILD_SHARED_LIBRARY OFF)
    set(BUILD_STUB_LIBRARY OFF)
    set(BUILD_STATIC_STUB_LIBRARY OFF)
    set(BUILD_SHARED_STUB_LIBRARY OFF)
    set(BUILD_UNIT_TESTS OFF)
endif (AVR_FRAMEWORK_BUILD_FOR_TARGET)

set(BUILD_TEST_EXECUTABLE_FOR_TARGET OFF)
if (AVR_FRAMEWORK_BUILD_TEST_EXECUTABLE_FOR_TARGET)
    set(BUILD_TEST_EXECUTABLE_FOR_TARGET ON)
endif (AVR_FRAMEWORK_BUILD_TEST_EXECUTABLE_FOR_TARGET)

message(STATUS "BUILD_FOR_TARGET: " ${BUILD_FOR_TARGET})
message(STATUS "BUILD_TEST_EXECUTABLE_FOR_TARGET: " ${BUILD_TEST_EXECUTABLE_FOR_TARGET})
message(STATUS "BUILD_LIBRARY: " ${BUILD_LIBRARY})
message(STATUS "BUILD_STATIC_LIBRARY: " ${BUILD_STATIC_LIBRARY})
message(STATUS "BUILD_SHARED_LIBRARY: " ${BUILD_SHARED_LIBRARY})
message(STATUS "BUILD_STUB_LIBRARY: " ${BUILD_STUB_LIBRARY})
message(STATUS "BUILD_STATIC_STUB_LIBRARY: " ${BUILD_STATIC_STUB_LIBRARY})
message(STATUS "BUILD_SHARED_STUB_LIBRARY: " ${BUILD_SHARED_STUB_LIBRARY})
message(STATUS "BUILD_UNIT_TESTS: " ${BUILD_UNIT_TESTS})
message(STATUS "GENERATE_CODE_COVERAGE: " ${GENERATE_CODE_COVERAGE})
message(STATUS "USE_ADDRESS_SANITIZER: " ${USE_ADDRESS_SANITIZER})
