##############################################################################
# \file  CMakeLists.txt
# \brief CMakeLists file to configure build system of all targets.
#
# For copyright information please see Copyright.txt in the root
# directory of the project.
#
# Contact: SBIA Group <sbia-software@uphs.upenn.edu>
##############################################################################

# ============================================================================
# helper variables
# ============================================================================

set (LINK_LIBRARIES
  ${NiftiCLib_LIB}
  ${OpenCV_LIBS}
  ${CBLAS_LIB}
  ${ATLAS_LIB}
)

# ============================================================================
# library target(s)
# ============================================================================

# Add library target for each static or shared library (including MEX-files)
# using the macro sbia_add_library (). Note that the maco sbia_add_library ()
# is used the same way as the CMake command add_library ().
#
# See documentation of sbia_add_executable in SbiaMacros.cmake for details.
#
# \see sbia_add_library ()
# \see http://www.cmake.org/cmake/help/cmake-2-8-docs.html#command:add_library

# ----------------------------------------------------------------------------
# common sources
# ----------------------------------------------------------------------------

set (ODVBA_SOURCES
  SbiaOdvbaUtilities.h
  SbiaOdvbaUtilities.cpp
  SbiaOdvbaAlgorithm.h
  SbiaOdvbaAlgorithm.cpp
)

source_group ("ODVBA" FILES ${ODVBA_SOURCES})

# ============================================================================
# executable target(s)
# ============================================================================

# Add executable target for each executable program using the macro
# sbia_add_executable () which is used just the same way as the CMake command
# add_executable () is used.
#
# The source_group () command can be used to group source files within IDEs
# such as the Microsoft Visual Studio IDE, in particular.
#
# See documentation of sbia_add_executable in SbiaMacros.cmake for details.
#
# \see sbia_add_executable ()
# \see http://www.cmake.org/cmake/help/cmake-2-8-docs.html#command:add_executable
# \see http://www.cmake.org/cmake/help/cmake-2-8-docs.html#command:source_group

# ----------------------------------------------------------------------------
# common sources
# ----------------------------------------------------------------------------

set (AUXILIARY_SOURCES
  MainAux.h
)

set (COMMON_SOURCES
  ${ODVBA_SOURCES}
  ${AUXILIARY_SOURCES}
  ${SBIA_TEMPLATE_SOURCES}
  ${SBIA_DEFAULT_SOURCES}
)

source_group ("Main" FILES ${AUXILIARY_SOURCES})
source_group ("Main" FILES CreateIndex.cpp)
source_group ("Main" FILES CreateNI.cpp)
source_group ("Main" FILES Main.cpp)

# ----------------------------------------------------------------------------
# target: OdvbaCreateIndex - index creation
# ----------------------------------------------------------------------------

sbia_add_executable (OdvbaCreateIndex CreateIndex.cpp ${COMMON_SOURCES})

target_link_libraries (OdvbaCreateIndex ${LINK_LIBRARIES})

# ----------------------------------------------------------------------------
# target: OdvbaCreateNI - neighborhood creation
# ----------------------------------------------------------------------------

sbia_add_executable (OdvbaCreateNI CreateNI.cpp ${COMMON_SOURCES})

target_link_libraries (OdvbaCreateNI ${LINK_LIBRARIES})

# ----------------------------------------------------------------------------
# target: Odvba - main program
# ----------------------------------------------------------------------------

sbia_add_executable (Odvba Main.cpp ${COMMON_SOURCES})

set_target_properties (
  Odvba
  PROPERTIES
    COMPILE_FLAGS "-DSBIA_ODVBA_USE_MPI=0"
)

target_link_libraries (Odvba ${LINK_LIBRARIES})

# ----------------------------------------------------------------------------
# target: OdvbaMPI - main program (parallel processing)
# ----------------------------------------------------------------------------

if (MPI_FOUND)


sbia_add_executable (OdvbaMPI Main.cpp ${COMMON_SOURCES})

set_target_properties (
  OdvbaMPI
  PROPERTIES
    COMPILE_FLAGS "-DSBIA_ODVBA_USE_MPI=1"
)

target_link_libraries (OdvbaMPI ${LINK_LIBRARIES} ${MPI_LIBRARIES})


endif ()

# ============================================================================
# scripts
# ============================================================================

# Use the macro sbia_add_script () to add scripts to the project.
#
# For convenience, the functions sbia_add_scripts_by_extension () and
# sbia_add_scripts_by_extensions () add all scripts within the current
# source directory with the given extension(s). The filenames of the scripts
# may contain an optional ".in" suffix or ".in." as any part of the name.
#
# Moreover, sbia_add_scripts () adds all scripts of common scripting languages
# given that the usual filename extensions are used. Hence, in most cases,
# the calling sbia_add_scripts () is sufficient.
#
# See documentation of these macros in SbiaMacros.cmake for details.
#
# \see sbia_add_script
# \see sbia_add_scripts_by_extension
# \see sbia_add_scripts_by_extensions
# \see sbia_add_scripts

if (MPI_FOUND)
  sbia_add_script (OdvbaMPIOnSGE.sh)
endif ()
