#
# This file is part of the ViTE project.
#
# This software is governed by the CeCILL-A license under French law
# and abiding by the rules of distribution of free software. You can
# use, modify and/or redistribute the software under the terms of the
# CeCILL-A license as circulated by CEA, CNRS and INRIA at the following
# URL: "http://www.cecill.info".
#
# As a counterpart to the access to the source code and rights to copy,
# modify and redistribute granted by the license, users are provided
# only with a limited warranty and the software's author, the holder of
# the economic rights, and the successive licensors have only limited
# liability.
#
# In this respect, the user's attention is drawn to the risks associated
# with loading, using, modifying and/or developing or reproducing the
# software by the user in light of its specific status of free software,
# that may mean that it is complicated to manipulate, and that also
# therefore means that it is reserved for developers and experienced
# professionals having in-depth computer knowledge. Users are therefore
# encouraged to load and test the software's suitability as regards
# their requirements in conditions enabling the security of their
# systems and/or data to be ensured and, more generally, to use and
# operate it in the same conditions as regards security.
#
# The fact that you are presently reading this means that you have had
# knowledge of the CeCILL-A license and that you accept its terms.
#
# ViTE developers are (for version 0.* to 1.0):
#
#        - COULOMB Kevin
#        - FAVERGE Mathieu
#        - JAZEIX Johnny
#        - LAGRASSE Olivier
#        - MARCOUEILLE Jule
#        - NOISETTE Pascal
#        - REDONDY Arthur
#        - VUCHENER Clment
#        - (RICHART Nicolas)
#
#

SET(VITE_HDRS
  common/Errors.hpp
  common/Info.hpp
  common/Memory.hpp
  common/Message.hpp
  common/Palette.hpp
  common/Session.hpp
  common/Tools.hpp
  common/common.hpp
  # Data structure headers
  trace/values/Color.hpp
  trace/values/Date.hpp
  trace/values/Double.hpp
  trace/values/Hex.hpp
  trace/values/Integer.hpp
  trace/values/Name.hpp
  trace/values/String.hpp
  trace/values/Value.hpp
  trace/values/Values.hpp
  trace/tree/BinaryTree.hpp
  trace/tree/Node.hpp
  trace/tree/Interval.hpp
  trace/ContainerType.hpp
  trace/EntityType.hpp
  trace/EventType.hpp
  trace/StateType.hpp
  trace/LinkType.hpp
  trace/VariableType.hpp
  trace/EntityTypes.hpp
  trace/EntityValue.hpp
  trace/Container.hpp
  trace/Entity.hpp
  trace/Event.hpp
  trace/State.hpp
  trace/StateChange.hpp
  trace/Link.hpp
  trace/Entitys.hpp
  trace/Variable.hpp
  trace/DrawTrace.hpp
  trace/DrawTree.hpp
  trace/Trace.hpp
  trace/IntervalOfContainer.hpp
  # Render headers
  render/Render.hpp
  render/Geometry.hpp
  render/Hook_event.hpp
  render/Minimap.hpp
  render/Render_opengl.hpp
  render/Render_svg.hpp
  render/render_stats.hpp
  render/render_stats_opengl.hpp
  render/render_stats_svg.hpp
  render/Ruler.hpp
  # Interface headers
  interface/resource.hpp
  interface/Interface.hpp
  interface/Settings_window.hpp
  interface/Interface_graphic.hpp
  interface/Node_select.hpp
  interface/viteqtreewidget.hpp
  interface/Interval_select.hpp
  interface/qxtspanslider.h
  interface/qxtspanslider_p.h
  # Core header
  core/Core.hpp
  core/getopt.h
  # Parser headers
  parser/ParsingThread.hpp
  parser/Parser.hpp
  parser/ParserFactory.hpp
  # Paje
  parser/PajeParser/PajeDefinition.hpp
  parser/PajeParser/PajeFileManager.hpp
  parser/PajeParser/ParserDefinitionPaje.hpp
  parser/PajeParser/ParserEventPaje.hpp
  parser/PajeParser/ParserPaje.hpp
  parser/PajeParser/ParserVite.hpp
  # Statistics headers
  statistics/Stats_window.hpp
  statistics/Statistic.hpp
  statistics/DrawStats.hpp
  statistics/DrawVDiagram.hpp
  statistics/DrawHDiagram.hpp
  statistics/DrawCounter.hpp
  # Plugin header
  plugin/Command_window.hpp
  plugin/Plugin_window.hpp
  plugin/Plugin.hpp
  )

