#TODO Make into a function/module
find_library(FFTW_LIB fftw3)
find_library(FFTW_THREADS_LIB fftw3_threads)
if(FlOATFFT)
	find_library(FFTWF_LIB fftw3f)
	find_library(FFTWF_THREADS_LIB fftw3f_threads)
endif()
find_path(FFTW_INCLUDES fftw3.h)
if(FlOATFFT)
	set(FFTW_LIBRARIES ${FFTW_THREADS_LIB} ${FFTWF_THREADS_LIB})
else()
	set(FFTW_LIBRARIES ${FFTW_THREADS_LIB})
endif()

if(MPI)
	find_library(FFTW_MPI_LIB fftw3_mpi)
	if(FlOATFFT)
		find_library(FFTWF_MPI_LIB fftw3f_mpi)
		set(FFTW_LIBRARIES ${FFTW_LIBRARIES} ${FFTW_MPI_LIB} ${FFTWF_MPI_LIB})
	else()
		set(FFTW_LIBRARIES ${FFTW_LIBRARIES} ${FFTW_MPI_LIB} )
	endif()
endif()
if(FlOATFFT)
	set(FFTW_LIBRARIES ${FFTW_LIBRARIES} ${FFTW_LIB} ${FFTWF_LIB})
else()
	set(FFTW_LIBRARIES ${FFTW_LIBRARIES} ${FFTW_LIB} )
endif()

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(FFTW DEFAULT_MSG
                                  FFTW_INCLUDES FFTW_LIBRARIES)

if(FlOATFFT)
	mark_as_advanced(FFTW_INCLUDES FFTW_LIBRARIES FFTW_LIB FFTWF_LIB FFTWL_LIB)
else()
	mark_as_advanced(FFTW_INCLUDES FFTW_LIBRARIES FFTW_LIB FFTWL_LIB)
endif()

