# Description: Example for the extraction of features from a segment of an image using TerraLib 
#
#  Author: Raian Vargas Maretto <raian@dpi.inpe.br>
#          Thales Sehn Korting <tkorting@dpi.inpe.br>
#          Emiliano Ferreira Castejon <castejon@dpi.inpe.br>
#

cmake_minimum_required(VERSION 3.1.3)
project(geodma)

################################################################################
#
# Main Variables for the build script
#
################################################################################

# variables that control the system versioning
set(GEODMA_VERSION_MAJOR 2)
set(GEODMA_VERSION_MINOR 0)
set(GEODMA_VERSION_PATCH 0)
set(GEODMA_VERSION_STATUS "alpha_3")
set(GEODMA_VERSION_STRING "${GEODMA_VERSION_MAJOR}.${GEODMA_VERSION_MINOR}.${GEODMA_VERSION_PATCH}-${GEODMA_VERSION_STATUS}")
set(GEODMA_PKG_VERSION "${GEODMA_VERSION_MAJOR}.${GEODMA_VERSION_MINOR}.${GEODMA_VERSION_PATCH}")


# Variables that contain project directories
set(GEODMA_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../..)
set(BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/bin)
set(GEODMA_SRC_DIR ${GEODMA_ROOT_DIR}/src)
set(GEODMA_DOC_DIR ${GEODMA_ROOT_DIR}/doc)
set(GEODMA_SHARE_DIR ${GEODMA_ROOT_DIR}/share)
set(GEODMA_ICONS_DIR ${GEODMA_SHARE_DIR}/icons)
set(GEODMA_TESTS_DIR ${GEODMA_ROOT_DIR}/tests)
set(GEODMA_DATA_DIR ${GEODMA_ROOT_DIR}/data)

# variables that control paths
if(NOT DEFINED GEODMA_DIR_VAR_NAME)
  set(GEODMA_DIR_VAR_NAME "GEODMA_HOME" CACHE STRING "Name of an environment variable with the base installation path of GeoDMA")
endif()

# this is the directory where additional scritps are located
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/find ${CMAKE_CURRENT_SOURCE_DIR}/code_style)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/modules")

# Defining the directory where terralib project is located
if(NOT DEFINED terralib_DIR)
    if(WIN32)
        set(terralib_DIR "C:/Program Files/terralib5.2.1"
            CACHE PATH "Path to the directory where TerraLib 5 is installed.")
    else()
        set(terralib_DIR /usr/local/terralib 
            CACHE PATH "Path to the directory where TerraLib 5 is installed.")
    endif()
endif()

if(WIN32 AND NOT DEFINED terralib_DEPENDENCIES_DIR)
    set(terralib_DEPENDENCIES_DIR ${GEODMA_ROOT_DIR}/../dependencies/terralib5-3rdparty-msvc-2013-win64
        CACHE PATH "Path to the directory where TerraLib third party Dependencies are located.")
endif()

# Defining the example data directory
if(NOT DEFINED GEODMA_DATA_DIR)
    set(GEODMA_DATA_DIR ${GEODMA_ROOT_DIR}/data
        CACHE PATH "Path to the directory where are located the example data.")
endif()

# Defining the directory where gtest is installed
if(NOT DEFINED GTEST_ROOT)
    if(WIN32)
        set(GTEST_ROOT C:/googletest-1.8.0/googletest
            CACHE PATH "Path to the directory where GTest is installed.")
    else()
        set(GTEST_ROOT /usr/local 
            CACHE PATH "Path to the directory where GTest is installed.")
    endif()
endif()

# Defining the directory where gtest is installed
if(NOT DEFINED GMOCK_ROOT)
    if(WIN32)
        set(GMOCK_ROOT C:/googletest-1.8.0/googlemock
            CACHE PATH "Path to the directory where GTest is installed.")
    else()
        set(GMOCK_ROOT /usr/local 
            CACHE PATH "Path to the directory where GTest is installed.")
    endif()
endif()

if(NOT DEFINED C50_ROOT)
    if(WIN32)
        set(C50_ROOT ${GEODMA_ROOT_DIR}/../dependencies/c50_decisionTree
            CACHE PATH "Path to the directory where C5.0 is installed.")
    else()
        set(C50_ROOT /usr/local 
            CACHE PATH "Path to the directory where C5.0 is installed.")
    endif()
