# РЎР±РѕСЂРєР° Р±РёР±Р»РёРѕС‚РµРєРё protocan_boot. РЎРѕСЃС‚Р°РІ РёСЃС…РѕРґРЅРёРєРѕРІ Рё РїСѓР±Р»РёС‡РЅС‹Рµ include-РїСѓС‚Рё Р·Р°РґР°СЋС‚
# РїРѕРґРєР»СЋС‡РµРЅРёРµ Рє РїСЂРѕРµРєС‚Сѓ РїРѕС‚СЂРµР±РёС‚РµР»СЏ. Р¤Р°Р№Р» С‚Р°РєР¶Рµ СЃРѕР±РёСЂР°РµС‚ Рё СЂРµРіРёСЃС‚СЂРёСЂСѓРµС‚ С…РѕСЃС‚РѕРІС‹Рµ РїСЂРѕРІРµСЂРєРё;
# Р·Р°РїСѓСЃРєР°С‚СЊ РёС… СЃР»РµРґСѓРµС‚ С‡РµСЂРµР· CTest РёР· РєР°С‚Р°Р»РѕРіР° СЃР±РѕСЂРєРё.

cmake_minimum_required(VERSION 3.13)
project(protocan_boot C)

set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD_REQUIRED ON)

add_library(protocan_boot STATIC src/pcan_boot.c)
target_include_directories(protocan_boot PUBLIC include)

if(MSVC)
    target_compile_options(protocan_boot PRIVATE /W4)
else()
    target_compile_options(protocan_boot PRIVATE -Wall -Wextra -Wpedantic)
endif()

option(PCAN_BOOT_BUILD_TESTS "РЎРѕР±РёСЂР°С‚СЊ С‚РµСЃС‚С‹ ProtoCAN boot" ON)
if(PCAN_BOOT_BUILD_TESTS)
    enable_testing()
    add_executable(test_pcan_boot tests/test_pcan_boot.c)
    target_link_libraries(test_pcan_boot PRIVATE protocan_boot)
    add_test(NAME pcan_boot COMMAND test_pcan_boot)
endif()

if(PCAN_BOOT_BUILD_TESTS)
    add_executable(test_f28335_can_boot tests/test_f28335_can_boot.c src/pcan_boot.c ports/tms320f28335/f28335_boot_store.c)
    target_compile_definitions(test_f28335_can_boot PRIVATE PCAN_BOOT_WIDE_BYTES)
    target_include_directories(test_f28335_can_boot PRIVATE tests/f28335_stubs)
    add_test(NAME f28335_can_boot COMMAND test_f28335_can_boot)
endif()

if(PCAN_BOOT_BUILD_TESTS)
    add_executable(test_f28335_application tests/test_f28335_can_boot.c src/pcan_boot.c ports/tms320f28335/f28335_boot_store.c)
    target_compile_definitions(test_f28335_application PRIVATE PCAN_BOOT_WIDE_BYTES F28335_BOOT_LOADER=0)
    target_include_directories(test_f28335_application PRIVATE tests/f28335_stubs)
    add_test(NAME f28335_application COMMAND test_f28335_application)
    foreach(width native wide)
        add_executable(test_f28335_store_${width} tests/test_f28335_boot_store.c ports/tms320f28335/f28335_boot_store.c)
        if(width STREQUAL "wide")
            target_compile_definitions(test_f28335_store_${width} PRIVATE PCAN_BOOT_WIDE_BYTES)
        endif()
        add_test(NAME f28335_store_${width} COMMAND test_f28335_store_${width})
    endforeach()
endif()
