#
# 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 Clement
#        - (RICHART Nicolas)
#
#
set(VITE_UIS
  interface/ui/info_window.ui
  interface/ui/select_info_window.ui
  interface/ui/settings.ui
  interface/ui/main_window.ui
  interface/ui/option_export_window.ui
  interface/ui/list_of_counter_to_export.ui
  interface/ui/node_select.ui
  interface/ui/interval_select.ui
  interface/ui/statistics.ui
  )
  
set(VITE_HDRS
  common/Errors.hpp
  common/Info.hpp
  common/Log.hpp
  common/LogConsole.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/GanttDiagram.hpp
  render/Geometry.hpp
  render/Hook_event.hpp
  render/Minimap.hpp
  render/Render_svg.hpp
  render/Ruler.hpp
  render/RenderLayout.hpp
  render/Render_windowed.hpp
  render/Render_abstract.hpp
  # Interface headers
  interface/resource.hpp
  interface/Settings_window.hpp
  interface/Interface_graphic.hpp
  interface/Node_select.hpp
  interface/viteqtreewidget.hpp
  interface/Interval_select.hpp
  interface/RangeSliderWidget.hpp
  # Core header
  core/Core.hpp
  core/getopt.h
  # Parser headers
  parser/ParsingThread.hpp
  parser/ParsingUpdateThread.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/Statistics_window.hpp
  statistics/ChartView.hpp
  statistics/Statistic.hpp
  statistics/Diagram.hpp
  # Plugin header
  plugin/Plugin_window.hpp
  plugin/Plugin.hpp
  )

set(VITE_SRCS
  # Messages & Errors
  common/Errors.cpp
  common/Info.cpp
  common/LogConsole.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/Container.cpp
  trace/ContainerType.cpp
  trace/DrawTrace.cpp
  trace/Entity.cpp
  trace/EntityType.cpp
  trace/EntityValue.cpp
  trace/Event.cpp
  trace/EventType.cpp
  trace/IntervalOfContainer.cpp
  trace/Link.cpp
  trace/LinkType.cpp
  trace/State.cpp
  trace/StateChange.cpp
  trace/StateType.cpp
  trace/Trace.cpp
  trace/Variable.cpp
  trace/VariableType.cpp
  # Render code files
  render/GanttDiagram.hpp
  render/Geometry.cpp
  render/Hook_event.cpp
  render/Minimap.cpp
  render/RenderLayout.cpp
  render/Render_svg.cpp
  render/Ruler.cpp
  render/Render_abstract.cpp
  # Parser code files
  parser/Parser.cpp
  parser/ParserFactory.cpp
  parser/ParsingThread.cpp
  parser/ParsingUpdateThread.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/ChartView.cpp
  statistics/Statistics_window.cpp
  statistics/Diagram.cpp
  # Interface code files
  interface/Interface_graphic.cpp
  interface/Interval_select.cpp
  interface/Node_select.cpp
  interface/Settings_window.cpp
  interface/RangeSliderWidget.cpp
  interface/viteqtreewidget.cpp
  # Plugin code file
  plugin/Plugin.cpp
  plugin/Plugin_window.cpp
  # Core code files
  core/Core.cpp
  core/getopt.c
  # Main
  main.cpp
  )
  
set(VITE_RCCS
  interface/ui/vite.qrc
  )

#############################################
#           Renderer
#############################################

if(USE_OPENGL)
  message("OpenGL will be used")
  set(VITE_HDRS
    ${VITE_HDRS}
    render/opengl/Render_opengl.hpp
    )

  set(VITE_SRCS
    ${VITE_SRCS}
    render/opengl/Render_opengl.cpp
    )
endif()

if(USE_VULKAN)
  message("Vulkan will be used")
  message(WARNING "The Vulkan version is not yet finished")
  set(VITE_HDRS
    ${VITE_HDRS}
    render/vulkan/Render_vulkan.hpp
    render/vulkan/Vulkan_window.hpp
    render/vulkan/Vulkan_window_renderer.hpp
    render/vulkan/Vk_buffer.hpp
    render/vulkan/Vk_vertex_buffer.hpp
    render/vulkan/Vk_uniform_buffer.hpp
    render/vulkan/Vk_pipeline.hpp
    )

  set(VITE_SRCS
    ${VITE_SRCS}
    render/vulkan/Render_vulkan.cpp
    render/vulkan/Vulkan_window.cpp
    render/vulkan/Vulkan_window_renderer.cpp
    render/vulkan/Vk_buffer.cpp
    render/vulkan/Vk_vertex_buffer.cpp
    render/vulkan/Vk_uniform_buffer.cpp
    render/vulkan/Vk_pipeline.cpp
    )
  include_directories(${Vulkan_INCLUDE_DIR})