endif()

################################################################################
#
# including CMake's auxiliary files
#
################################################################################

include(CMakeDependentOption)

################################################################################
#
# Search for main dependencies
#
################################################################################
# ----------------------
# Search for Thread

find_package (Threads)
if(Threads_FOUND)
    message( "Threads libraries found")
else()
    message( "Could not find Threads libraries")
endif()

# ----------------------
# Search for TerraLib
find_package(terralib REQUIRED)
if(NOT terralib_FOUND)
    message(FATAL_ERROR "Could not find required TerraLib libraries!")
else()
    list(APPEND terralib_INCLUDE_DIRS ${terralib_DIR} ${terralib_INCLUDE_DIRS}/terralib)

    find_package(TerraLibPaths)

    if(NOT terralib_PATHS_FOUND)
        if(WIN32)
            set(terralib_ROOT ${terralib_DIR}/../../
                CACHE PATH "Path to the directory where TerraLib 5 is installed.")
            set(TERRALIB_GDAL_DATA_DIR ${terralib_DEPENDENCIES_DIR}/data
                CACHE PATH "Path to the directory where GDAL DATA files are located.")
        else()
            set(terralib_ROOT /usr/local/terralib 
                CACHE PATH "Path to the directory where TerraLib 5 is installed.")
        endif()
    endif()

endif()

# ----------------------
# Search for Boost
find_package(Boost 1.58 REQUIRED system date_time chrono timer filesystem thread)
if(NOT Boost_FOUND)
    message(FATAL_ERROR "Could not find required Boost libraries!")
endif()

# ----------------------
# Search for CGAL (Computational Geometry Algorithms Library)
find_package(CGAL REQUIRED COMPONENTS Core)
if(CGAL_FOUND)
    include(${CGAL_USE_FILE})
    message("CGAL: ${CGAL_LIBRARIES_DIR}")
else()
    message(FATAL_ERROR "Could not find required CGAL libraries!")
endif()

find_package(GTest)

find_package(GMock)

find_package(Qt5 5.1 REQUIRED COMPONENTS Core Gui Widgets PrintSupport)

find_package(C50Lib REQUIRED)

find_package(Doxygen)

if(NOT QT_QCOLLECTIONGENERATOR_EXECUTABLE)
  find_program(QT_QCOLLECTIONGENERATOR_EXECUTABLE
               NAME qcollectiongenerator
               PATHS /usr
                     /usr/local
                     ${Qt5_DIR}/../../..
               PATH_SUFFIXES bin)
endif()

################################################################################
#
# Build options
# warning: please, do not change the order below!
#
################################################################################

option(GEODMA_MOD_COMMON_ENABLED "Build Common functions module?" ON)

cmake_dependent_option(GEODMA_MOD_FTE_ENABLED "Build Feature Extraction module?" ON
                       "Threads_FOUND;CGAL_FOUND;GEODMA_MOD_COMMON_ENABLED"
                       OFF)

option(GEODMA_MOD_CLASSIFICATION_ENABLED "Build Classification module?" ON)

option(GEODMA_MOD_DM_ENABLED "Build Data Manager module?" ON)

cmake_dependent_option(GEODMA_MOD_TP_ENABLED "Build Task Processing module?" ON
                       "Threads_FOUND;GEODMA_MOD_COMMON_ENABLED"
                       OFF)

cmake_dependent_option(GEODMA_MOD_SA_ENABLED "Build Semantic Analysis module?" ON
                       "Threads_FOUND;Boost_FOUND;GEODMA_MOD_COMMON_ENABLED;GEODMA_MOD_DM_ENABLED;GEODMA_MOD_TP_ENABLED;GEODMA_MOD_FTE_ENABLED"
                       OFF)

option(GEODMA_MOD_GUICMP_ENABLED "Build Gui Components module?" ON)

cmake_dependent_option(GEODMA_MOD_TVPLUGIN_ENABLED "Build GeoDMA TerraView Plugin module?" ON
                       "GEODMA_MOD_COMMON_ENABLED;GEODMA_MOD_FTE_ENABLED;GEODMA_MOD_DM_ENABLED;GEODMA_MOD_GUICMP_ENABLED"
                       OFF)

