PROJECT(D4CMTK)

##
##  Copyright 2004-2012 SRI International
##
##  This file is part of the Computational Morphometry Toolkit.
##
##  http://www.nitrc.org/projects/cmtk/
##
##  The Computational Morphometry Toolkit is free software: you can
##  redistribute it and/or modify it under the terms of the GNU General Public
##  License as published by the Free Software Foundation, either version 3 of
##  the License, or (at your option) any later version.
##
##  The Computational Morphometry Toolkit is distributed in the hope that it
##  will be useful, but WITHOUT ANY WARRANTY; without even the implied
##  warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
##  GNU General Public License for more details.
##
##  You should have received a copy of the GNU General Public License along
##  with the Computational Morphometry Toolkit.  If not, see
##  <http://www.gnu.org/licenses/>.
##
##  $Revision: 4596 $
##      
##  $LastChangedDate: 2012-11-12 15:30:14 -0800 (Mon, 12 Nov 2012) $
##
##  $LastChangedBy: torsten_at_home $
##      

SET(DCMTK_PREFIX ${CMAKE_BINARY_DIR})
SET(DCM_DICT_DEFAULT_PATH "/dicom.dic;${DCMTK_PREFIX}/lib/dicom.dic;${CMTK_INSTALL_DATA_DIR}/dicom.dic")

SET(WITH_ZLIB 1)

IF(CMTK_USE_SMP)
  SET(WITH_THREADS 1)
ENDIF(CMTK_USE_SMP)

INCLUDE (${CMAKE_ROOT}/Modules/CMakeBackwardCompatibilityC.cmake)
INCLUDE (${CMAKE_ROOT}/Modules/CMakeBackwardCompatibilityCXX.cmake)

CHECK_TYPE_SIZE(int64_t HAVE_INT64_T)
CHECK_TYPE_SIZE(uint64_t HAVE_UINT64_T)

CHECK_INCLUDE_FILE_CXX (sstream HAVE_SSTREAM)
CHECK_INCLUDE_FILE_CXX (strstream HAVE_STRSTREAM)
CHECK_INCLUDE_FILE_CXX (sstream.h HAVE_SSTREAM_H)
CHECK_INCLUDE_FILE_CXX (strstrea.h HAVE_STRSTREA_H)
CHECK_INCLUDE_FILE_CXX (strstream.h HAVE_STRSTREAM_H)
CHECK_INCLUDE_FILE_CXX (alloca.h HAVE_ALLOCA_H)
CHECK_INCLUDE_FILE_CXX (arpa/inet.h HAVE_ARPA_INET_H)
CHECK_INCLUDE_FILE_CXX (assert.h HAVE_ASSERT_H)
CHECK_INCLUDE_FILE_CXX (ctype.h HAVE_CTYPE_H)
CHECK_INCLUDE_FILE_CXX (dirent.h HAVE_DIRENT_H)
CHECK_INCLUDE_FILE_CXX (errno.h HAVE_ERRNO_H)
CHECK_INCLUDE_FILE_CXX (fcntl.h HAVE_FCNTL_H)
CHECK_INCLUDE_FILE_CXX (float.h HAVE_FLOAT_H)
CHECK_INCLUDE_FILE_CXX (fnmatch.h HAVE_FNMATCH_H)
CHECK_INCLUDE_FILE_CXX (fstream HAVE_FSTREAM)
CHECK_INCLUDE_FILE_CXX (fstream.h HAVE_FSTREAM_H)
CHECK_INCLUDE_FILE_CXX (grp.h HAVE_GRP_H)
CHECK_INCLUDE_FILE_CXX (ieeefp.h HAVE_IEEEFP_H)
CHECK_INCLUDE_FILE_CXX (inttypes.h HAVE_INTTYPES_H)
CHECK_INCLUDE_FILE_CXX (iomanip HAVE_IOMANIP)
CHECK_INCLUDE_FILE_CXX (iomanip.h HAVE_IOMANIP_H)
CHECK_INCLUDE_FILE_CXX (iostream HAVE_IOSTREAM)
CHECK_INCLUDE_FILE_CXX (iostream.h HAVE_IOSTREAM_H)
CHECK_INCLUDE_FILE_CXX (io.h HAVE_IO_H)
CHECK_INCLUDE_FILE_CXX (iso646.h HAVE_ISO646_H)
CHECK_INCLUDE_FILE_CXX (libc.h HAVE_LIBC_H)
IF(HAVE_LIBC_H)
  SET(INCLUDE_LIBC_H_AS_CXX 1)
