####################
# Test Application #
####################

# This test target is only supported on the build machine
if(NOT CMAKE_CROSSCOMPILING)
	add_subdirectory(mocks)

	add_executable(CPF_build_machine_tests)
	target_sources(CPF_build_machine_tests PRIVATE
		TestMain.cpp
		TestEventProcessing.cpp
	)
	target_link_libraries(CPF_build_machine_tests PRIVATE
		cpf_support_tests
		cpf_hw_driver_build_host_tests
		cpf_mock_tests
		cpf_testing_mocks
		cpf_offtarget_interfaces_tests
		etl
		CppUTest
		CppUTestExt
	)

	if(NOT (CMAKE_CXX_COMPILER_ID MATCHES "MSVC"))
		target_compile_options(CPF_build_machine_tests PRIVATE -Wno-old-style-cast)
	endif()

	add_test(
		NAME CPF.offtarget
		COMMAND CPF_build_machine_tests
	)
endif()

# This build will be cleaned up after the source file re-organization.
# For now, we need to a) not build core to avoid main, and b) still compile
# the STM32 files
if(CMAKE_CROSSCOMPILING AND USING_VISUAL_GDB)
	add_executable(cpf_target_tests)
	target_sources(cpf_target_tests PRIVATE
		OnDeviceTestMain.cpp
	)
	target_compile_definitions(cpf_target_tests PRIVATE BUILD_FOR_TESTING)
	target_compile_options(cpf_target_tests PRIVATE -Wno-old-style-cast)
	target_link_libraries(cpf_target_tests PRIVATE
		cpf_interfaces_tests
		cpf_support_tests
		cpf_devices_tests
		bsp_tests
		hw_platform_dep
		error_handler
		cpf_state
		EFP
		SysprogsCppUTest
	)
	target_linker_map(cpf_target_tests)

	add_executable(cpf_uart_loopback_test)
	target_sources(cpf_uart_loopback_test PRIVATE
		UartLoopbackTest.cpp
		OnDeviceTestMain.cpp
	)
	target_compile_definitions(cpf_uart_loopback_test PRIVATE BUILD_FOR_TESTING)
	target_compile_options(cpf_uart_loopback_test PRIVATE -Wno-old-style-cast)
	target_link_libraries(cpf_uart_loopback_test PRIVATE cpf_support etl::etl cpf_interfaces hw_platform_dep error_handler cpf_state)
	target_link_libraries(cpf_uart_loopback_test PRIVATE EFP SysprogsCppUTest)
	target_linker_map(cpf_uart_loopback_test)
endif()