# TODO: Review this part. This variable must have another name, even as the module
cmake_dependent_option(GEODMA_EXECUTABLE "Build GeoDMA Application Executable?" ON
                       "GEODMA_MOD_COMMON_ENABLED;GEODMA_MOD_FTE_ENABLED;GEODMA_MOD_DM_ENABLED" 
                       OFF)

# variable indicating that it will search for 3rd-party libraries and install them
if(NOT DEFINED GEODMA_TRACK_3RDPARTY_DEPENDENCIES)
    set(GEODMA_TRACK_3RDPARTY_DEPENDENCIES 0 CACHE BOOL "If \"on\" it will search for 3rd-party libraries and install them when building the install target (e.g.: make install)")
endif()

### Enable or disable source code verification through cppling
option(GEODMA_SOURCE_VERIFY_ENABLED
       "Enable the automatic verification of the source code through cpplint.py." ON)

### Enable or disable source code documentation through Doxygen
cmake_dependent_option(GEODMA_DOXYGEN_ENABLED 
    "Enable the automatic verification of the source code documentation through doxygen." ON
    "DOXYGEN_FOUND"
    OFF)

if(QT_QCOLLECTIONGENERATOR_EXECUTABLE)
  CMAKE_DEPENDENT_OPTION(GEODMA_QHELP_ENABLED  "Enable Qt-Help build?" ON "GEODMA_MOD_TVPLUGIN_ENABLED" OFF)
endif()

if(GTEST_FOUND)
    option(GEODMA_UNITTEST_ENABLED "Build Unit tests for the Feature Extraction module" ON)
endif()

if(APPLE)
    cmake_dependent_option(BUILD_GEODMA_AS_BUNDLE "If on, tells that the build will generate a bundle" OFF
                           "GEODMA_EXECUTABLE" OFF)
endif()

# variable that set the bundle items as writable before install_name_tool tries to change them (for APPLE platforms)
if(APPLE AND BUILD_GEODMA_AS_BUNDLE AND GEODMA_TRACK_3RDPARTY_DEPENDENCIES AND NOT DEFINED BU_CHMOD_BUNDLE_ITEMS)
    set(BU_CHMOD_BUNDLE_ITEMS ON CACHE BOOL "If ON, set the bundle items as writable")
endif()

################################################################################
#
# Setting Destination of built files
#
################################################################################

if(APPLE AND BUILD_GEODMA_AS_BUNDLE AND NOT DEFINED GEODMA_BASE_DESTINATION_DIR)
    set(GEODMA_BASE_DESTINATION_DIR "geodma.app/Contents/")
elseif(NOT DEFINED GEODMA_BASE_DESTINATION_DIR)
    set(GEODMA_BASE_DESTINATION_DIR "")
endif()

if(NOT DEFINED GEODMA_DESTINATION_LIBRARY)
    set(GEODMA_DESTINATION_LIBRARY "${GEODMA_BASE_DESTINATION_DIR}lib")
endif()

if(NOT DEFINED GEODMA_DESTINATION_RUNTIME)
    set(GEODMA_DESTINATION_RUNTIME "${GEODMA_BASE_DESTINATION_DIR}bin")
endif()

if(NOT DEFINED GEODMA_DESTINATION_ARCHIVE)
    set(GEODMA_DESTINATION_ARCHIVE "${GEODMA_BASE_DESTINATION_DIR}lib")
endif()

if(NOT DEFINED GEODMA_DESTINATION_HEADERS)
    set(GEODMA_DESTINATION_HEADERS "${GEODMA_BASE_DESTINATION_DIR}include")
endif()

if(NOT DEFINED GEODMA_DESTINATION_SHARE)
    set(GEODMA_DESTINATION_SHARE "${GEODMA_BASE_DESTINATION_DIR}share")
endif()

if(NOT DEFINED GEODMA_DESTINATION_DATA)
    set(GEODMA_DESTINATION_DATA "${GEODMA_BASE_DESTINATION_DIR}data")
endif()

###########
# Settings to build files into a single folder
if((CMAKE_GENERATOR STREQUAL Xcode) OR MSVC)
    set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
    set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
    set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
else()
    set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
    set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
    set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
endif()

#################################################################################
#
# Destination of TerraView Plugin
#
################################################################################

if(GEODMA_MOD_TVPLUGIN_ENABLED)
    set(GEODMA_DESTINATION_PLUGIN "C:/Program Files/terralib5.3.3/") # @TODO(RAIAN): Change this. Try to get terralib version from a variable
    set(GEODMA_DESTINATION_PLUGIN_SHARE "${GEODMA_DESTINATION_PLUGIN}share")