endif()

#############################################
#                VBO
#############################################
if(VITE_ENABLE_VBO)
  message("OpenGL with VBO will be used")
  set(VITE_HDRS
    ${VITE_HDRS}
    render/vbo/vbo.hpp
    render/vbo/Shader.hpp
    render/vbo/Render_alternate.hpp
    )

  set(VITE_SRCS
    ${VITE_SRCS}
    render/vbo/vbo.cpp
    render/vbo/Shader.cpp
    render/vbo/Render_alternate.cpp
    )
endif()

#############################################
#           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
  )

#############################################
#              OTF2 Parser
#############################################
if(VITE_ENABLE_OTF2)
  add_definitions(-DWITH_OTF2)

  set(VITE_HDRS
    ${VITE_HDRS}
    parser/OTF2Parser/ParserDefinitionOTF2.hpp
    parser/OTF2Parser/ParserEventOTF2.hpp
    parser/OTF2Parser/ParserOTF2.hpp
    )

  set(VITE_SRCS
    ${VITE_SRCS}
    parser/OTF2Parser/ParserDefinitionOTF2.cpp
    parser/OTF2Parser/ParserEventOTF2.cpp
    parser/OTF2Parser/ParserOTF2.cpp
    )

  include_directories(${OTF2_INCLUDE_DIR})
endif()

#############################################
#              TAU Parser
#############################################
if(VITE_ENABLE_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()

#############################################
#        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()

#############################################
#              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})

include_directories(
  ${CMAKE_CURRENT_BINARY_DIR}/common
  ${CMAKE_CURRENT_BINARY_DIR}
  ${CMAKE_CURRENT_SOURCE_DIR}
  ${QTCOLORPICKERDIR}
  )

if(VITE_ENABLE_OTF2)
  link_directories(${OTF2_LIBRARY_DIR})
endif()

#resource
if(WIN32)
  set(VITE_RES
    "${PROJECT_SOURCE_DIR}/src/interface/icon/logo.ico"
    "${PROJECT_SOURCE_DIR}/src/interface/windows_icon.rc"
    )
endif()

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()
  add_executable(vite ${VITE_SRCS} ${VITE_MOC} ${VITE_RCC_SRCS} ${VITE_RES})
endif()

#############################################
#              QT5
#############################################
#qt5_use_modules(vite Widgets Core Xml OpenGL UiTools Charts Svg)
target_link_libraries(vite
  Qt5::Widgets
  Qt5::Core
  Qt5::Xml
  Qt5::OpenGL
  Qt5::UiTools
  Qt5::Charts
  Qt5::Svg)

target_link_libraries(vite
  ${OPENGL_gl_LIBRARY}
  ${OPENGL_glu_LIBRARY}
  ${Boost_LIBRARIES}
  )

if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
  target_link_libraries(vite
    rt
    )
  #ADD_DEFINITIONS("-DBOOST_GZIP")
endif()

if(VITE_ENABLE_VBO)
  target_link_libraries(vite
    ${GLEW_LIBRARY}
    )
endif()

if(VITE_ENABLE_OTF2)
  target_link_libraries(vite
    ${OTF2_LIBRARY}
    )
  # if OTF2 is compiled with zlib support we need to add it
  if(WIN32)
    target_link_libraries(vite
      ${ZLIB_LIBRARY}
      )
  endif()
endif()

if(VITE_ENABLE_TAU)
  target_link_libraries(vite
    ${TAU_LIBRARY}
    )
endif()

if(USE_VULKAN)
  #Compile shader for Vulkan
  find_program(GLSLC glslc REQUIRED)
  add_custom_command(TARGET vite POST_BUILD
    COMMAND ${GLSLC} ${CMAKE_SOURCE_DIR}/src/render/vulkan/vulkanshader.vert -o color_vert.spv
    COMMAND ${GLSLC} ${CMAKE_SOURCE_DIR}/src/render/vulkan/vulkanshader.frag -o color_frag.spv
    )
endif()

if(VITE_ENABLE_MPI)
  message("MPI will be used")
  target_compile_definitions(vite PUBLIC -DUSE_MPI)
  target_link_libraries(vite Boost::mpi)
endif()

if(WIN32)
  # Remove the console for windows
  set_target_properties(vite PROPERTIES LINK_FLAGS -Wl,-subsystem,windows)
endif()

install_targets(/bin vite)
