#------------------------------------------------------------------------------
#
# \brief	CMakeLists.txt file for "libbiwak"
#
#------------------------------------------------------------------------------


cmake_minimum_required(VERSION 3.11)
project(biwak_tests)

find_package( Catch2 3 )
if( NOT Catch2_FOUND )
   find_package( Catch )
   if( NOT Catch_FOUND )
      # find_package does not work for Catch, at least on ubuntu 20.04
      if( EXISTS /usr/include/catch )
         add_definitions( "-DCATCH_V1" )
      elseif( EXISTS /usr/include/catch2 )
         if( EXISTS /usr/include/catch2/catch_test_macros.hpp )
            add_definitions( "-DCATCH_V3" )
         else()
            add_definitions( "-DCATCH_V2" )
         endif()
      else( EXISTS /usr/include/catch2 )
         message( FATAL_ERROR "Install eeither Catch or Catch2")
      endif( EXISTS /usr/include/catch )
   endif( NOT Catch_FOUND )
   add_definitions( "-DCATCH_V1" )
else( NOT Catch2_FOUND)
   add_definitions( "-DCATCH_V3" )
   set( CATCH_LIBRARY "Catch2::Catch2WithMain" )
endif( NOT Catch2_FOUND )

# Yes, just enable this for tests.
# add_definitions( "-DCONFIG_BIWAK_LOG_HEARTBEAT" )

set( CMAKE_AUTOUIC ON )
set( CMAKE_AUTOMOC ON )
set( CMAKE_AUTORCC ON )
set( CMAKE_AUTOUIC_SEARCH_PATHS "ui" )

find_package( QT NAMES Qt6 Qt5 COMPONENTS Core Gui asd Widgets REQUIRED )
find_package( Qt${QT_VERSION_MAJOR} COMPONENTS Core Gui Widgets REQUIRED )

set(headers
         #include/ocelli/touch.h
)

set(sources
   test_main.cpp
   test_barrel.cpp
   test_log.cpp
   test_retain.cpp
   test_can.cpp
   test_heartbeat.cpp
   test_systick.cpp
   test_fader.cpp
   test_lrtimer.cpp
   test_time.cpp
)

# Get write access to flash.bin without changing sources
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/flash.bin
						 COMMAND ${CMAKE_COMMAND} -E copy
														${CMAKE_CURRENT_SOURCE_DIR}/flash.bin
														${CMAKE_CURRENT_BINARY_DIR}/flash.bin
						 DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/flash.bin )

add_definitions( -DBIWAK_TEST_FLASH_FILE="${CMAKE_CURRENT_BINARY_DIR}/flash.bin")

add_executable( biwak_tests
         ${sources}
         ${headers}
			${CMAKE_CURRENT_BINARY_DIR}/flash.bin
)

target_link_libraries(
   biwak_tests
   PRIVATE
      biwak
      lepto
      ${CATCH_LIBRARY}
      Qt${QT_VERSION_MAJOR}::Core
      Qt${QT_VERSION_MAJOR}::Widgets
      Qt${QT_VERSION_MAJOR}::Gui
)

add_test(
   NAME biwak_tests
   COMMAND biwak_tests
   WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)


#------------------------------------------------------------------------------