ELSE(HAVE_LIBC_H)
  CHECK_INCLUDE_FILE (libc.h HAVE_LIBC_H)
ENDIF(HAVE_LIBC_H)

CHECK_INCLUDE_FILE_CXX (libpng/png.h HAVE_LIBPNG_PNG_H)
CHECK_INCLUDE_FILE_CXX (limits.h HAVE_LIMITS_H)
CHECK_INCLUDE_FILE_CXX (locale.h HAVE_LOCALE_H)
CHECK_INCLUDE_FILE_CXX (malloc.h HAVE_MALLOC_H)
CHECK_INCLUDE_FILE_CXX (math.h HAVE_MATH_H)
CHECK_INCLUDE_FILE_CXX (memory.h HAVE_MEMORY_H)
CHECK_INCLUDE_FILE_CXX (netdb.h HAVE_NETDB_H)
CHECK_INCLUDE_FILE_CXX (netinet/in.h HAVE_NETINET_IN_H)
CHECK_INCLUDE_FILE_CXX (netinet/in_systm.h HAVE_NETINET_IN_SYSTM_H)
CHECK_INCLUDE_FILE_CXX (netinet/tcp.h HAVE_NETINET_TCP_H)
CHECK_INCLUDE_FILE_CXX (new.h HAVE_NEW_H)
CHECK_INCLUDE_FILE_CXX (pthread.h HAVE_PTHREAD_H)
CHECK_INCLUDE_FILE_CXX (pwd.h HAVE_PWD_H)
CHECK_INCLUDE_FILE_CXX (semaphore.h HAVE_SEMAPHORE_H)
CHECK_INCLUDE_FILE_CXX (setjmp.h HAVE_SETJMP_H)
CHECK_INCLUDE_FILE_CXX (signal.h HAVE_SIGNAL_H)
CHECK_INCLUDE_FILE_CXX (sstream.h HAVE_SSTREAM_H)
CHECK_INCLUDE_FILE_CXX (stat.h HAVE_STAT_H)
CHECK_INCLUDE_FILE_CXX (stdarg.h HAVE_STDARG_H)
CHECK_INCLUDE_FILE_CXX (stdbool.h HAVE_STDBOOL_H)
CHECK_INCLUDE_FILE_CXX (stddef.h HAVE_STDDEF_H)
CHECK_INCLUDE_FILE_CXX (stdint.h HAVE_STDINT_H)
CHECK_INCLUDE_FILE_CXX (stdio.h HAVE_STDIO_H)
CHECK_INCLUDE_FILE_CXX (stdlib.h HAVE_STDLIB_H)
CHECK_INCLUDE_FILE_CXX (strings.h HAVE_STRINGS_H)
CHECK_INCLUDE_FILE_CXX (string.h HAVE_STRING_H)
CHECK_INCLUDE_FILE_CXX (synch.h HAVE_SYNCH_H)
CHECK_INCLUDE_FILE_CXX (sys/errno.h HAVE_SYS_ERRNO_H)
CHECK_INCLUDE_FILE_CXX (sys/file.h HAVE_SYS_FILE_H)
CHECK_INCLUDE_FILE_CXX (sys/param.h HAVE_SYS_PARAM_H)
CHECK_INCLUDE_FILE_CXX (sys/resource.h HAVE_SYS_RESOURCE_H)
CHECK_INCLUDE_FILE_CXX (sys/select.h HAVE_SYS_SELECT_H)
CHECK_INCLUDE_FILE_CXX (sys/socket.h HAVE_SYS_SOCKET_H)
CHECK_INCLUDE_FILE_CXX (sys/stat.h HAVE_SYS_STAT_H)
CHECK_INCLUDE_FILE_CXX (sys/time.h HAVE_SYS_TIME_H)
CHECK_INCLUDE_FILE_CXX (sys/types.h HAVE_SYS_TYPES_H)
CHECK_INCLUDE_FILE_CXX (sys/utime.h HAVE_SYS_UTIME_H)
CHECK_INCLUDE_FILE_CXX (sys/utsname.h HAVE_SYS_UTSNAME_H)
CHECK_INCLUDE_FILE_CXX (sys/wait.h HAVE_SYS_WAIT_H)
CHECK_INCLUDE_FILE_CXX (thread.h HAVE_THREAD_H)
CHECK_INCLUDE_FILE_CXX (time.h HAVE_TIME_H)
CHECK_INCLUDE_FILE_CXX (unistd.h HAVE_UNISTD_H)
CHECK_INCLUDE_FILE_CXX (unix.h HAVE_UNIX_H)
CHECK_INCLUDE_FILE_CXX (utime.h HAVE_UTIME_H)
CHECK_INCLUDE_FILE_CXX (wctype.h HAVE_WCTYPE_H)