SET(VITE_UIS
  interface/info_window.ui
  interface/settings.ui
  interface/main_window.ui
  interface/option_export_window.ui
  interface/stats_viewer.ui
  interface/global_cmd.ui
  interface/list_of_counter_to_export.ui
  interface/node_select.ui
  interface/interval_select.ui
  )

SET(VITE_SRCS
  # Messages & Errors
  common/Errors.cpp
  common/Info.cpp
  common/Memory.cpp
  common/Message.cpp
  common/Palette.cpp
  common/Session.cpp
  common/Tools.cpp
  # Data structure code files
  trace/values/Color.cpp
  trace/values/Date.cpp
  trace/values/Double.cpp
  trace/values/Hex.cpp
  trace/values/Integer.cpp
  trace/values/Name.cpp
  trace/values/String.cpp
  trace/tree/Interval.cpp
  trace/EntityValue.cpp
  trace/ContainerType.cpp
  trace/EntityType.cpp
  trace/EventType.cpp
  trace/StateType.cpp
  trace/LinkType.cpp
  trace/VariableType.cpp
  trace/Entity.cpp
  trace/Event.cpp
  trace/State.cpp
  trace/StateChange.cpp
  trace/Link.cpp
  trace/Variable.cpp
  trace/Container.cpp
  trace/Trace.cpp
  trace/IntervalOfContainer.cpp
  # Render code files
  render/Geometry.cpp
  render/Hook_event.cpp
  render/Render.hpp
  render/Minimap.cpp
  render/Render_opengl.cpp
  render/Render_svg.cpp
  render/render_stats_opengl.cpp
  render/render_stats_svg.cpp
  render/Ruler.cpp
  # Parser code files
  parser/Parser.cpp
  parser/ParserFactory.cpp
  parser/ParsingThread.cpp
  # Paje Parser
  parser/PajeParser/PajeDefinition.cpp
  parser/PajeParser/PajeFileManager.cpp
  parser/PajeParser/ParserDefinitionPaje.cpp
  parser/PajeParser/ParserEventPaje.cpp
  parser/PajeParser/ParserPaje.cpp
  parser/PajeParser/ParserVite.cpp
  # Statistics code files
  statistics/Statistic.cpp
  statistics/Stats_window.cpp
  # Interface code files
  interface/Settings_window.cpp
  interface/Interface_graphic.cpp
  interface/Node_select.cpp
  interface/viteqtreewidget.cpp
  interface/Interval_select.cpp
  interface/qxtspanslider.cpp
  # Plugin code file
  plugin/Command_window.cpp
  plugin/Plugin_window.cpp
  plugin/Plugin.cpp
  # Core code files
  core/Core.cpp
  core/getopt.c
  # Main
  main.cpp
  )

SET(VITE_RCCS
  interface/vite.qrc
  )

#############################################
#           QtColorPicker
#############################################
set(QTCOLORPICKERDIR
  ${CMAKE_SOURCE_DIR}/externals/qtcolorpicker/src
  )

set(VITE_HDRS
  ${VITE_HDRS}
  ${QTCOLORPICKERDIR}/qtcolorpicker.h
  )

set(VITE_SRCS
  ${VITE_SRCS}
  ${QTCOLORPICKERDIR}/qtcolorpicker.cpp
  )

#############################################
#                VBO
#############################################
IF(VITE_ENABLE_VBO)
  ADD_DEFINITIONS(-DWITH_VBO)

  SET(VITE_HDRS
    ${VITE_HDRS}
    render/vbo.hpp
    render/Render_alternate.hpp
    )

  SET(VITE_SRCS
    ${VITE_SRCS}
    render/vbo.cpp
    render/Render_alternate.cpp
    )
ENDIF(VITE_ENABLE_VBO)

