if(QT_VERSION_MAJOR STREQUAL 6)
  set(QT6_OPENGL_SUFFIX Widgets)
endif()

find_package(Qt${QT_VERSION_MAJOR} COMPONENTS OpenGL${QT6_OPENGL_SUFFIX} QUIET)

if (Qt${QT_VERSION_MAJOR}OpenGL${QT6_OPENGL_SUFFIX}_FOUND)
  project(IvtTools)

  #Ask CMake to automoc needed includes
  set(CMAKE_AUTOMOC ON)
  set(CMAKE_INCLUDE_CURRENT_DIR ON)

  include_directories(
    ${CMAKE_CURRENT_SOURCE_DIR}/
    ${CMAKE_CURRENT_SOURCE_DIR}/DirectionalLightEditor/
    ${CMAKE_CURRENT_SOURCE_DIR}/ProcessingMenu/
    ${CMAKE_CURRENT_SOURCE_DIR}/ShaderEditor/
    ${CMAKE_CURRENT_SOURCE_DIR}/ViewingToolbar/
  )

  # Wrap our UI so we can list them in sources of the project
  qt_wrap_ui(${PROJECT_NAME}_UICS
    DirectionalLightEditor/Ivt_DirectionalLightEditor_UI.ui
    ShaderEditor/Ivt_ShaderEditor_UI.ui
  )

  # Same with resources.
  qt_add_resources(${PROJECT_NAME}_QRCS
    DirectionalLightEditor/Resources/lightEditor.qrc
    ShaderEditor/Resources/shaderEditor.qrc
    ViewingToolbar/Resources/ViewingTB.qrc
  )
  
  # Those headers will be auto mocced. Gather them here
  # so we could easily list them later
  set(${PROJECT_NAME}_MOCS
    DirectionalLightEditor/Ivt_DirectionalLightEditor.h
    ProcessingMenu/Ivt_PMSplitDialog.h
    ProcessingMenu/Ivt_ProcessingMenu.h
    ShaderEditor/Ivt_ShaderEditor.h
    ViewingToolbar/Ivt_ViewingToolbar.h
  )

  #define sources of the project
  set(${PROJECT_NAME}_SOURCES
    IvtToolsPlugin.cxx

    # Directional Light
    DirectionalLightEditor/Ivt_DirectionalLightEditor.cxx

    # Processing Menu
    ProcessingMenu/Ivt_PMSplitDialog.cxx
    ProcessingMenu/Ivt_ProcessingMenu.cxx
    ProcessingMenu/Ivt_ProcessingMenuActionsManager.cxx

    # Share Editor
    ShaderEditor/Ivt_ShaderEditor.cxx
    ShaderEditor/Ivt_ShaderSyntaxHighlight.cxx

    # Viewing Toolbar
    ViewingToolbar/Ivt_ViewingToolbar.cxx
  )

  set(Resource_SOURCES
    resource/Version.rc
  )

  file(GLOB_RECURSE PUBLIC_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/*.h)

  create_vcproj_hierarchy("Source Files" ${${PROJECT_NAME}_SOURCES})
  create_vcproj_hierarchy("Header Files" ${CMAKE_CURRENT_SOURCE_DIR} ${PUBLIC_HEADERS})
  create_vcproj_hierarchy("Resource Files" ${Resource_SOURCES})

  # Time to build our lib with Source, Mocs, Uics and resources.
  add_oiv_library(${PROJECT_NAME} SHARED
    ${${PROJECT_NAME}_SOURCES}

    # Because we automoc, just add needed includes.
    ${${PROJECT_NAME}_MOCS}

    # Add .h generated from UIC
    ${${PROJECT_NAME}_UICS}

    # Add generated resources
    ${${PROJECT_NAME}_QRCS}

    ${Resource_SOURCES}
  )

  target_link_libraries(${PROJECT_NAME} Qt::OpenGL${QT6_OPENGL_SUFFIX})
  if (${QT_VERSION_MAJOR} EQUAL 6)
    qt_allow_non_utf8_sources(${PROJECT_NAME})
    qt_disable_unicode_defines(${PROJECT_NAME})
  endif()

  set_target_properties( ${PROJECT_NAME} PROPERTIES OUTPUT_NAME fei_ivTune_extender_inventor )
  
  if(APPLE)
    target_link_libraries(${PROJECT_NAME} ${OpenInventorGLEW_LIBRARIES})
  endif()
  
endif()
