# CMakeFiles.txt for the minc-tools
#
# Andrew Janke - a.janke@gmail.com
# Vladimir S. FONOV - vladimir.fonov@gmail.com

PROJECT(minc-tools)

SET(MINC_TOOLS_PACKAGE_VERSION_MAJOR 2)
SET(MINC_TOOLS_PACKAGE_VERSION_MINOR 3)
SET(MINC_TOOLS_PACKAGE_VERSION_PATCH 01)
SET(PACKAGE "minc-tools")
SET(PACKAGE_BUGREPORT "a.janke@gmail.com")

SET(PACKAGE_NAME "minc-tools")
SET(PACKAGE_VERSION "${MINC_TOOLS_PACKAGE_VERSION_MAJOR}.${MINC_TOOLS_PACKAGE_VERSION_MINOR}.${MINC_TOOLS_PACKAGE_VERSION_PATCH}")
SET(PACKAGE_STRING  "${PACKAGE_NAME} ${PACKAGE_VERSION}")
ENABLE_TESTING()
INCLUDE(CTest)

CMAKE_MINIMUM_REQUIRED(VERSION 2.6)

IF(COMMAND CMAKE_POLICY)
  IF(POLICY CMP0026)
    CMAKE_POLICY(SET CMP0026 OLD) # NEEDED in testing to read location of target
  ENDIF(POLICY CMP0026)
ENDIF(COMMAND CMAKE_POLICY)

IF(MINC_TOOLKIT_BUILD)
  SET(MINC_TOOLS_EXTERNALLY_CONFIGURED ON)
ENDIF(MINC_TOOLKIT_BUILD)

IF(NOT MINC_TOOLS_EXTERNALLY_CONFIGURED)
  SET(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" "${CMAKE_CURRENT_SOURCE_DIR}/cmake-modules")
  
  SET(CPACK_GENERATOR TGZ)
  SET(CPACK_PACKAGE_VERSION_MAJOR ${MINC_TOOLS_PACKAGE_VERSION_MAJOR})
  SET(CPACK_PACKAGE_VERSION_MINOR ${MINC_TOOLS_PACKAGE_VERSION_MINOR})
  SET(CPACK_PACKAGE_VERSION_PATCH ${MINC_TOOLS_PACKAGE_VERSION_PATCH})
  
  INCLUDE(CPack)
  
  FIND_PACKAGE(LIBMINC REQUIRED)

ENDIF(NOT MINC_TOOLS_EXTERNALLY_CONFIGURED)

INCLUDE( ${LIBMINC_USE_FILE} )
INCLUDE( InstallManPages )
# check for prereqs
INCLUDE(CheckFunctionExists)

CHECK_FUNCTION_EXISTS(mkstemp  HAVE_MKSTEMP)
CHECK_FUNCTION_EXISTS(tmpnam   HAVE_TMPNAM)
CHECK_FUNCTION_EXISTS(tempnam  HAVE_TEMPNAM)
CHECK_FUNCTION_EXISTS(strerror HAVE_STRERROR)
CHECK_FUNCTION_EXISTS(popen    HAVE_POPEN)
CHECK_FUNCTION_EXISTS(fork     HAVE_WORKING_FORK)
CHECK_FUNCTION_EXISTS(vfork    HAVE_WORKING_VFORK)
CHECK_FUNCTION_EXISTS(fdopen   HAVE_FDOPEN)
CHECK_FUNCTION_EXISTS(strdup   HAVE_STRDUP)
CHECK_FUNCTION_EXISTS(getpwnam HAVE_GETPWNAM) 
CHECK_FUNCTION_EXISTS(select   HAVE_SELECT)
CHECK_FUNCTION_EXISTS(strerror HAVE_STRERROR) 
CHECK_FUNCTION_EXISTS(sysconf  HAVE_SYSCONF)
CHECK_FUNCTION_EXISTS(system   HAVE_SYSTEM)

INCLUDE(CheckIncludeFiles)
CHECK_INCLUDE_FILES(float.h     HAVE_FLOAT_H)
CHECK_INCLUDE_FILES(sys/dir.h   HAVE_SYS_DIR_H)
CHECK_INCLUDE_FILES(sys/ndir.h  HAVE_SYS_NDIR_H)
CHECK_INCLUDE_FILES(sys/stat.h  HAVE_SYS_STAT_H)
CHECK_INCLUDE_FILES(sys/types.h HAVE_SYS_TYPES_H)
CHECK_INCLUDE_FILES(sys/wait.h  HAVE_SYS_WAIT_H)
CHECK_INCLUDE_FILES(values.h    HAVE_VALUES_H)
CHECK_INCLUDE_FILES(unistd.h    HAVE_UNISTD_H)
CHECK_INCLUDE_FILES(dirent.h    HAVE_DIRENT_H)
CHECK_INCLUDE_FILES(memory.h    HAVE_MEMORY_H)
CHECK_INCLUDE_FILES(stdlib.h    HAVE_STDLIB_H)
CHECK_INCLUDE_FILES(fcntl.h     HAVE_FCNTL_H)
CHECK_INCLUDE_FILES(dlfcn.h     HAVE_DLFCN_H)
CHECK_INCLUDE_FILES(vfork.h     HAVE_VFORK_H)
CHECK_INCLUDE_FILES(inttypes.h  HAVE_INTTYPES_H)
CHECK_INCLUDE_FILES(string.h    HAVE_STRING_H)
CHECK_INCLUDE_FILES(strings.h   HAVE_STRINGS_H)
CHECK_INCLUDE_FILES(pwd.h       HAVE_PWD_H)

ADD_DEFINITIONS(-DHAVE_CONFIG_H)

# aliases
SET(VERSION "${PACKAGE_VERSION}")

# netcdf and HDF5

# config files for build
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h @ONLY)

# set the master INCLUDE directories
INCLUDE_DIRECTORIES(
  ${CMAKE_CURRENT_BINARY_DIR}
   )

ADD_SUBDIRECTORY( progs )
ADD_SUBDIRECTORY( conversion )

# testing
IF(BUILD_TESTING)
  ADD_SUBDIRECTORY( Testing )
ENDIF(BUILD_TESTING)