#############################################
#              OTF Parser
#############################################
IF(VITE_ENABLE_OTF)
  ADD_DEFINITIONS(-DWITH_OTF)

  SET(VITE_HDRS
    ${VITE_HDRS}
    parser/OTFParser/ParserDefinitionOTF.hpp
    parser/OTFParser/ParserEventOTF.hpp
    parser/OTFParser/ParserOTF.hpp
    )

  SET(VITE_SRCS
    ${VITE_SRCS}
    parser/OTFParser/ParserDefinitionOTF.cpp
    parser/OTFParser/ParserEventOTF.cpp
    parser/OTFParser/ParserOTF.cpp
    )

  IF(VITE_ENABLE_MT_PARSERS)
    SET(VITE_HDRS
      ${VITE_HDRS}
      parser/OTFParser/mt_ParserEventOTF.hpp
      parser/OTFParser/mt_ParserOTF.hpp
      parser/OTFParser/OTFTraceBuilderThread.hpp
      )
    SET(VITE_SRCS
      ${VITE_SRCS}
      parser/OTFParser/mt_ParserEventOTF.cpp
      parser/OTFParser/mt_ParserOTF.cpp
      parser/OTFParser/OTFTraceBuilderThread.cpp
      )
  ENDIF()
  
  INCLUDE_DIRECTORIES(BEFORE ${OTF_INCLUDE_DIR})

ENDIF(VITE_ENABLE_OTF)

#############################################
#              TAU Parser
#############################################
IF(VITE_ENABLE_TAU)
  ADD_DEFINITIONS(-DWITH_TAU)

  SET(VITE_HDRS
    ${VITE_HDRS}
    parser/TauParser/ParserTau.hpp
    parser/TauParser/TauStructs.hpp
    )

  SET(VITE_SRCS
    ${VITE_SRCS}
    parser/TauParser/ParserTau.cpp
    )

  INCLUDE_DIRECTORIES(${TAU_INCLUDE_DIR})

ENDIF(VITE_ENABLE_TAU)

#############################################
#        Multi-threaded Paje Parser
#############################################

IF(VITE_ENABLE_MT_PARSERS)

  SET(VITE_HDRS
    ${VITE_HDRS}
    #Multithread Paje
    parser/PajeParser/mt_ParserEventPaje.hpp
    parser/PajeParser/mt_ParserPaje.hpp
    parser/PajeParser/mt_PajeFileManager.hpp
    parser/PajeParser/BuilderThread.hpp
    trace/TraceBuilderThread.hpp
    )

  SET(VITE_SRCS
    ${VITE_SRCS}
    #Multithread Paje Parser
    parser/PajeParser/mt_ParserEventPaje.cpp
    parser/PajeParser/mt_ParserPaje.cpp
    parser/PajeParser/mt_PajeFileManager.cpp
    parser/PajeParser/BuilderThread.cpp
    trace/TraceBuilderThread.cpp
    )

ENDIF()

#############################################
#                BOOST
#############################################
IF(VITE_ENABLE_SERIALIZATION)
  link_directories ( ${Boost_LIBRARY_DIRS} )
  include_directories ( ${Boost_INCLUDE_DIRS} )
  add_definitions("-DUSE_ITC -DBOOST_SERIALIZE")

  SET(VITE_HDRS
    ${VITE_HDRS}
    parser/ParserSplitted.hpp
    trace/IntervalOfContainer.hpp
    trace/SerializerWriter.hpp
    trace/SerializerDispatcher.hpp
    )

  SET(VITE_SRCS
    ${VITE_SRCS}
    parser/ParserSplitted.cpp
    trace/IntervalOfContainer.cpp
    trace/SerializerWriter.cpp
    trace/SerializerDispatcher.cpp
    )

ENDIF(VITE_ENABLE_SERIALIZATION)

#############################################
#              QT5
#############################################
IF(USE_QT5)
  QT5_WRAP_UI(VITE_UIS_H ${VITE_UIS})
  QT5_WRAP_CPP(VITE_MOC ${VITE_UIS_H} ${VITE_MOC_HDRS})
  QT5_ADD_RESOURCES(VITE_RCC_SRCS ${VITE_RCCS})
  ADD_DEFINITIONS(-DQT_NO_DEBUG)
  #############################################
  #              QT4
  #############################################