INCLUDE(CheckFunctionExists)
CHECK_FUNCTION_EXISTS (accept HAVE_ACCEPT)
CHECK_FUNCTION_EXISTS (access HAVE_ACCESS)
CHECK_FUNCTION_EXISTS (bcmp HAVE_BCMP)
CHECK_FUNCTION_EXISTS (bcopy HAVE_BCOPY)
CHECK_FUNCTION_EXISTS (bind HAVE_BIND)
CHECK_FUNCTION_EXISTS (bzero HAVE_BZERO)
CHECK_FUNCTION_EXISTS (connect HAVE_CONNECT)
CHECK_FUNCTION_EXISTS (cuserid HAVE_CUSERID)
CHECK_FUNCTION_EXISTS (finite HAVE_FINITE)
CHECK_FUNCTION_EXISTS (flock HAVE_FLOCK)
CHECK_FUNCTION_EXISTS (fork HAVE_FORK)
CHECK_FUNCTION_EXISTS (getenv HAVE_GETENV)
CHECK_FUNCTION_EXISTS (geteuid HAVE_GETEUID)
CHECK_FUNCTION_EXISTS (getgrnam HAVE_GETGRNAM)
CHECK_FUNCTION_EXISTS (gethostbyname HAVE_GETHOSTBYNAME)
CHECK_FUNCTION_EXISTS (gethostid HAVE_GETHOSTID)
CHECK_FUNCTION_EXISTS (gethostname HAVE_GETHOSTNAME)
CHECK_FUNCTION_EXISTS (getlogin HAVE_GETLOGIN)
CHECK_FUNCTION_EXISTS (getpid HAVE_GETPID)
CHECK_FUNCTION_EXISTS (getpwnam HAVE_GETPWNAM)
CHECK_FUNCTION_EXISTS (getsockname HAVE_GETSOCKNAME)
CHECK_FUNCTION_EXISTS (getsockopt HAVE_GETSOCKOPT)
CHECK_FUNCTION_EXISTS (getuid HAVE_GETUID)
CHECK_FUNCTION_EXISTS (index HAVE_INDEX)
CHECK_FUNCTION_EXISTS (isinf HAVE_ISINF)
CHECK_FUNCTION_EXISTS (isnan HAVE_ISNAN)
CHECK_FUNCTION_EXISTS (itoa HAVE_ITOA)
CHECK_FUNCTION_EXISTS (listen HAVE_LISTEN)
CHECK_FUNCTION_EXISTS (lockf HAVE_LOCKF)
CHECK_FUNCTION_EXISTS (malloc_debug HAVE_MALLOC_DEBUG)
CHECK_FUNCTION_EXISTS (memcmp HAVE_MEMCMP)
CHECK_FUNCTION_EXISTS (memcpy HAVE_MEMCPY)
CHECK_FUNCTION_EXISTS (memmove HAVE_MEMMOVE)
CHECK_FUNCTION_EXISTS (memset HAVE_MEMSET)
CHECK_FUNCTION_EXISTS (mkstemp HAVE_MKSTEMP)
CHECK_FUNCTION_EXISTS (mktemp HAVE_MKTEMP)
CHECK_FUNCTION_EXISTS (rindex HAVE_RINDEX)
CHECK_FUNCTION_EXISTS (select HAVE_SELECT)
CHECK_FUNCTION_EXISTS (setsockopt HAVE_SETSOCKOPT)
CHECK_FUNCTION_EXISTS (setuid HAVE_SETUID)
CHECK_FUNCTION_EXISTS (sleep HAVE_SLEEP)
CHECK_FUNCTION_EXISTS (socket HAVE_SOCKET)
CHECK_FUNCTION_EXISTS (stat HAVE_STAT)
CHECK_FUNCTION_EXISTS (strchr HAVE_STRCHR)
CHECK_FUNCTION_EXISTS (strdup HAVE_STRDUP)
CHECK_FUNCTION_EXISTS (strerror HAVE_STRERROR)
CHECK_FUNCTION_EXISTS (strlcat HAVE_STRLCAT)
CHECK_FUNCTION_EXISTS (strlcpy HAVE_STRLCPY)
CHECK_FUNCTION_EXISTS (strstr HAVE_STRSTR)
CHECK_FUNCTION_EXISTS (strtoul HAVE_STRTOUL)
CHECK_FUNCTION_EXISTS (sysinfo HAVE_SYSINFO)
CHECK_FUNCTION_EXISTS (tempnam HAVE_TEMPNAM)
CHECK_FUNCTION_EXISTS (tmpnam HAVE_TMPNAM)
CHECK_FUNCTION_EXISTS (uname HAVE_UNAME)
CHECK_FUNCTION_EXISTS (usleep HAVE_USLEEP)
CHECK_FUNCTION_EXISTS (vprintf HAVE_VPRINTF)
CHECK_FUNCTION_EXISTS (waitpid HAVE_WAITPID)
CHECK_FUNCTION_EXISTS (_findfirst HAVE__FINDFIRST)

