project(EigenTesting)
add_custom_target(buildtests)
add_custom_target(check COMMAND "ctest")
add_dependencies(check buildtests)

option(EIGEN_SPLIT_LARGE_TESTS "Split large tests into smaller executables" ON)

find_package(GSL)
if(GSL_FOUND AND GSL_VERSION_MINOR LESS 9)
  set(GSL_FOUND "")
endif(GSL_FOUND AND GSL_VERSION_MINOR LESS 9)
if(GSL_FOUND)
  add_definitions("-DHAS_GSL" ${GSL_DEFINITIONS})
  include_directories(${GSL_INCLUDE_DIR})
  ei_add_property(EIGEN_TESTED_BACKENDS "GSL, ")
else(GSL_FOUND)
  ei_add_property(EIGEN_MISSING_BACKENDS "GSL, ")
  set(GSL_LIBRARIES " ")
endif(GSL_FOUND)

set(SPARSE_LIBS "")

find_package(Taucs)
if(TAUCS_FOUND)
  add_definitions("-DEIGEN_TAUCS_SUPPORT")
  include_directories(${TAUCS_INCLUDES})
  set(SPARSE_LIBS ${SPARSE_LIBS} ${TAUCS_LIBRARIES})
  ei_add_property(EIGEN_TESTED_BACKENDS "Taucs, ")
else(TAUCS_FOUND)
  ei_add_property(EIGEN_MISSING_BACKENDS "Taucs, ")
endif(TAUCS_FOUND)

find_package(Cholmod)
if(CHOLMOD_FOUND)
  add_definitions("-DEIGEN_CHOLMOD_SUPPORT")
  include_directories(${CHOLMOD_INCLUDES})
  set(SPARSE_LIBS ${SPARSE_LIBS} ${CHOLMOD_LIBRARIES})
  ei_add_property(EIGEN_TESTED_BACKENDS "Cholmod, ")
else(CHOLMOD_FOUND)
  ei_add_property(EIGEN_MISSING_BACKENDS "Cholmod, ")
endif(CHOLMOD_FOUND)

find_package(Umfpack)
if(UMFPACK_FOUND)
  add_definitions("-DEIGEN_UMFPACK_SUPPORT")
  include_directories(${UMFPACK_INCLUDES})
  set(SPARSE_LIBS ${SPARSE_LIBS} ${UMFPACK_LIBRARIES})
  ei_add_property(EIGEN_TESTED_BACKENDS "UmfPack, ")
else(UMFPACK_FOUND)
  ei_add_property(EIGEN_MISSING_BACKENDS "UmfPack, ")
endif(UMFPACK_FOUND)

find_package(SuperLU)
if(SUPERLU_FOUND)
  add_definitions("-DEIGEN_SUPERLU_SUPPORT")
  include_directories(${SUPERLU_INCLUDES})
  set(SPARSE_LIBS ${SPARSE_LIBS} ${SUPERLU_LIBRARIES})
  ei_add_property(EIGEN_TESTED_BACKENDS  "SuperLU, ")
else(SUPERLU_FOUND)
  ei_add_property(EIGEN_MISSING_BACKENDS  "SuperLU, ")
endif(SUPERLU_FOUND)

find_package(GoogleHash)
if(GOOGLEHASH_FOUND)
  add_definitions("-DEIGEN_GOOGLEHASH_SUPPORT")
  include_directories(${GOOGLEHASH_INCLUDES})
  ei_add_property(EIGEN_TESTED_BACKENDS  "GoogleHash, ")
else(GOOGLEHASH_FOUND)
  ei_add_property(EIGEN_MISSING_BACKENDS  "GoogleHash, ")
endif(GOOGLEHASH_FOUND)

option(EIGEN_TEST_NOQT "Disable Qt support in unit tests" OFF)
if(NOT EIGEN_TEST_NOQT)
  find_package(Qt4)
endif(NOT EIGEN_TEST_NOQT)
if(QT4_FOUND)
  include(${QT_USE_FILE})
  ei_add_property(EIGEN_TESTED_BACKENDS  "Qt4 support, ")
