# -*- mode: cmake -*-

#
#  Amanzi
#    Sample CMakeLists.txt file
#

#
#   The Amanzi project uses CMake (www.cmake.org) to build 
# Amanzi libraries and binaries. This file is a sample
# CMakeLists.txt file that cmake parses and interpets to
# generate UNIX Makefiles, Eclipse and KDevelop3 project
# files, and Xcode files.
#  
#   A CMakeLists.txt file must exist in any directory that
# has been added by a add_subdirectory call in a parent
# directory CMakeLists.txt file.
#
#   See AmanziCMakeTips.pdf for more information on the 
# Amanzi build system.



# Amanzi module, include files found in AMANZI_MODULE_PATH
#  PrintVariable useful debugging macro print_variable that 
#  prints variables out during cmake execution. 
#  AddParallelTest adds the function add_parallel_test
#  that should be used to add parallel tests. See 
#  AddParallelTest for more information.
#  Other CMake macros or functions that are needed in this
#  CMakeLists.txt file should be added here. 
include(PrintVariable)
include(AddParallelTest)

#
# Define a project name
# After this command the following variables are defined
#   XXX_SOURCE_DIR
#   XXX_BINARY_DIR
# Other projects (subdirectories) can reference this directory
# through these variables.
project(XXX)


# Define include directories to build any binary or library
# in this directory. 

# Amanzi include directories
#   Any CMakeLists.txt file that contains a project(YYY)
# command will define YYY_SOURCE_DIR (source directory location)
# YYY_BINARY_DIR (build directory location). Use these variables
# to locate header files.
include_directories(${DBC_SOURCE_DIR})
include_directories(${ATK_SOURCE_DIR})
include_directories(${MESH_SOURCE_DIR})
include_directories(${MESH_BASE_SOURCE_DIR})
include_directories(${MESH_DATA_SOURCE_DIR})
include_directories(${OUTPUT_SOURCE_DIR})
include_directories(${STATE_SOURCE_DIR})
include_directories(${CHEM_SOURCE_DIR})
include_directories(${TRANSPORT_SOURCE_DIR})
include_directories(${FLOW_SOURCE_DIR})

# Chemistry includes directory -- An example of using a global property
#   CMake is a scoped language. Variables defined in this file
# are not visible to parent files or other parts of the build
# system unless specifically defined as GLOBAL (All Amanzi build)
# or PARENT_SCOPE (defined for the parent scope). This is an
# example of retrieving a global property. The call queries 
# the global property CHEM_INCLUDES_DIR and set the local variable
# CHEM_INCLUDE_DIR to its value. For this call to work, there
# must be a corresponding set_property call in a directory that
# is processed BEFORE this directory.
get_property(CHEM_INCLUDES_DIR GLOBAL PROPERTY CHEM_INCLUDES_DIR)
include_directories(${CHEM_INCLUDES_DIR})

# External (TPL) include directories
#   External software libraries are called Third Party Libraries
# (TPL). Each TPL has either a TPLConfig.cmake or FindTPL.cmake
# file that defines TPL_INCLUDE_DIRS and TPL_LIBRARIES along
# with other useful variables. Use the plural form of INCLUDE_DIRS
# and LIBRARIES to include dependent libraries and include directories.
include_directories(${Boost_INCLUDE_DIRS})
include_directories(${Teuchos_INCLUDE_DIRS})
include_directories(${Epetra_INCLUDE_DIRS})

# Need to move this up to the root -- lpritch
#   Add a definition to the compile line. Before
# adding a definition, PLEASE verify that it
# has not been included in a previous CMakeLists.txt file.
add_definitions("-DUSE_MPI")


#
# Library: xxx
#
#  Steps to create a library target
#  (1) add_library(target_name [list of files to build target_name])
#  (2) Define the targets that are required to link against this library
#      Only include targets that the library calls directly. Do not
#      include all the dependencies! Let CMake do that for you with the
#      target_link_libraries call. If the build breaks when linking against
#      this library with unresolved symbols, there is a bug in the build
#      system and it needs to be reported and fixed. See AmanziCmakeTips.pdf
#      for more information.
add_library(xxx XXX.cpp)
set(xxx_tpl_libs ${Boost_LIBRARIES} ${Teuchos_LIBRARIES} ${Epetra_LIBRARIES})
list(REMOVE_DUPLICATES xxx_tpl_libs) # Concerned about command line length! --lpritch
target_link_libraries(xxx output state simple_mesh mesh_data cell_geometry ${xxx_tpl_libs})


# Define all tests at the of the file. BUILD_TESTS gates test building.
if (BUILD_TESTS)
    
    # Add UnitTest includes
    include_directories(${UnitTest_INCLUDE_DIRS})

    # Add XXX include directory. Need to remove this required path. -- lpritch
    include_directories(${XXX_SOURCE_DIR})

    # Copy test subdirectory for out of source builds
    if (NOT (XXX_SOURCE_DIR STREQUAL XXX_BINARY_DIR))
        execute_process(COMMAND ${CMAKE_COMMAND} -E 
          copy_directory ${XXX_SOURCE_DIR}/test ${XXX_BINARY_DIR}/test) 
    endif()

   
    # Example: Adding a unit test
    # Use add_parallel_test if the test needs to be run in parallel  
    if ( ENABLE_MOAB_Mesh )
        include_directories(${MOAB_SOURCE_DIR})
        include_directories(${MOAB_INCLUDE_DIRS})

        # Test: xxx-moab
        add_executable(test_xxx_moab test/Main.cc test/test_driver.cpp)
        target_link_libraries(test_xxx_moab xxx moab_mesh chemistry transport flow ${UnitTest_LIBRARIES})
        add_test(xxx-moab test_xxx_moab)
    
    endif()

endif()
