# Description: Script for generating the GeoDMA plugin installer.
#
#  Author: Raian Vargas Maretto <raian@dpi.inpe.br>
#          Thales Sehn Korting <tkorting@dpi.inpe.br>
#          Emiliano Ferreira Castejon <castejon@dpi.inpe.br>
#

add_custom_command(
    OUTPUT copy_geodma_libs
    COMMAND ${CMAKE_COMMAND} -E copy  $<TARGET_FILE:geodma_mod_common> ${CMAKE_BINARY_DIR}/plugin_installer/installer/bin/$<TARGET_FILE_NAME:geodma_mod_common>
    COMMAND ${CMAKE_COMMAND} -E copy  $<TARGET_FILE:geodma_mod_datamanager> ${CMAKE_BINARY_DIR}/plugin_installer/installer/bin/$<TARGET_FILE_NAME:geodma_mod_datamanager>
    COMMAND ${CMAKE_COMMAND} -E copy  $<TARGET_FILE:geodma_mod_featextraction> ${CMAKE_BINARY_DIR}/plugin_installer/installer/bin/$<TARGET_FILE_NAME:geodma_mod_featextraction>
    COMMAND ${CMAKE_COMMAND} -E copy  $<TARGET_FILE:geodma_mod_classification> ${CMAKE_BINARY_DIR}/plugin_installer/installer/bin/$<TARGET_FILE_NAME:geodma_mod_classification>
    COMMAND ${CMAKE_COMMAND} -E copy  $<TARGET_FILE:geodma_mod_semanticanalysis> ${CMAKE_BINARY_DIR}/plugin_installer/installer/bin/$<TARGET_FILE_NAME:geodma_mod_semanticanalysis>
    COMMAND ${CMAKE_COMMAND} -E copy  $<TARGET_FILE:geodma_mod_taskprocessing> ${CMAKE_BINARY_DIR}/plugin_installer/installer/bin/$<TARGET_FILE_NAME:geodma_mod_taskprocessing>
    COMMAND ${CMAKE_COMMAND} -E copy  $<TARGET_FILE:geodma_mod_guicomponents> ${CMAKE_BINARY_DIR}/plugin_installer/installer/bin/$<TARGET_FILE_NAME:geodma_mod_guicomponents>
    COMMAND ${CMAKE_COMMAND} -E copy  $<TARGET_FILE:geodma_mod_tvplugin> ${CMAKE_BINARY_DIR}/plugin_installer/installer/bin/$<TARGET_FILE_NAME:geodma_mod_tvplugin>
    COMMENT "Copying GeoDMA Libraries..."
)

# TODO: How to copy CGAL files here? See: https://cmake.org/pipermail/cmake/2012-January/048484.html
# This strategy is not working. Is there a better way to do this?
message("CGAL Libraries: '${CGAL_CONFIGURED_LIBRARIES}'")
add_custom_command(
    OUTPUT copy_cgal_libs
    COMMAND ${CMAKE_COMMAND} -E copy  "${CGAL_LIBRARIES_DIR}/../bin/*.dll" ${CMAKE_BINARY_DIR}/plugin_installer/installer/bin/
    COMMENT "Copying CGAL Libraries..."
)

add_custom_target(
    plugin_installer
    DEPENDS copy_geodma_libs
    		copy_cgal_libs
    COMMENT "Generating Plugin Installer"
    VERBATIM
)

# if(MSVC)
#     add_custom_command(TARGET geodma_qhelp POST_BUILD
#                        COMMAND ${CMAKE_COMMAND} -E copy_directory
#                                "${CMAKE_BINARY_DIR}/share/geodma/help/"
#                                "${terralib_ROOT}/built/share/terraview/help"
#                        COMMENT "Copying plugin 'help files' to '${terralib_ROOT}/built/share/terraview/help'"
#                        VERBATIM
#         )
# endif()

# install(DIRECTORY ${CMAKE_BINARY_DIR}/share/geodma/help/
#         DESTINATION ${TERRALIB_DESTINATION_SHARE}/help/terraview/ COMPONENT runtime)
        
# if(Qt5_FOUND AND GEODMA_TRACK_3RDPARTY_DEPENDENCIES AND WIN32)

#     find_program(ASSIST_PRG
#                NAME assistant
#                PATHS ${Qt5_DIR}/../../../bin)

#     if(ASSIST_PRG)
#     install (FILES ${ASSIST_PRG}
#              DESTINATION ${GEODMA_DESTINATION_RUNTIME}
#              PERMISSIONS OWNER_READ OWNER_EXECUTE
#                          GROUP_READ GROUP_EXECUTE
#                          WORLD_READ WORLD_EXECUTE
#              COMPONENT runtime)
#     endif()

# endif()
