#File Generated by Hans J. Johnson
#Please contact hans-johnson@uiowa.edu for making enhancments/corrections
PROJECT(NIFTI)
# Configure Dart testing support.
INCLUDE(${CMAKE_ROOT}/Modules/Dart.cmake)

SUBDIRS(znzlib niftilib)
ADD_DEFINITIONS(-DHAVE_ZLIB)

# Set default shared library version
# This library version will be applied to all libraries in the package
# unless it is not explicitely for a certain lib.
IF (NOT DEFINED NIFTI_SHAREDLIB_VERSION)
  SET ( NIFTI_SHAREDLIB_VERSION 0.0.0 )
ENDIF (NOT DEFINED NIFTI_SHAREDLIB_VERSION)

# add option to build shared libraries. The default is OFF to maintain the
# current build behavior
OPTION ( BUILD_SHARED_LIBS "Toggle building shared libraries")

# Michael Hanke 2007-04-25 Note:
# 'Utilities' is merged into the include install path to be able to easily
# install into any other path if necessary. For the same reason lib, bin and
# include dir for standalone builds are only set if not yet defined.

###  USE AS PART OF ITK
IF("${ITK_VERSION_MAJOR}" GREATER 0.0)
  MESSAGE(STATUS "---------------------ITK ZLIB  ${ITK_ZLIB_LIBRARIES}")
  ADD_DEFINITIONS(-DHAVE_ZLIB)
  ADD_DEFINITIONS(-DITKZLIB)
  SET(PACKAGE_PREFIX "ITK")
  SET(NIFTI_INSTALL_BIN_DIR "${CMAKE_INSTALL_PREFIX}/${ITK_INSTALL_BIN_DIR}")
  SET(NIFTI_INSTALL_LIB_DIR "${CMAKE_INSTALL_PREFIX}/${ITK_INSTALL_LIB_DIR}")
  SET(NIFTI_INSTALL_INCLUDE_DIR "${CMAKE_INSTALL_PREFIX}/${ITK_INSTALL_INCLUDE_DIR}/Utilities")
  SET(NIFTI_ZLIB_LIBRARIES ${ITK_ZLIB_LIBRARIES})
  SET(NIFTI_INSTALL_NO_DEVELOPMENT ${ITK_INSTALL_NO_DEVELOPMENT})
  SET(NIFTI_INSTALL_NO_LIBRARIES ${ITK_INSTALL_NO_LIBRARIES})
ELSE("${ITK_VERSION_MAJOR}" GREATER 0.0)
###  USE AS STAND ALONE PACKAGE
   FIND_PACKAGE(ZLIB)
  MESSAGE(STATUS "---------------------SYSTEM ZLIB ${ZLIB_LIBRARY}")
  SET(PACKAGE_PREFIX "")
  SET(NIFTI_INSTALL_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib")
  SET(NIFTI_INSTALL_BIN_DIR "${CMAKE_INSTALL_PREFIX}/bin")
  SET(NIFTI_INSTALL_INCLUDE_DIR "${CMAKE_INSTALL_PREFIX}/include/nifti")
  SET(NIFTI_ZLIB_LIBRARIES ${ZLIB_LIBRARIES})
  SET(NIFTI_INSTALL_NO_DEVELOPMENT 0)
  SET(NIFTI_INSTALL_NO_LIBRARIES 0)

  #Needs an if clause and more work before testing can take place.
  SUBDIRS(Testing)
  SUBDIRS(nifticdf utils)

  OPTION(USE_FSL_CODE "If OFF, The copyright of this code is questionable for inclusion with nifti." OFF)
  MARK_AS_ADVANCED(USE_FSL_CODE)

  # the order of subdirs is important! fsliolob has to preceed examples
  # as otherwise FSLIOLIB_SOURCE_DIR is undefined and hence the examples
  # will fail to compile
  IF(USE_FSL_CODE)
    SUBDIRS(fsliolib)
    SUBDIRS(examples)
  ENDIF(USE_FSL_CODE)
  ENABLE_TESTING()
ENDIF("${ITK_VERSION_MAJOR}" GREATER 0.0)

IF(NOT DEFINED NIFTI_INSTALL_LIB_DIR)
  MESSAGE(FATAL_ERROR "Must set NIFTI_INSTALL_LIB_DIR.")
ENDIF(NOT DEFINED NIFTI_INSTALL_LIB_DIR)
IF(NOT DEFINED NIFTI_INSTALL_BIN_DIR)
  MESSAGE(FATAL_ERROR "Must set NIFTI_INSTALL_BIN_DIR.")
ENDIF(NOT DEFINED NIFTI_INSTALL_BIN_DIR)
IF(NOT DEFINED NIFTI_INSTALL_INCLUDE_DIR)
  MESSAGE(FATAL_ERROR "Must set NIFTI_INSTALL_INCLUDE_DIR.")
ENDIF(NOT DEFINED NIFTI_INSTALL_INCLUDE_DIR)

####################################
### Define information necessary for packaging with CPACK (http://www.cmake.org/Wiki/CMake:Packaging_With_CPack)
INCLUDE(InstallRequiredSystemLibraries)

SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Niftilib is a set of i/o libraries for reading and writing files in the nifti-1 data format. nifti-1 is a binary file format for storing medical image data, e.g. magnetic resonance image (MRI) and functional MRI (fMRI) brain images.")
SET(CPACK_PACKAGE_VENDOR "NIFTI DFWG")
SET(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README")
SET(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/README")
SET(CPACK_PACKAGE_VERSION_MAJOR "0")
SET(CPACK_PACKAGE_VERSION_MINOR "5")
SET(CPACK_PACKAGE_VERSION_PATCH "0")
SET(CPACK_PACKAGE_INSTALL_DIRECTORY "NIFTI ${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}")
INCLUDE(CPack)
