# - Use Module for QT4
# Sets up C and C++ to use Qt 4.  It is assumed that FindQt.cmake
# has already been loaded.  See FindQt.cmake for information on
# how to load Qt 4 into your CMake project.


ADD_DEFINITIONS(${QT_DEFINITIONS})

# check that QT_NO_DEBUG is defined for release configurations
MACRO(QT_CHECK_FLAG_EXISTS FLAG VAR DOC)
  IF(NOT ${VAR} MATCHES "${FLAG}")
    SET(${VAR} "${${VAR}} ${FLAG}" 
      CACHE STRING "Flags used by the compiler during ${DOC} builds." FORCE)
  ENDIF(NOT ${VAR} MATCHES "${FLAG}")
ENDMACRO(QT_CHECK_FLAG_EXISTS FLAG VAR)
QT_CHECK_FLAG_EXISTS(-DQT_NO_DEBUG CMAKE_CXX_FLAGS_RELWITHDEBINFO "Release with Debug Info")
QT_CHECK_FLAG_EXISTS(-DQT_NO_DEBUG CMAKE_CXX_FLAGS_RELEASE "release")
QT_CHECK_FLAG_EXISTS(-DQT_NO_DEBUG CMAKE_CXX_FLAGS_MINSIZEREL "release minsize")

INCLUDE_DIRECTORIES(${QT_INCLUDE_DIR})

SET(QT_LIBRARIES "")

IF (QT_USE_QTMAIN)
  IF (WIN32)
    SET(QT_LIBRARIES ${QT_LIBRARIES} ${QT_QTMAIN_LIBRARY})
  ENDIF (WIN32)
ENDIF (QT_USE_QTMAIN)

# Macro for setting up compile flags for Qt modules
MACRO(QT_MODULE_SETUP module)
  IF (QT_QT${module}_FOUND)
    ADD_DEFINITIONS(-DQT_${module}_LIB)
    INCLUDE_DIRECTORIES(${QT_QT${module}_INCLUDE_DIR})
    SET(QT_LIBRARIES ${QT_LIBRARIES} ${QT_QT${module}_LIBRARY} ${QT_${module}_LIB_DEPENDENCIES})
  ELSE (QT_QT${module}_FOUND)
    MESSAGE("Qt ${module} library not found.")
  ENDIF (QT_QT${module}_FOUND)
ENDMACRO(QT_MODULE_SETUP)


# Qt modules  (in order of dependence)

IF (QT_USE_QT3SUPPORT)
  QT_MODULE_SETUP(3SUPPORT)
  ADD_DEFINITIONS(-DQT3_SUPPORT)
ENDIF (QT_USE_QT3SUPPORT)

IF (QT_USE_QTOPENGL)
  QT_MODULE_SETUP(OPENGL)
ENDIF (QT_USE_QTOPENGL)

IF (QT_USE_QTASSISTANT)
  QT_MODULE_SETUP(ASSISTANT)
ENDIF (QT_USE_QTASSISTANT)

IF (QT_USE_QTDESIGNER)
  QT_MODULE_SETUP(DESIGNER)
ENDIF (QT_USE_QTDESIGNER)

IF (QT_USE_QTMOTIF)
  QT_MODULE_SETUP(MOTIF)
ENDIF (QT_USE_QTMOTIF)

IF (QT_USE_QTNSPLUGIN)
  QT_MODULE_SETUP(NSPLUGIN)
ENDIF (QT_USE_QTNSPLUGIN)

IF (QT_USE_QTSCRIPT)
  QT_MODULE_SETUP(SCRIPT)
ENDIF (QT_USE_QTSCRIPT)

IF (QT_USE_QTSVG)
  QT_MODULE_SETUP(SVG)
ENDIF (QT_USE_QTSVG)

IF (QT_USE_QTUITOOLS)
  QT_MODULE_SETUP(UITOOLS)
ENDIF (QT_USE_QTUITOOLS)

IF (NOT QT_DONT_USE_QTGUI)
  QT_MODULE_SETUP(GUI)
ENDIF (NOT QT_DONT_USE_QTGUI)

IF (QT_USE_QTTEST)
  QT_MODULE_SETUP(TEST)
ENDIF (QT_USE_QTTEST)

IF (QT_USE_QTXML)
  QT_MODULE_SETUP(XML)
ENDIF (QT_USE_QTXML)

IF (QT_USE_QTSQL)
  QT_MODULE_SETUP(SQL)
ENDIF (QT_USE_QTSQL)

IF (QT_USE_QTNETWORK)
  QT_MODULE_SETUP(NETWORK)
ENDIF (QT_USE_QTNETWORK)

IF (QT_USE_QTDBUS)
  QT_MODULE_SETUP(DBUS)
ENDIF (QT_USE_QTDBUS)

IF (NOT QT_DONT_USE_QTCORE)
  QT_MODULE_SETUP(CORE)
ENDIF (NOT QT_DONT_USE_QTCORE)