ELSE(USE_QT5)
  QT4_AUTOMOC(${VITE_SRCS})
  FOREACH(_hdrs_file ${VITE_HDRS})
    GET_FILENAME_COMPONENT(_abs_file ${_hdrs_file} ABSOLUTE)
    FILE(READ ${_abs_file} _contents)
    STRING(REGEX MATCHALL "Q_OBJECT" _match "${_contents}")
    IF(_match)
      SET(VITE_MOC_HDRS ${VITE_MOC_HDRS} ${_hdrs_file})
    ENDIF(_match)
  ENDFOREACH(_hdrs_file ${VITE_HDRS})

  QT4_WRAP_UI(VITE_UIS_H ${VITE_UIS})
  QT4_WRAP_CPP(VITE_MOC ${VITE_UIS_H} ${VITE_MOC_HDRS})
  QT4_ADD_RESOURCES(VITE_RCC_SRCS ${VITE_RCCS})

  ADD_DEFINITIONS(-DQT_NO_DEBUG)

ENDIF(USE_QT5)
#############################################

INCLUDE_DIRECTORIES(
  ${CMAKE_CURRENT_BINARY_DIR}
  ${CMAKE_CURRENT_SOURCE_DIR}
  ${QTCOLORPICKERDIR}
  )
#ADD_LIBRARY(vite2 SHARED ${VITE_SRCS} ${VITE_MOC} ${VITE_RCC_SRCS})

IF( VITE_ENABLE_OTF )
  LINK_DIRECTORIES( ${OTF_LIBRARY_DIR} )
ENDIF( VITE_ENABLE_OTF )


if( APPLE )
  INCLUDE_DIRECTORIES(/usr/X11/include)
  SET( OSX_ICON_FILES "interface/icon/mac_logo.icns")
  set_source_files_properties(${OSX_ICON_FILES} PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
  ADD_EXECUTABLE(vite MACOSX_BUNDLE ${VITE_SRCS} ${VITE_MOC} ${VITE_RCC_SRCS} ${OSX_ICON_FILES})
  SET_TARGET_PROPERTIES(vite PROPERTIES
    MACOSX_BUNDLE_INFO_STRING "ViTE"
    MACOSX_BUNDLE_ICON_FILE "mac_logo.icns"
    MACOSX_BUNDLE_LONG_VERSION_STRING "Visual Trace Explorer - version ${VITE_VERSION_MAJOR}.${VITE_VERSION_MINOR}"
    MACOSX_BUNDLE_BUNDLE_NAME "Vite-MacOSX"
    MACOSX_BUNDLE_SHORT_VERSION_STRING "ViTE-${VITE_VERSION_MAJOR}.${VITE_VERSION_MINOR}"
    MACOSX_BUNDLE_BUNDLE_VERSION "1.0"
    MACOSX_BUNDLE_COPYRIGHT "INRIA 2006-2012"
    MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/vite-info.plist.in)
else( APPLE )
  ADD_EXECUTABLE(vite ${VITE_SRCS} ${VITE_MOC} ${VITE_RCC_SRCS})
endif( APPLE )

#############################################
#              QT5
#############################################
IF(USE_QT5)
  qt5_use_modules(vite Widgets Core Xml OpenGL UiTools)
ENDIF(USE_QT5)

TARGET_LINK_LIBRARIES(vite
  ${QT_LIBRARIES}
  ${GLU_LIBRARY}
  ${Boost_LIBRARIES}
  )

IF(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
  TARGET_LINK_LIBRARIES(vite
    rt
    )
  ADD_DEFINITIONS("-DBOOST_GZIP")
ENDIF(${CMAKE_SYSTEM_NAME} MATCHES "Linux")

IF(VITE_ENABLE_VBO)
  TARGET_LINK_LIBRARIES(vite
    ${GLEW_LIBRARY}
    )
ENDIF(VITE_ENABLE_VBO)

IF(VITE_ENABLE_OTF)
  TARGET_LINK_LIBRARIES(vite
    ${OTF_LIBRARY}
    )
ENDIF(VITE_ENABLE_OTF)

IF(VITE_ENABLE_TAU)
  TARGET_LINK_LIBRARIES(vite
    ${TAU_LIBRARY}
    )
ENDIF(VITE_ENABLE_TAU)

INSTALL_TARGETS(/bin vite)
