
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)


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

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(first_aligned)
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(integer_types)
ei_add_test(cwiseop)
ei_add_test(unalignedcount)
ei_add_test(exceptions)
ei_add_test(redux)
ei_add_test(visitor)
ei_add_test(block)
ei_add_test(corners)
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(diagonal)
ei_add_test(miscmatrices)
ei_add_test(commainitializer)
ei_add_test(smallvectors)
ei_add_test(map)
ei_add_test(mapstride)
ei_add_test(mapstaticmethods)
ei_add_test(array)
ei_add_test(array_for_matrix)
ei_add_test(array_replicate)
ei_add_test(array_reverse)
ei_add_test(triangular)
ei_add_test(selfadjoint)
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_trsolve)
ei_add_test(product_mmtr)
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(upperbidiagonalization)
ei_add_test(hessenberg)
ei_add_test(schur_real)
ei_add_test(schur_complex)
ei_add_test(eigensolver_selfadjoint "" "${GSL_LIBRARIES}")
ei_add_test(eigensolver_generic "" "${GSL_LIBRARIES}")
ei_add_test(eigensolver_complex)
ei_add_test(jacobi)
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(stdvector)
ei_add_test(stdvector_overload)
ei_add_test(stdlist)
ei_add_test(stddeque)
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(eigen2support)
ei_add_test(nullary)
ei_add_test(nesting_ops "${CMAKE_CXX_FLAGS_DEBUG}")
ei_add_test(zerosized)
ei_add_test(dontalign)
ei_add_test(sizeoverflow)
ei_add_test(prec_inverse_4x4)

string(TOLOWER "${CMAKE_CXX_COMPILER}" cmake_cxx_compiler_tolower)
if(cmake_cxx_compiler_tolower MATCHES "qcc")
  set(CXX_IS_QCC "ON")
endif()

ei_add_property(EIGEN_TESTING_SUMMARY "CXX:               ${CMAKE_CXX_COMPILER}\n")
if(CMAKE_COMPILER_IS_GNUCXX AND NOT CXX_IS_QCC)
  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()
ei_add_property(EIGEN_TESTING_SUMMARY "CXX_FLAGS:         ${CMAKE_CXX_FLAGS}\n")
ei_add_property(EIGEN_TESTING_SUMMARY "Sparse lib flags:  ${SPARSE_LIBS}\n")

option(EIGEN_TEST_EIGEN2 "Run whole Eigen2 test suite against EIGEN2_SUPPORT" OFF)
if(EIGEN_TEST_EIGEN2)
  add_subdirectory(eigen2)
endif()
