include(FindPackageHandleStandardArgs)
include(SelectLibraryConfigurations)

find_path(
	ATIDAQ_INCLUDE_DIRS
	NAMES
	atidaq/ftconfig.h
)

mark_as_advanced(ATIDAQ_INCLUDE_DIRS)

find_library(
	ATIDAQ_LIBRARY_DEBUG
	NAMES
	atidaqd
)

find_library(
	ATIDAQ_LIBRARY_RELEASE
	NAMES
	atidaq
)

select_library_configurations(ATIDAQ)

find_package_handle_standard_args(
	ATIDAQ
	FOUND_VAR ATIDAQ_FOUND
	REQUIRED_VARS ATIDAQ_INCLUDE_DIRS ATIDAQ_LIBRARIES
)

if(ATIDAQ_FOUND AND NOT TARGET ATIDAQ::ATIDAQ)
	add_library(ATIDAQ::ATIDAQ UNKNOWN IMPORTED)
	
	if(ATIDAQ_LIBRARY_RELEASE)
		set_property(TARGET ATIDAQ::ATIDAQ APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE)
		set_target_properties(ATIDAQ::ATIDAQ PROPERTIES IMPORTED_LOCATION_RELEASE "${ATIDAQ_LIBRARY_RELEASE}")
	endif()
	
	if(ATIDAQ_LIBRARY_DEBUG)
		set_property(TARGET ATIDAQ::ATIDAQ APPEND PROPERTY IMPORTED_CONFIGURATIONS DEBUG)
		set_target_properties(ATIDAQ::ATIDAQ PROPERTIES IMPORTED_LOCATION_DEBUG "${ATIDAQ_LIBRARY_DEBUG}")
	endif()
	
	set_target_properties(
		ATIDAQ::ATIDAQ PROPERTIES
		INTERFACE_INCLUDE_DIRECTORIES "${ATIDAQ_INCLUDE_DIRS}"
	)
endif()
