# Description: Build configuration for the GeoDMA TerraView Plugin
#
#  Author: Raian Vargas Maretto <raian@dpi.inpe.br>
#          Thales Sehn Korting <tkorting@dpi.inpe.br>
#          Emiliano Ferreira Castejon <castejon@dpi.inpe.br>
#

# Includes
include_directories(${Boost_INCLUDE_DIRS})
include_directories(${terralib_INCLUDE_DIRS})

include_directories(${GEODMA_SRC_DIR})

if(WIN32)
  add_definitions(-DGDMATVPLGDLL)
endif()

#if(Qt5_FOUND)
set(CMAKE_AUTOMOC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
#endif()

file(GLOB GEODMA_PLUGIN_SRC_FILES ${GEODMA_SRC_DIR}/geodma_tvplugin/*.cpp)
file(GLOB GEODMA_PLUGIN_HDR_FILES ${GEODMA_SRC_DIR}/geodma_tvplugin/*.hpp)
file(GLOB GEODMA_PLUGIN_DCTR_SRC_FILES ${GEODMA_SRC_DIR}/geodma_tvplugin/classification/*.cpp)
file(GLOB GEODMA_PLUGIN_DCTR_HDR_FILES ${GEODMA_SRC_DIR}/geodma_tvplugin/classification/*.hpp)
file(GLOB GEODMA_PLUGIN_UI_FILES ${GEODMA_SRC_DIR}/geodma_tvplugin/ui/*.ui)

# Creating source groups for IDEs
source_group("Source Files"  FILES ${GEODMA_PLUGIN_SRC_FILES})
source_group("Header Files"  FILES ${GEODMA_PLUGIN_HDR_FILES})
source_group("Source Files\\classification"  FILES ${GEODMA_PLUGIN_DCTR_SRC_FILES})
source_group("Header Files\\classification"  FILES ${GEODMA_PLUGIN_DCTR_HDR_FILES})
source_group("UI Files"  FILES ${GEODMA_PLUGIN_UI_FILES})

#if(Qt5_FOUND)
# uic'ing
QT5_WRAP_UI(GEODMA_PLG_GEN_HDR_FILES ${GEODMA_PLUGIN_UI_FILES})
set(GEODMA_FILES ${GEODMA_PLUGIN_SRC_FILES}
                 ${GEODMA_PLUGIN_HDR_FILES}
                 ${GEODMA_PLG_GEN_HDR_FILES}
                 ${GEODMA_PLUGIN_DCTR_SRC_FILES}
                 ${GEODMA_PLUGIN_DCTR_HDR_FILES}
)
add_library(geodma_mod_tvplugin SHARED ${GEODMA_FILES})

target_link_libraries(geodma_mod_tvplugin  geodma_mod_common
                                           geodma_mod_datamanager
                                           geodma_mod_guicomponents
                                           terralib_mod_qt_widgets
                                           terralib_mod_qt_apf
                                           ${Boost_FILESYSTEM_LIBRARY}
                                           ${QT_LIBRARIES})

qt5_use_modules(geodma_mod_tvplugin Widgets)
#endif()

if(GEODMA_SOURCE_VERIFY_ENABLED)
    add_style_check_target(geodma_mod_tvplugin "${GEODMA_PLUGIN_SRC_FILES} ${GEODMA_PLUGIN_HDR_FILES} ${GEODMA_PLUGIN_DCTR_SRC_FILES} ${GEODMA_PLUGIN_DCTR_HDR_FILES}")
endif()

#install(TARGETS geodma_mod_tvplugin
#        EXPORT geodma-targets
#        RUNTIME DESTINATION ${GEODMA_DESTINATION_RUNTIME} COMPONENT runtime
#        LIBRARY DESTINATION ${GEODMA_DESTINATION_LIBRARY} COMPONENT runtime
#        ARCHIVE DESTINATION ${GEODMA_DESTINATION_ARCHIVE} COMPONENT runtime
#)

if(MSVC)
    set_target_properties(geodma_mod_tvplugin
                          PROPERTIES VERSION ${GEODMA_VERSION_MAJOR}.${GEODMA_VERSION_MINOR}
                                     SOVERSION ${GEODMA_VERSION_MAJOR}.${GEODMA_VERSION_MINOR})

    add_custom_command(TARGET geodma_mod_tvplugin POST_BUILD 
                       COMMAND ${CMAKE_COMMAND} -E copy
                               "$<TARGET_FILE:geodma_mod_tvplugin>"
                               "${terralib_DIR}/$<CONFIGURATION>"
                       COMMENT "Copying 'geodma_mod_tvplugin' library to '${terralib_DIR}/$<CONFIGURATION>'"
                       VERBATIM
    )

    add_custom_command(TARGET geodma_mod_tvplugin POST_BUILD 
                       COMMAND ${CMAKE_COMMAND} -E copy
                               "${GEODMA_ICONS_DIR}/scalable/icon_geodma.svg"
                               "${terralib_ROOT}/share/terralib/icons/terralib/scalable/icon_geodma.svg"
                       COMMENT "Copying plugin 'icon_geodma.svg' to '${terralib_ROOT}/share/terralib/icons/terralib/scalable'"
                       VERBATIM
    )

    add_custom_command(TARGET geodma_mod_tvplugin POST_BUILD 
                       COMMAND ${CMAKE_COMMAND} -E copy
                               "${GEODMA_ICONS_DIR}/scalable/icon_geodma_name.svg"
                               "${terralib_ROOT}/share/terralib/icons/terralib/scalable/icon_geodma_name.svg"
                       COMMENT "Copying plugin 'icon_geodma_name.svg' to '${terralib_ROOT}/share/terralib/icons/terralib/scalable'"
                       VERBATIM
    )

    add_custom_command(TARGET geodma_mod_tvplugin POST_BUILD 
                       COMMAND ${CMAKE_COMMAND} -E copy
                               "${GEODMA_ICONS_DIR}/scalable/remove_entry.svg"
                               "${terralib_ROOT}/share/terralib/icons/terralib/scalable/remove_entry.svg"
                       COMMENT "Copying plugin 'remove_entry.svg' to '${terralib_ROOT}/share/terralib/icons/terralib/scalable'"
                       VERBATIM
    )

    add_custom_command(TARGET geodma_mod_tvplugin POST_BUILD 
                       COMMAND ${CMAKE_COMMAND} -E copy
                               "${GEODMA_ICONS_DIR}/scalable/save_samples.svg"
                               "${terralib_ROOT}/share/terralib/icons/terralib/scalable/save_samples.svg"
                       COMMENT "Copying plugin 'save_samples.svg' to '${terralib_ROOT}/share/terralib/icons/terralib/scalable'"
                       VERBATIM
    )

    add_custom_command(TARGET geodma_mod_tvplugin POST_BUILD 
                       COMMAND ${CMAKE_COMMAND} -E copy
                               "${GEODMA_ICONS_DIR}/scalable/changeColor.svg"
                               "${terralib_ROOT}/share/terralib/icons/terralib/scalable/changeColor.svg"
                       COMMENT "Copying plugin 'changeColor.svg' to '${terralib_ROOT}/share/terralib/icons/terralib/scalable'"
                       VERBATIM
    )

    add_custom_command(TARGET geodma_mod_tvplugin POST_BUILD 
                       COMMAND ${CMAKE_COMMAND} -E copy
                               "${GEODMA_ICONS_DIR}/scalable/changeLabel.svg"
                               "${terralib_ROOT}/share/terralib/icons/terralib/scalable/changeLabel.svg"
                       COMMENT "Copying plugin 'changeLabel.svg' to '${terralib_ROOT}/share/terralib/icons/terralib/scalable'"
                       VERBATIM
    )

    add_custom_command(TARGET geodma_mod_tvplugin POST_BUILD 
                       COMMAND ${CMAKE_COMMAND} -E copy
                               "${GEODMA_ICONS_DIR}/scalable/decisionTree.svg"
                               "${terralib_ROOT}/share/terralib/icons/terralib/scalable/decisionTree.svg"
                       COMMENT "Copying plugin 'decisionTree.svg' to '${terralib_ROOT}/share/terralib/icons/terralib/scalable'"
                       VERBATIM
    )

    add_custom_command(TARGET geodma_mod_tvplugin POST_BUILD 
                       COMMAND ${CMAKE_COMMAND} -E copy
                               "${GEODMA_ICONS_DIR}/scalable/decisionTree_Classification.svg"
                               "${terralib_ROOT}/share/terralib/icons/terralib/scalable/decisionTree_Classification.svg"
                       COMMENT "Copying plugin 'decisionTree_Classification.svg' to '${terralib_ROOT}/share/terralib/icons/terralib/scalable'"
                       VERBATIM
    )

    add_custom_command(TARGET geodma_mod_tvplugin POST_BUILD 
                       COMMAND ${CMAKE_COMMAND} -E copy
                               "${GEODMA_ICONS_DIR}/scalable/k_means.svg"
                               "${terralib_ROOT}/share/terralib/icons/terralib/scalable/k_means.svg"
                       COMMENT "Copying plugin 'k_means.svg' to '${terralib_ROOT}/share/terralib/icons/terralib/scalable'"
                       VERBATIM
    )

    add_custom_command(TARGET geodma_mod_tvplugin POST_BUILD 
                       COMMAND ${CMAKE_COMMAND} -E copy
                               "${GEODMA_ICONS_DIR}/scalable/kmeans_cluster.svg"
                               "${terralib_ROOT}/share/terralib/icons/terralib/scalable/kmeans_cluster.svg"
                       COMMENT "Copying plugin 'kmeans_cluster.svg' to '${terralib_ROOT}/share/terralib/icons/terralib/scalable'"
                       VERBATIM
    )

    add_custom_command(TARGET geodma_mod_tvplugin POST_BUILD
                       COMMAND ${CMAKE_COMMAND} -E copy
                               "${GEODMA_SHARE_DIR}/plugin/gdma.tvplugin.teplg.json"
                               "${terralib_ROOT}/share/terralib/plugins/gdma.tvplugin.teplg.json"
                       COMMENT "Copying plugin 'gdma.tvplugin.teplg.json' to '${terralib_ROOT}/share/terralib/plugins/'"
                       VERBATIM
    )

    add_custom_command(TARGET geodma_mod_tvplugin POST_BUILD
                       COMMAND ${CMAKE_COMMAND} -E copy_directory
                               "${GEODMA_DOC_DIR}/qhelp/src/geodma/"
                               "${terralib_ROOT}/built/share/terraview/help/plugins/geodma/"
                       COMMENT "Copying plugin 'help files' to '${terralib_ROOT}/built/share/terraview/help/plugins/geodma/'"
                       VERBATIM
    )

    # add_custom_command(TARGET geodma_mod_tvplugin POST_BUILD
    #                    COMMAND ${CMAKE_COMMAND} -E copy
    #                            "${GEODMA_DOC_DIR}/qhelp/src/geodma/decision_trees/geodma_c50_decision_trees.html"
    #                            "${terralib_ROOT}/built/share/terraview/help/plugins/geodma/decision_trees/geodma_c50_decision_trees.html"
    #                    COMMENT "Copying plugin 'geodma_c50_decision_trees.html' to '${terralib_ROOT}/built/share/terraview/help/plugins/geodma/decision_trees/'"
    #                    VERBATIM
    # )
endif()

#if(MSVC)
#    add_custom_command(
#        TARGET terralib_mod_qt_plugins_layout
##        POST_BUILD
#      COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_BINARY_DIR}/Debug ${terralib_DIR}/debug
#        
#        COMMENT "Copying plugin files..."
#        VERBATIM
##      )
#    add_custom_command(
#        TARGET terralib_mod_qt_plugins_layout
#        POST_BUILD
#      COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_BINARY_DIR}/Release ${terralib_DIR}/release
#        
#        COMMENT "Copying plugin files..."
#        VERBATIM
#      )
#endif()

## @TODO SET HERE INSTALL COMMANDS