###########################################################
#
# CMAKE FILE TO GENERATE libcudaamber.a 
# 
############################################################

find_package(CUDA)
set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS};-O3 -arch compute_35 -use_fast_math)

file( GLOB AMBER12_F_SOURCES ${SVN_ROOT}/AMBER12/*.F90 ${SVN_ROOT}/AMBER12/cuda/*.F90 )
file( GLOB AMBER12_C_SOURCES ${SVN_ROOT}/AMBER12/*.c ${SVN_ROOT}/AMBER12/cuda/*.cpp )

# we need fortran free-from flag
SET_SOURCE_FILES_PROPERTIES(${AMBER12CUDA_F_SOURCES}
  PROPERTIES
  COMPILE_FLAGS "${FORTRAN_FREEFORM_FLAG}"
)

# Full double precision
add_definitions(-Duse_DPDP -DCUDA)

set(INCDIR1 "${SVN_ROOT}/AMBER12/cuda/B40C")
set(INCDIR2 "/usr/local/cuda-5.5/targets/x86_64-linux/include")
cuda_include_directories(${INCDIR1})
include_directories(${INCDIR2})

file( GLOB CU_SOURCES ${SVN_ROOT}/AMBER12/cuda/*.cu)
cuda_compile(CU_COMP_SOURCES ${CU_SOURCES})

# build library of local sources (libcudaamber.a)  
add_library(cudaamber12 ${AMBER12_F_SOURCES} ${AMBER12_C_SOURCES} ${HEADERS_COPIED} ${CU_COMP_SOURCES})
ADD_DEPENDENCIES(cudaamber12 gminlib)

target_link_libraries (cudaamber12 /usr/local/cuda-5.5/targets/x86_64-linux/lib/libcurand.so)
CUDA_ADD_CUFFT_TO_TARGET(cudaamber12)