CHECK_FUNCTION_EXISTS(accept HAVE_PROTOTYPE_ACCEPT)
CHECK_FUNCTION_EXISTS(bind HAVE_PROTOTYPE_BIND)
CHECK_FUNCTION_EXISTS(bzero HAVE_PROTOTYPE_BZERO)
CHECK_FUNCTION_EXISTS(connect HAVE_PROTOTYPE_CONNECT)
CHECK_FUNCTION_EXISTS(finite HAVE_PROTOTYPE_FINITE)
CHECK_FUNCTION_EXISTS(flock HAVE_PROTOTYPE_FLOCK)
CHECK_FUNCTION_EXISTS(gethostbyname HAVE_PROTOTYPE_GETHOSTBYNAME)
CHECK_FUNCTION_EXISTS(gethostid HAVE_PROTOTYPE_GETHOSTID)
CHECK_FUNCTION_EXISTS(gethostname HAVE_PROTOTYPE_GETHOSTNAME)
CHECK_FUNCTION_EXISTS(getsockname HAVE_PROTOTYPE_GETSOCKNAME)
CHECK_FUNCTION_EXISTS(getsockopt HAVE_PROTOTYPE_GETSOCKOPT)
CHECK_FUNCTION_EXISTS(gettimeofday HAVE_PROTOTYPE_GETTIMEOFDAY)
CHECK_FUNCTION_EXISTS(isinf HAVE_PROTOTYPE_ISINF)
CHECK_FUNCTION_EXISTS(isnan HAVE_PROTOTYPE_ISNAN)
CHECK_FUNCTION_EXISTS(listen HAVE_PROTOTYPE_LISTEN)
CHECK_FUNCTION_EXISTS(mkstemp HAVE_PROTOTYPE_MKSTEMP)
CHECK_FUNCTION_EXISTS(mktemp HAVE_PROTOTYPE_MKTEMP)
CHECK_FUNCTION_EXISTS(select HAVE_PROTOTYPE_SELECT)
CHECK_FUNCTION_EXISTS(setsockopt HAVE_PROTOTYPE_SETSOCKOPT)
CHECK_FUNCTION_EXISTS(socket HAVE_PROTOTYPE_SOCKET)
CHECK_FUNCTION_EXISTS(std::_vfprintf HAVE_PROTOTYPE_STD__VFPRINTF)
CHECK_FUNCTION_EXISTS(strcasecmp HAVE_PROTOTYPE_STRCASECMP)
CHECK_FUNCTION_EXISTS(stdncasecmp HAVE_PROTOTYPE_STRNCASECMP)
CHECK_FUNCTION_EXISTS(usleep HAVE_PROTOTYPE_USLEEP)
CHECK_FUNCTION_EXISTS(wait3 HAVE_PROTOTYPE_WAIT3)
CHECK_FUNCTION_EXISTS(waitpid HAVE_PROTOTYPE_WAITPID)
CHECK_FUNCTION_EXISTS(_stricmp HAVE_PROTOTYPE__STRICMP)

