#    Copyright (C) 2016 University of the Basque Country, UPV/EHU.
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.

cmake_minimum_required( VERSION 2.8 )
project( dev_testsuite )

set( TESTSUITE_NAME dev_testsuite )

set( TEST_SRC "src/test.cpp")
foreach( FILE ${SRC_BASE} )
	if( EXISTS "${PROJECT_SOURCE_DIR}/${FILE}" )
		list( APPEND TEST_SRC "${PROJECT_SOURCE_DIR}/${FILE}" )
	else( EXISTS "${PROJECT_SOURCE_DIR}/${FILE}" )
		set( SOURCE_FILE "${cuPoisson_SOURCE_DIR}/${FILE}" ) # Needed in test.h.in.
		configure_file( "${PROJECT_SOURCE_DIR}/src/test.h.in"
		                "${PROJECT_BINARY_DIR}/${FILE}" )
		list( APPEND TEST_SRC "${PROJECT_BINARY_DIR}/${FILE}" )
	endif( EXISTS "${PROJECT_SOURCE_DIR}/${FILE}" )
endforeach( FILE ${SRC_BASE} )

set( SRC "" )
include( ../multi_mod.CMake )

if( MOD_SERIAL )
	foreach( file ${MULTI_SRC_SERIAL} )
		add_suffix_to_filename( "ser" ${file} )
		if( EXISTS "${PROJECT_SOURCE_DIR}/${DERIVED_FILE}" )
			list( APPEND TEST_SRC "${PROJECT_SOURCE_DIR}/${DERIVED_FILE}" )
		else( EXISTS "${PROJECT_SOURCE_DIR}/${DERIVED_FILE}" )
			set( SOURCE_FILE "${PROJECT_BINARY_DIR}/multi_mod/${DERIVED_FILE}" ) # Needed in test.h.in.
			configure_file( "${PROJECT_SOURCE_DIR}/src/test.h.in"
			                "${PROJECT_BINARY_DIR}/${DERIVED_FILE}" )
			list( APPEND TEST_SRC "${PROJECT_BINARY_DIR}/${DERIVED_FILE}" )
		endif( EXISTS "${PROJECT_SOURCE_DIR}/${DERIVED_FILE}" )
	endforeach( file ${MULTI_SRC_SERIAL} )
endif( MOD_SERIAL )

include_directories( "${PROJECT_BINARY_DIR}/multi_mod/src" )
include_directories( "${PROJECT_SOURCE_DIR}/src" )
include_directories( "${testsuite_SOURCE_DIR}/src" ) # To include test.h

cuda_add_executable( ${TESTSUITE_NAME} ${TEST_SRC} )
target_link_libraries( ${TESTSUITE_NAME} ${CUDA_cufft_LIBRARY} )
if( MOD_MPI )
	target_link_libraries( ${TESTSUITE_NAME} ${MPI_C_LIBRARIES} )
endif( MOD_MPI )

add_test( distribute_blocks "${TESTSUITE_NAME}" "src/utils/utils.cu" "distribute_blocks" )
add_test( daddvv "${TESTSUITE_NAME}" "src/utils/alg.cu" "daddvv" )
add_test( dsubvv "${TESTSUITE_NAME}" "src/utils/alg.cu" "dsubvv" )
add_test( dnorm2v "${TESTSUITE_NAME}" "src/utils/alg.cu" "dnorm2v" )
add_test( ddotp "${TESTSUITE_NAME}" "src/utils/alg.cu" "ddotp" )
add_test( dsaddvv "${TESTSUITE_NAME}" "src/utils/alg.cu" "dsaddvv" )
add_test( dssubvv "${TESTSUITE_NAME}" "src/utils/alg.cu" "dssubvv" )
add_test( dscalv "${TESTSUITE_NAME}" "src/utils/alg.cu" "dscalv" )
add_test( copy_grid "${TESTSUITE_NAME}" "src/core/grid.c" "copy_grid" )
if( MOD_SERIAL )
	add_test( init_fft_solver   "${TESTSUITE_NAME}" "src/solvers/fft_ser.cu" "init_fft_solver" )
	add_test( solve_poisson_in_GPU   "${TESTSUITE_NAME}" "src/solvers/fft_utils_ser.cu" "solve_poisson_in_GPU" )
	add_test( cup_create_solver "${TESTSUITE_NAME}" "src/solvers/solver_ser.cu" "cup_create_solver" )
endif( MOD_SERIAL )
