# -*- mode: cmake -*-

#
#  Amanzi
#   Solvers
#

# Amanzi module, include files found in AMANZI_MODULE_PATH
include(PrintVariable)
include(TestManager)

#
# Define a project name
# After this command the following varaibles are defined
#   SOLVERS_SOURCE_DIR
#   SOLVERS_BINARY_DIR
# Other projects (subdirectories) can reference this directory
# through these variables.
project(SOLVERS)

# Amanzi include directories
include_directories(${DBC_SOURCE_DIR})
include_directories(${ATK_SOURCE_DIR})
include_directories(${DBG_SOURCE_DIR})
include_directories(${WHETSTONE_SOURCE_DIR})

# External (TPL) include directories
include_directories(${Teuchos_INCLUDE_DIRS})
include_directories(${Epetra_INCLUDE_DIRS})
include_directories(${NOX_INCLUDE_DIRS})

#
# Library: solvers
#
file(GLOB solvers_inc_files "*.hh")
set(solvers_source_files PreconditionerFactory.cc PreconditionerBoomerAMG.cc PreconditionerML.cc
                         PreconditionerEuclid.cc PreconditionerBlockILU.cc)

set(solvers_tpl_libs ${DBC_LIBRARIES} ${Teuchos_LIBRARIES} ${Epetra_LIBRARIES} ${NOX_LIBRARIES})
list(REVERSE solvers_tpl_libs)
list(REMOVE_DUPLICATES solvers_tpl_libs)
list(REVERSE solvers_tpl_libs)
add_amanzi_library(solvers
                   SOURCE ${solvers_source_files} 
                   HEADERS ${solvers_inc_files}
                   LINK_LIBS error_handling ${solvers_tpl_libs})

if (BUILD_TESTS)
    # Add UnitTest include directoy
    include_directories(${UnitTest_INCLUDE_DIRS})

    # Copy test directory files if an out of source build
    if (NOT (${SOLVERS_SOURCE_DIR} EQUAL ${SOLVERS_BINARY_DIR}))
        execute_process(COMMAND ${CMAKE_COMMAND} -E
          copy_directory ${SOLVERS_SOURCE_DIR}/test ${SOLVERS_BINARY_DIR}/test)
    endif()

    # Add the time_integration directory to the include paths
    include_directories(${SOLVERS_SOURCE_DIR})

    add_amanzi_test(solver_linear_operators solver_linear_operators
                    KIND unit
                    SOURCE test/Main.cc test/solver_linear_operators.cc
                    LINK_LIBS error_handling whetstone atk ${UnitTest_LIBRARIES} ${solvers_tpl_libs})

    add_amanzi_test(solver_preconditioners solver_preconditioners
                    KIND unit
                    SOURCE test/Main.cc test/solver_preconditioners.cc
                    LINK_LIBS error_handling solvers whetstone atk ${UnitTest_LIBRARIES} ${solvers_tpl_libs})

    add_amanzi_test(solver_linear_jfnk solver_linear_jfnk
                    KIND unit
                    SOURCE test/Main.cc test/solver_linear_jfnk.cc
                    LINK_LIBS error_handling whetstone atk ${UnitTest_LIBRARIES} ${solvers_tpl_libs})

    add_amanzi_test(solver_nka solver_nka
                    KIND unit
                    SOURCE test/Main.cc test/solver_nka.cc
                    LINK_LIBS error_handling whetstone atk ${UnitTest_LIBRARIES} ${solvers_tpl_libs})

    add_amanzi_test(solver_continuation solver_continuation
                    KIND unit
                    SOURCE test/Main.cc test/solver_continuation.cc
                    LINK_LIBS error_handling whetstone atk ${UnitTest_LIBRARIES} ${solvers_tpl_libs})
endif()