#Include(CheckLibraryExists)
#CHECK_LIBRARY_EXISTS(iostream HAVE_LIBIOSTREAM)
#CHECK_LIBRARY_EXISTS(nsl HAVE_LIBNSL)
#CHECK_LIBRARY_EXISTS(socket HAVE_LIBSOCKET)

SET(CMAKE_EXTRA_INCLUDE_FILES sys/types.h)
CHECK_TYPE_SIZE("pid_t" SYS_TYPES_PID_T)
CHECK_TYPE_SIZE("size_t" SYS_TYPES_SIZE_T)
CHECK_TYPE_SIZE("ssize_t" SYS_TYPES_SSIZE_T)
CHECK_TYPE_SIZE("uchar" SYS_TYPES_UCHAR)
CHECK_TYPE_SIZE("uint" SYS_TYPES_UINT)
CHECK_TYPE_SIZE("ulong" SYS_TYPES_ULONG)
SET(CMAKE_EXTRA_INCLUDE_FILES) 

Include(CheckSymbolExists)
CHECK_SYMBOL_EXISTS(DIR ndir.h HAVE_NDIR_H)
CHECK_SYMBOL_EXISTS(DIR sys/dir.h HAVE_SYS_DIR_H)
CHECK_SYMBOL_EXISTS(DIR sys/ndir.h HAVE_SYS_NDIR_H)
IF(HAVE_IOSTREAM_H)
  CHECK_SYMBOL_EXISTS(ios::nocreate iostream.h HAVE_IOS_NOCREATE)
ENDIF(HAVE_IOSTREAM_H)

SET(USE_STD_CXX_INCLUDES 1)

SET(HAVE_STD_NAMESPACE ${CMAKE_STD_NAMESPACE})
SET(HAVE_CLASS_TEMPLATE 1)
SET(HAVE_FUNCTION_TEMPLATE 1)
SET(HAVE_EXPLICIT_TEMPLATE_SPECIALIZATION 1)
SET(HAVE_CXX_BOOL 1)