endif()

################################################################################
#
# global definitions and includes
#
################################################################################
add_definitions(-DBOOST_ALL_NO_LIB -DBOOST_FILESYSTEM_VERSION=3 -DBOOST_UBLAS_TYPE_CHECK=0)

if(WIN32)
    if(MINGW)
        add_definitions(-DTE_MINGW -D_WIN32_WINNT=0x601 -fpermissive)
    endif()
elseif(APPLE)
    add_definitions(-ftemplate-depth-1024 -Wc++11-extensions -std=c++11)
    set(CMAKE_INSTALL_NAME_DIR "@executable_path/../lib")
elseif(UNIX)
    if(CMAKE_COMPILER_IS_GNUCC)
      if(CMAKE_BUILD_TYPE==Release)
        add_definitions(-g -O0)
      endif()
    endif()
    set(CMAKE_INSTALL_NAME_DIR "@executable_path/../lib")
endif()

if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX OR (CMAKE_CXX_COMPILER MATCHES ".*clang") OR (CMAKE_CXX_COMPILER_ID STREQUAL "Clang"))
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic -std=c++11")
endif()

# Turn on multi process compilation
if(MSVC)
    add_definitions(/MP)
    set(CMAKE_DEBUG_POSTFIX "d")
endif()

################################################################################
#
# Searching for CPP lint check dependencies
#
################################################################################

if(GEODMA_SOURCE_VERIFY_ENABLED)
    message("    -> Code style verification enabled!")
    find_package(PythonInterp 2.7 REQUIRED)
    if(PYTHONINTERP_FOUND)
        include(CodeStyleCheck)
    else()
        message(FATAL_ERROR "Could not find Python interpreter. It is required to enable the CppLint check.")
    endif()
endif()

################################################################################
#
# Defining Configure files
#
################################################################################

configure_file(${GEODMA_SRC_DIR}/BuildConfig.hpp.in
               ${CMAKE_BINARY_DIR}/geodmaconfig_files/geodma_buildconfig.hpp @ONLY)

configure_file(${GEODMA_ROOT_DIR}/COPYING ${CMAKE_BINARY_DIR}/COPYING.txt COPYONLY)

include_directories(${CMAKE_BINARY_DIR}/geodmaconfig_files
                    ${GEODMA_SRC_DIR}
)

################################################################################
#
# Build Modules
#
################################################################################

message("-- Checking Modules!")

##############
# GeoDMA Data Manager Module
if(GEODMA_MOD_COMMON_ENABLED)
    message("    -> Common module enabled!")
    add_subdirectory(geodma_mod_common)
endif()

##############
# GeoDMA Data Manager Module
if(GEODMA_MOD_DM_ENABLED)
    message("    -> Data Manager module enabled!")
    add_subdirectory(geodma_mod_datamanager)
endif()

##############
# GeoDMA Feature Extraction Module
if(GEODMA_MOD_FTE_ENABLED)
    message("    -> Feature extraction module enabled!")
    add_subdirectory(geodma_mod_featextraction)
endif()

##############
# GeoDMA Classification Module
if(GEODMA_MOD_CLASSIFICATION_ENABLED)
    message("    -> Classification module enabled!")
    add_subdirectory(geodma_mod_classification)
endif()

##############
# GeoDMA Task Processing
if(GEODMA_MOD_TP_ENABLED)
    message("    -> Task Processing module enabled!")
    add_subdirectory(geodma_mod_taskprocessing)
endif()

##############
# GeoDMA Semantic Analysis
if(GEODMA_MOD_SA_ENABLED)
    message("    -> Semantic Analysis module enabled!")
    add_subdirectory(geodma_mod_semanticanalysis)
endif()

##############
# GeoDMA Executable - TODO: REVIEW
if(GEODMA_EXECUTABLE)
    message("    -> GeoDMA Executable enabled")
    add_subdirectory(geodma_executable)
endif()

if(GEODMA_MOD_GUICMP_ENABLED)
    message("    -> GeoDMA Gui Components enabled")
    add_subdirectory(geodma_mod_guicomponents)
endif()

if(GEODMA_MOD_TVPLUGIN_ENABLED)
    message("    -> GeoDMA TerraView Plugin enabled")
    add_subdirectory(geodma_mod_tvplugin)
