# Example:
# cmake -DLIBSTDCPP_HOME=/path/to/avr-libstdcpp -DCMAKE_TOOLCHAIN_FILE=../examples/mb/toolchain.cmake -DCMAKE_BUILD_TYPE=MinSizeRel
# -DXIL_STANDALONE_BSP_INCLUDE=/path/to/bspinclude/include -DXIL_STANDALONE_BSP_LIB=/path/to/bsplib/lib -DCMAKE_CXX_COMPILER_AR=mb-ar
# -DCMAKE_CXX_COMPILER_RANLIB=mb-ranlib  ..

cmake_minimum_required(VERSION 3.8)
cmake_policy(SET CMP0069 NEW)

include(CheckIPOSupported)
check_ipo_supported(RESULT supported OUTPUT error)
if( supported )
    message(STATUS "IPO / LTO enabled for the microblaze builds")
    set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
else()
    message(STATUS "IPO / LTO not supported: <${error}>")
endif()

if (NOT ("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "MICROBLAZE" ))
  message(FATAL_ERROR "wrong system processor ${CMAKE_SYSTEM_PROCESSOR}, expected: MICROBLAZE")
endif()

message(STATUS "will use stdlib++ from '${LIBSTDCPP_HOME}'")
add_library(board board.cpp)

target_include_directories(rotor_light PUBLIC "${LIBSTDCPP_HOME}/include")
target_include_directories(board PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}")
target_link_libraries(board rotor_light)

add_executable(blink-led blink-led.cpp)
target_link_libraries(blink-led board)

add_executable(ping-pong-poll ping-pong-poll.cpp)
target_link_libraries(ping-pong-poll board)
