##############################################################################
# @file  CMakeLists.txt
# @brief Build configuration of software.
#
# Copyright (c) 2012 University of Pennsylvania. All rights reserved.<br />
# See http://www.rad.upenn.edu/sbia/software/license.html or COPYING file.
#
# Contact: SBIA Group <sbia-software at uphs.upenn.edu>
##############################################################################

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

# Add library target for each library using basis_add_library().
#
# This command can not only be used to build libraries from C/C++, but also source
# code written in other programming languages such as Java, Python, Perl, BASH,
# and MATLAB. Note that here we consider modules written in a scripting language
# which are no executables but to be included by other scripts written in the
# particular language as libraries.

basis_add_library (odvbalib STATIC odvba-lib.cxx utilities.cxx)
basis_set_target_properties (
  odvbalib
  PROPERTIES
    OUTPUT_NAME odvba
)
basis_target_link_libraries (
  odvbalib
    ${NiftiCLib_LIB}
    ${BLAS_f77blas_LIBRARY}
    ${BLAS_cblas_LIBRARY}
    ${BLAS_atlas_LIBRARY}
    ${OpenCV_LIBS}
)

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

# Add executable target for each executable program using basis_add_executable().
#
# This command can not only be used to build executables from C/C++, but also
# source code written in other programming languages such as Java, Python, Perl,
# BASH, and MATLAB.

# to enable compatibility mode with BASIS 1.3 even though source files are
# updated to use BASIS 2 C++ utilities by default
if (BASIS_VERSION_MAJOR)
  basis_add_definitions(-DBASIS_VERSION_MAJOR=${BASIS_VERSION_MAJOR})
endif ()

# ----------------------------------------------------------------------------
# helper
macro (odvba_add_executable TGT)
  basis_add_executable(${TGT} ${ARGN})
  basis_target_link_libraries (${TGT} odvbalib)
endmacro ()

# ----------------------------------------------------------------------------
# index creation
odvba_add_executable (odvba-index odvba-index.cxx)

# ----------------------------------------------------------------------------
# neighborhood creation
odvba_add_executable (odvba-ni odvba-ni.cxx)

# ----------------------------------------------------------------------------
# main program
odvba_add_executable (odvba odvba.cxx)

if (MPI_FOUND)
  # program which utilizes MPI for parallelization
  odvba_add_executable (odvba-mpi odvba.cxx)
  basis_set_target_properties (
    odvba-mpi
    PROPERTIES
      COMPILE_DEFINITIONS "SBIA_ODVBA_USE_MPI=1"
      COMPILE_FLAGS       "${MPI_COMPILE_FLAGS}"
      LINK_FLAGS          "${MPI_LINK_FLAGS}"
  )
  basis_target_link_libraries (odvba-mpi ${MPI_LIBRARIES})
endif ()

# ----------------------------------------------------------------------------
# SBIA wrapper - for both odvba and odvba-mpi
basis_add_executable (odvba-sbia.sh)