else(QT4_FOUND)
  ei_add_property(EIGEN_MISSING_BACKENDS  "Qt4 support, ")
endif(QT4_FOUND)

if(TEST_LIB)
  add_definitions("-DEIGEN_EXTERN_INSTANTIATIONS=1")
endif(TEST_LIB)

ei_add_test(meta)
ei_add_test(sizeof)
ei_add_test(dynalloc)
ei_add_test(nomalloc)
ei_add_test(mixingtypes)
ei_add_test(packetmath)
ei_add_test(unalignedassert)
ei_add_test(vectorization_logic)
ei_add_test(basicstuff)
ei_add_test(linearstructure)
ei_add_test(cwiseop)
ei_add_test(redux)
ei_add_test(visitor)
ei_add_test(product_small)
ei_add_test(product_large)
ei_add_test(product_extra)
ei_add_test(diagonalmatrices)
ei_add_test(adjoint)
ei_add_test(submatrices)
ei_add_test(miscmatrices)
ei_add_test(commainitializer)
ei_add_test(smallvectors)
ei_add_test(map)
ei_add_test(array)
ei_add_test(array_replicate)
ei_add_test(array_reverse)
ei_add_test(triangular)
ei_add_test(product_selfadjoint)
ei_add_test(product_symm)
ei_add_test(product_syrk)
ei_add_test(product_trmv)
ei_add_test(product_trmm)
ei_add_test(product_trsm)
ei_add_test(product_notemporary)
ei_add_test(stable_norm)
ei_add_test(bandmatrix)
ei_add_test(cholesky " " "${GSL_LIBRARIES}")
ei_add_test(lu)
ei_add_test(determinant)
ei_add_test(inverse)
ei_add_test(qr)
ei_add_test(qr_colpivoting)
ei_add_test(qr_fullpivoting)
ei_add_test(eigensolver_selfadjoint " " "${GSL_LIBRARIES}")
ei_add_test(eigensolver_generic " " "${GSL_LIBRARIES}")
ei_add_test(eigensolver_complex)
ei_add_test(svd)
ei_add_test(jacobisvd)
ei_add_test(geo_orthomethods)
ei_add_test(geo_homogeneous)
ei_add_test(geo_quaternion)
ei_add_test(geo_transformations)
ei_add_test(geo_eulerangles)
ei_add_test(geo_hyperplane)
ei_add_test(geo_parametrizedline)
ei_add_test(geo_alignedbox)
ei_add_test(regression)
ei_add_test(stdvector)
ei_add_test(resize)
if(QT4_FOUND)
  ei_add_test(qtvector " " "${QT_QTCORE_LIBRARY}")
endif(QT4_FOUND)
ei_add_test(sparse_vector)
ei_add_test(sparse_basic)
ei_add_test(sparse_product)
ei_add_test(sparse_solvers " " "${SPARSE_LIBS}")
ei_add_test(umeyama)
ei_add_test(householder)
ei_add_test(swap)
ei_add_test(conservative_resize)
ei_add_test(permutationmatrices)

ei_add_test(prec_inverse_4x4)

ei_add_property(EIGEN_TESTING_SUMMARY "CXX:               ${CMAKE_CXX_COMPILER}\n")
if(CMAKE_COMPILER_IS_GNUCXX)
  execute_process(COMMAND ${CMAKE_CXX_COMPILER} --version COMMAND head -n 1 OUTPUT_VARIABLE EIGEN_CXX_VERSION_STRING OUTPUT_STRIP_TRAILING_WHITESPACE)
  ei_add_property(EIGEN_TESTING_SUMMARY "CXX_VERSION:       ${EIGEN_CXX_VERSION_STRING}\n")
endif(CMAKE_COMPILER_IS_GNUCXX)
ei_add_property(EIGEN_TESTING_SUMMARY "CXX_FLAGS:         ${CMAKE_CXX_FLAGS}\n")
ei_add_property(EIGEN_TESTING_SUMMARY "Sparse lib flags:  ${SPARSE_LIBS}\n")