endif()

##############
# API Documentation generation with Doxygen
if(GEODMA_DOXYGEN_ENABLED)
    message("    -> Doxygen Documentation enabled")

    # find_package(LATEX)

    # if(NOT LATEX_FOUND)
    #    MESSAGE(WARNING "Could not find LaTeX compiler. It is recomended to use it to the corect generation of Doxygen Documentation.")
    # endif()

    if(DOXYGEN_FOUND)
        add_subdirectory(geodma_doxygen)
    else()
        message(FATAL_ERROR "Could not find Doxygen. It is needed to build the documentation.")
    endif()
endif()

if(GEODMA_QHELP_ENABLED)
  add_subdirectory(geodma_qhelp)
endif()

if(GEODMA_MOD_TVPLUGIN_ENABLED)
  add_subdirectory(plugin_installer)
endif()

################################################################################
#
# Build Tests
#
################################################################################

if(GEODMA_UNITTEST_ENABLED)
    message("    -> Unit Tests enabled")

    if(GTEST_FOUND)
        add_subdirectory(geodma_unittest)
    else()
        message(FATAL_ERROR "Could not find Google Test. It is needed to build the tests.")
    endif()
endif()

################################################################################
#
# install and targets export
#
################################################################################

configure_file(${CMAKE_SOURCE_DIR}/geodma-config.cmake.in
               ${CMAKE_BINARY_DIR}/geodma-config.cmake @ONLY)

configure_file(${CMAKE_SOURCE_DIR}/geodma-config-pkg.cmake.in
               ${CMAKE_BINARY_DIR}/pkg/geodma-config.cmake @ONLY)

configure_file(${CMAKE_SOURCE_DIR}/geodma-config-version.cmake.in
               ${CMAKE_BINARY_DIR}/geodma-config-version.cmake @ONLY)

