add_library(cpf_support STATIC)
target_include_directories(cpf_support PUBLIC .)
target_sources(cpf_support PRIVATE
	FIFO.cpp
	FIFO.hpp
	FIFOQueue.hpp
	Logger.hpp
	volatile.hpp
	endian.hpp
	get_field.hpp
	GPS_NMEA.hpp
	Supervised_PV_Controller.cpp
	Supervised_PV_Controller.hpp
	controls/LPF_Estimator.cpp
	controls/LPF_Estimator.hpp
	controls/FIR_Filter.cpp
	controls/FIR_Filter.hpp
	controls/BuoyancyEngine.cpp
	controls/BuoyancyEngine.hpp
	controls/AH_PID.cpp
	controls/AH_PID.hpp
)
# TODO: FIX THIS Otherwise, when building tests, I get
# undefined reference to `Logger::loggerEngFileHeader`
# The reason is that some libraries are linked whole, and cmake
# is not respecting linker ordering for these... but alwys puts link-whole at the end.
target_sources(cpf_support INTERFACE
	Logger.cpp
	GPS_NMEA.cpp
	get_field.cpp
)
target_link_libraries(cpf_support PRIVATE etl::etl cpf_interfaces)

# This was refactored into this section.
# We kept the library dep in case it gets refactored elsewhere again.
# Then, dependent targets won't need changed.
add_library(logger_include_dep INTERFACE)
target_include_directories(logger_include_dep INTERFACE . controls)

add_library(cpf_support_tests INTERFACE)
target_include_directories(cpf_support_tests INTERFACE .)
# These tests can be run both on- and off-device
target_sources(cpf_support_tests INTERFACE
	volatile_tests.cpp
	FifoQueue_tests.cpp
	Fifo_tests.cpp
	get_field_tests.cpp
	GPS_NMEA_tests.cpp
	controls/AH_PID_tests.cpp
	controls/LPF_Estimator_tests.cpp
)

# These tests can only be run off-device
if(NOT CMAKE_CROSSCOMPILING)
target_sources(cpf_support_tests INTERFACE
	# This depends on a simulation header and doesn't not currently build
	# for the device.
	Supervised_PV_Controller_tests.cpp
)
endif()

target_link_libraries(cpf_support_tests INTERFACE cpf_support)