## Copy variables from CMake's internal names to their names in configurable header 
SET(SIZEOF_CHAR ${CMAKE_SIZEOF_CHAR})
SET(SIZEOF_DOUBLE ${CMAKE_SIZEOF_DOUBLE})
SET(SIZEOF_FLOAT ${CMAKE_SIZEOF_FLOAT})
SET(SIZEOF_INT ${CMAKE_SIZEOF_INT})
SET(SIZEOF_LONG ${CMAKE_SIZEOF_LONG})
SET(SIZEOF_SHORT ${CMAKE_SIZEOF_SHORT})
SET(SIZEOF_VOID_P ${CMAKE_SIZEOF_VOID_P})

## Created configured configuration header
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/dcmtk/config/cfunix.h.in ${CMAKE_CURRENT_BINARY_DIR}/cfunix.h @ONLY)

INCLUDE_DIRECTORIES(
	${CMAKE_CURRENT_BINARY_DIR}
	${CMAKE_CURRENT_SOURCE_DIR}
	${ZLIB_INCLUDE_DIRS})

INCLUDE_REGULAR_EXPRESSION("^.*.h$")

SET(dcmtk_SRCS
  cmdlnarg.cc
  dcbytstr.cc
  dcchrstr.cc
  dccodec.cc
  dcdatset.cc
  dcdebug.cc
  dcdicdir.cc
  dcdicent.cc
  dcdict.cc
  dcdictzz.cc
  dcdirrec.cc
  dcelem.cc
  dcerror.cc
  dcfilefo.cc
  dchashdi.cc
  dcistrma.cc
  dcistrmf.cc
  dcistrmz.cc
  dcitem.cc
  dclist.cc
  dcmetinf.cc
  dcobject.cc
  dcostrma.cc
  dcostrmf.cc
  dcostrmz.cc
  dcpcache.cc
  dcpixel.cc
  dcpixseq.cc
  dcpxitem.cc
  dcsequen.cc
  dcstack.cc
  dcswap.cc
  dctag.cc
  dctagkey.cc
  dctypes.cc
  dcuid.cc
  dcvm.cc
  dcvr.cc
  dcvrae.cc
  dcvras.cc
  dcvrat.cc
  dcvrcs.cc
  dcvrda.cc
  dcvrds.cc
  dcvrdt.cc
  dcvrfd.cc
  dcvrfl.cc
  dcvris.cc
  dcvrlo.cc
  dcvrlt.cc
  dcvrobow.cc
  dcvrof.cc
  dcvrpn.cc
  dcvrpobw.cc
  dcvrsh.cc
  dcvrsl.cc
  dcvrss.cc
  dcvrst.cc
  dcvrtm.cc
  dcvrui.cc
  dcvrul.cc
  dcvrulup.cc
  dcvrus.cc
  dcvrut.cc
  dcxfer.cc
  didocu.cc
  diutils.cc
  ofcond.cc
  ofconsol.cc
  ofcrc32.cc
  ofdate.cc
  ofdatime.cc
  oflist.cc
  ofstd.cc
  ofstring.cc
  ofthread.cc
  oftime.cc
)

ADD_LIBRARY(D4CMTK ${dcmtk_SRCS})
TARGET_LINK_LIBRARIES(D4CMTK ${ZLIB_LIBRARIES})

IF(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
  TARGET_LINK_LIBRARIES(D4CMTK wsock32 netapi32)
ENDIF(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
  
INSTALL(TARGETS D4CMTK
  RUNTIME DESTINATION ${CMTK_INSTALL_BIN_DIR} COMPONENT runtime
  LIBRARY DESTINATION ${CMTK_INSTALL_LIB_DIR} COMPONENT runtime
  ARCHIVE DESTINATION ${CMTK_INSTALL_LIB_DIR} COMPONENT libraries)

FILE(GLOB files "${CMAKE_CURRENT_SOURCE_DIR}/dcmtk/*/*.h")
INSTALL(FILES ${files} DESTINATION ${CMTK_INSTALL_INCLUDE_DIR}/dcmtk COMPONENT headers)
INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/dicom.dic DESTINATION ${CMTK_INSTALL_DATA_DIR} COMPONENT runtime)