if(GEODMA_MOD_TVPLUGIN_ENABLED) 
    # Plug-in file
    file(GLOB GEODMA_JSON_FILES ${GEODMA_ROOT_DIR}/share/plugin/*.json)
    install(
        FILES ${GEODMA_JSON_FILES}
        DESTINATION ${GEODMA_DESTINATION_PLUGIN_SHARE}/terralib/plugins
        COMPONENT TerraViewPlugin
    )

    # Icon files
    install(
        DIRECTORY ${GEODMA_ROOT_DIR}/share/icons/
        DESTINATION ${GEODMA_DESTINATION_PLUGIN_SHARE}/terralib/icons/terralib/scalable
        COMPONENT TerraViewPlugin
    )
endif()

# @TODO(Raian): Verify these config files. Are they really necessary? 
install(FILES ${geodma_BINARY_DIR}/pkg/geodma-config.cmake
              ${geodma_BINARY_DIR}/geodma-config-version.cmake
        DESTINATION ${GEODMA_DESTINATION_LIBRARY}/cmake/geodma-${GEODMA_PKG_VERSION} 
        COMPONENT devel)

install(EXPORT geodma-targets
        DESTINATION ${GEODMA_DESTINATION_LIBRARY}/cmake/geodma-${GEODMA_PKG_VERSION}
        FILE geodma-exports.cmake
        COMPONENT devel)

file(GLOB GEODMA_HDR_FILES ${GEODMA_ROOT_DIR}/src/*.h)

install(FILES ${CMAKE_BINARY_DIR}/geodmaconfig_files/geodma_buildconfig.hpp
              ${TERRALIB_HDR_FILES}
        DESTINATION ${GEODMA_DESTINATION_HEADERS}
        COMPONENT devel)

install(FILES ${GEODMA_SRC_DIR}/BuildConfig.hpp
        DESTINATION ${GEODMA_DESTINATION_HEADERS}
        COMPONENT devel)

#install(DIRECTORY ${GEODMA_DATA_DIR}/
#        DESTINATION ${GEODMA_DESTINATION_DATA} 
#        COMPONENT data)

# TerraLib Files
#install(DIRECTORY ${terralib_ROOT}/share/terralib/config/
#        DESTINATION ${GEODMA_DESTINATION_SHARE}/terralib/config/ 
#        COMPONENT runtime)

#install(DIRECTORY ${terralib_ROOT}/share/terralib/json/
#        DESTINATION ${GEODMA_DESTINATION_SHARE}/terralib/json/
#        COMPONENT runtime)

#install(DIRECTORY ${terralib_ROOT}/share/terralib/schemas/
#        DESTINATION ${GEODMA_DESTINATION_SHARE}/terralib/schemas/
#        COMPONENT runtime)

#install(FILES ${terralib_ROOT}/share/terralib/plugins/te.da.gdal.teplg.json
#        DESTINATION ${GEODMA_DESTINATION_SHARE}/terralib/plugins/
#        COMPONENT runtime)

#install(FILES ${terralib_ROOT}/share/terralib/plugins/te.da.ogr.teplg.json
#        DESTINATION ${GEODMA_DESTINATION_SHARE}/terralib/plugins/
#        COMPONENT runtime)

#install(DIRECTORY ${TERRALIB_GDAL_DATA_DIR}/
#        DESTINATION ${GEODMA_DESTINATION_SHARE}/data/
#        COMPONENT runtime)

#TerraLib Plugins

#get_target_property(TERRALIB_PLUGIN_OGR terralib_mod_ogr LOCATION_RELEASE)
#get_target_property(TERRALIB_PLUGIN_GDAL terralib_mod_gdal LOCATION_RELEASE)

#get_filename_component(TERRALIB_PLUGIN_OGR_NAME ${TERRALIB_PLUGIN_OGR} NAME)
#get_filename_component(TERRALIB_PLUGIN_GDAL_NAME ${TERRALIB_PLUGIN_GDAL} NAME)

#set (TERRALIB_PLUGINS ${TERRALIB_PLUGIN_OGR} 
#                      ${TERRALIB_PLUGIN_GDAL})

#install(FILES ${TERRALIB_PLUGINS}
#        DESTINATION ${GEODMA_DESTINATION_RUNTIME}
#        COMPONENT runtime)


################################################################################
#
# Track dependencies
#
################################################################################

if(GEODMA_TRACK_3RDPARTY_DEPENDENCIES)
    message("-> Track Third party libraries enabled")
    #set(CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_SKIP ON)

    include(InstallRequiredSystemLibraries)

    #install(PROGRAMS ${CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS}
    #        DESTINATION bin
    #        COMPONENT runtime)

    add_subdirectory(fix_bundle)
endif()

################################################################################
#
# CPack
#
################################################################################

set(CPACK_SOURCE_INSTALLED_DIRECTORIES "${GEODMA_ROOT_DIR};/")

configure_file(${geodma_SOURCE_DIR}/geodma-cpack-options.cmake.in
               ${geodma_BINARY_DIR}/geodmaCPackOptions.cmake @ONLY)

set(CPACK_PROJECT_CONFIG_FILE ${geodma_BINARY_DIR}/geodmaCPackOptions.cmake)

include(CPack)

# defining installation types, components and groups
cpack_add_install_type(full DISPLAY_NAME "Complete")
cpack_add_install_type(minimalistic DISPLAY_NAME "Minimalistic")

cpack_add_component_group(general_group
                          DISPLAY_NAME "Applications"
                          DESCRIPTION "GeoDMA Stand Alone Application"
                          EXPANDED)

cpack_add_component_group(devel_group
                          DISPLAY_NAME "Development Tools"
                          DESCRIPTION "Development Tools: header files, libraries and cmake stuffs"
                          EXPANDED)

cpack_add_component_group(data_group
                          DISPLAY_NAME "Data"
                          DESCRIPTION "Example data"
                          EXPANDED)

cpack_add_component(runtime
                    DISPLAY_NAME "Runtime Libraries and Executables"
                    DESCRIPTION "Install only necessary shared libraries (or DLLs) and executables"
                    GROUP general_group
                    INSTALL_TYPES full minimalistic)

cpack_add_component(devel
                    DISPLAY_NAME "Development package"
                    DESCRIPTION "Install header files, cmake stuffs and additional shared libraries"
                    GROUP devel_group
                    INSTALL_TYPES full minimalistic)

cpack_add_component(data
                    DISPLAY_NAME "Example Data"
                    DESCRIPTION "Install some sample data, used to run the examples"
                    GROUP data_group
                    INSTALL_TYPES full minimalistic)

#
# Uninstall target
#

configure_file(
    "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
    "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
    IMMEDIATE @ONLY)

add_custom_target(uninstall
    COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
