#
#  Copyright (C) 2008-2014 National Institute For Space Research (INPE) - Brazil.
#
#  This file is part of the TerraLib - a Framework for building GIS enabled applications.
#
#  TerraLib is free software: you can redistribute it and/or modify
#  it under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation, either version 3 of the License,
#  or (at your option) any later version.
#
#  TerraLib is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#  GNU Lesser General Public License for more details.
#
#  You should have received a copy of the GNU Lesser General Public License
#  along with TerraLib. See COPYING. If not, write to
#  TerraLib Team at <terralib-team@terralib.org>.
#
#
#  Description: Main CMake script for the TerraLib build system.
#
#  Author: Gilberto Ribeiro de Queiroz <gribeiro@dpi.inpe.br>
#          Juan Carlos P. Garrido <juan@dpi.inpe.br>
#          Frederico Augusto T. Bede <frederico.bede@funcate.org.br>
#

cmake_minimum_required(VERSION 2.8.7)

project(terralib)

#
# main variables for the build script
#

# variables that control the system versioning
set(TERRALIB_VERSION_MAJOR 5)
set(TERRALIB_VERSION_MINOR 0)
set(TERRALIB_VERSION_PATCH 0)
set(TERRALIB_VERSION_STATUS "beta1")
set(TERRALIB_VERSION_STRING "${TERRALIB_VERSION_MAJOR}.${TERRALIB_VERSION_MINOR}.${TERRALIB_VERSION_PATCH}-${TERRALIB_VERSION_STATUS}")
set(TERRALIB_VERSION "0x050000")
set(TERRALIB_PKG_VERSION ${TERRALIB_VERSION_MAJOR}.${TERRALIB_VERSION_MINOR}.${TERRALIB_VERSION_PATCH})

# variable indicating that it will search for 3rd-party libraries and install them
if(NOT DEFINED TERRALIB_TRACK_3RDPARTY_DEPENDENCIES)
  set(TERRALIB_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()

# variables storing absolute paths
set(TERRALIB_ABSOLUTE_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../..)

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

if(NOT DEFINED TERRALIB_DATA_DIR)
  set(TERRALIB_DATA_DIR "${CMAKE_BINARY_DIR}/data" CACHE PATH "Path to a directory containing the data used in the examples and/or in the unit test")
endif()

if(NOT DEFINED TERRALIB_REPORT_DIR)
  set(TERRALIB_REPORT_DIR "${CMAKE_BINARY_DIR}/report" CACHE PATH "Path to a directory containing the report used in the examples and/or in the unit test")
endif()

if(APPLE AND TERRALIB_BUILD_AS_BUNDLE AND NOT DEFINED TERRALIB_BASE_DESTINATION_DIR)
  set(TERRALIB_BASE_DESTINATION_DIR "terraview.app/Contents/")
elseif(NOT DEFINED TERRALIB_BASE_DESTINATION_DIR)
  set(TERRALIB_BASE_DESTINATION_DIR "")
endif()

# variables that control the install location
if(NOT DEFINED TERRALIB_DESTINATION_PLUGINS)
  set(TERRALIB_DESTINATION_PLUGINS "${TERRALIB_BASE_DESTINATION_DIR}share/terralib/plugins")
endif()

if(NOT DEFINED TERRALIB_DESTINATION_EXAMPLES)
  set(TERRALIB_DESTINATION_EXAMPLES "${TERRALIB_BASE_DESTINATION_DIR}share/terralib/examples")
endif()

if(NOT DEFINED TERRALIB_DESTINATION_UNITTEST)
  set(TERRALIB_DESTINATION_UNITTEST "${TERRALIB_BASE_DESTINATION_DIR}share/terralib/unittest")
endif()

if(NOT DEFINED TERRALIB_DESTINATION_LIBRARY)
  set(TERRALIB_DESTINATION_LIBRARY "${TERRALIB_BASE_DESTINATION_DIR}lib")
endif()

if(NOT DEFINED TERRALIB_DESTINATION_RUNTIME)
  set(TERRALIB_DESTINATION_RUNTIME "${TERRALIB_BASE_DESTINATION_DIR}bin")
endif()

if(NOT DEFINED TERRALIB_DESTINATION_ARCHIVE)
  set(TERRALIB_DESTINATION_ARCHIVE "${TERRALIB_BASE_DESTINATION_DIR}lib")
endif()

if(NOT DEFINED TERRALIB_DESTINATION_HEADERS)
  set(TERRALIB_DESTINATION_HEADERS "${TERRALIB_BASE_DESTINATION_DIR}include")
endif()

if(NOT DEFINED TERRALIB_DESTINATION_SHARE)
  set(TERRALIB_DESTINATION_SHARE "${TERRALIB_BASE_DESTINATION_DIR}share")
endif()

# variables that controls what is built
if(NOT DEFINED TERRALIB_BUILD_EXAMPLES_ENABLED)
  set(TERRALIB_BUILD_EXAMPLES_ENABLED ON CACHE BOOL "If on, shows the list of examples to be built")
endif()

if(NOT DEFINED TERRALIB_BUILD_UNITTEST_ENABLED)
  set(TERRALIB_BUILD_UNITTEST_ENABLED ON CACHE BOOL "If on, shows the list of unit-tests to be built")
endif()

if(NOT DEFINED TERRALIB_BUILD_AS_BUNDLE)
  set(TERRALIB_BUILD_AS_BUNDLE 0 CACHE BOOL "If on, tells that the build will generate a bundle")
endif()

if(NOT DEFINED TERRALIB_AUTOMATIC_INITIALIZATION)
  set(TERRALIB_AUTOMATIC_INITIALIZATION 1 CACHE BOOL "Tells that TerraLib should initialize its resources automatically")
endif()

# variable that set the bundle items as writable before install_name_tool tries to change them (for APPLE platforms)
if(APPLE AND TERRALIB_BUILD_AS_BUNDLE AND TERRALIB_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()


#
# global definitions and includes
#

add_definitions(-DBOOST_ALL_NO_LIB -DBOOST_FILESYSTEM_VERSION=3 -DBOOST_UBLAS_TYPE_CHECK=0)

if(WIN32)
  add_definitions(-D_CRT_SECURE_NO_WARNINGS)
elseif(APPLE)
  add_definitions(-ftemplate-depth-1024)
endif()

# Note: automatically link executables with qtmain.lib on Windows when it has Qt dependency.
if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER  2.8.9)
  cmake_policy(SET CMP0020 NEW)
endif()

if(${CMAKE_MAJOR_VERSION} GREATER 2)
  cmake_policy(SET CMP0042 NEW)  
  cmake_policy(SET CMP0043 NEW)  
endif()


include_directories(${CMAKE_BINARY_DIR})
include_directories(${TERRALIB_ABSOLUTE_ROOT_DIR}/src)

#
# Build will generate 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()


#
# global configurations
#

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/modules")

if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic")
endif()


#
# including CMake's auxiliary files
#

include(CMakeDependentOption)


#
# including TerraLib auxiliary macros and functions
#

include(terralib_macros.cmake)


#
# first check of libraries
#

find_package(Boost 1.54.0 REQUIRED system date_time chrono timer filesystem thread unit_test_framework)

if(NOT Boost_FOUND)
  message(FATAL_ERROR "TerraLib: could not find required Boost libraries!")
endif()

find_package(Doxygen QUIET)

if(WIN32)

  find_package(ADO)

  find_package(Terralib4)

endif()

find_package(GDAL)

find_package(GEOS)

find_package(GEOSC)

find_package(GNUGettext)

find_package(GNUIConv)

find_package(Log4cxx)

#find_package(Lua51)

find_package(LibPQ)

if(NOT LIBPQ_FOUND)
  find_package(PostgreSQL)
endif()

find_package(Proj4)

find_package(Qt5 5.1 QUIET COMPONENTS Core Gui Widgets PrintSupport)

if(NOT Qt5_FOUND)
  find_package(Qt4 4.6.3 QUIET COMPONENTS QtCore QtGui)
else()
  find_package(Qt5LinguistTools QUIET)
endif()

if(Qt5_FOUND OR QT4_FOUND)
  find_package(Qwt)
  find_package(QtPropertyBrowser)
endif()

find_package(Xerces)

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

find_package(CppUnit)


#
# some variables needed in config file
#

if(Boost_FOUND)
  set(TERRALIB_BOOST_ENABLED ON)
endif()

if(GDAL_FOUND)
  set(TERRALIB_GDAL_ENABLED ON)
endif()

if(GEOS_FOUND)
  set(TERRALIB_GEOS_ENABLED ON)
endif()

if(GEOSC_FOUND)
  set(TERRALIB_GEOSC_ENABLED ON)
endif()

if(GNUGETTEXT_FOUND)

  set(TERRALIB_GNU_GETTEXT_ENABLED ON)

  if(NOT DEFINED TERRALIB_TRANSLATOR_ENABLED)
    set(TERRALIB_TRANSLATOR_ENABLED 1 CACHE BOOL "Enable translator support?")
  endif()

else()

  if(DEFINED TERRALIB_TRANSLATOR_ENABLED)
    set(TERRALIB_TRANSLATOR_ENABLED 0 CACHE BOOL "Enable translator support?" FORCE)
  endif()
  
endif()

if(GNUICONV_FOUND)

  set(TERRALIB_GNU_ICONV_ENABLED ON)

  if(NOT DEFINED TERRALIB_CHARENCODING_ENABLED)
    set(TERRALIB_CHARENCODING_ENABLED 1 CACHE BOOL "Enable character encoding support?")
  endif()

else()

  if(DEFINED TERRALIB_CHARENCODING_ENABLED)
    set(TERRALIB_CHARENCODING_ENABLED 0 CACHE BOOL "Enable character encoding support?" FORCE)
  endif()

endif()

if(LUA51_FOUND)
  set(TERRALIB_LUA_ENABLED ON)
endif()

if(LOG4CXX_FOUND)
  set(TERRALIB_APACHE_LOG4CXX_ENABLED ON)

  if(NOT DEFINED TERRALIB_LOGGER_ENABLED)
    set(TERRALIB_LOGGER_ENABLED 1 CACHE BOOL "Enable logger?")
  endif()

else()

  if(DEFINED TERRALIB_LOGGER_ENABLED)
    set(TERRALIB_LOGGER_ENABLED 0 CACHE BOOL "Enable logger?" FORCE)
  endif()

endif()

if((PostgreSQL_INCLUDE_DIRS AND PostgreSQL_LIBRARIES) OR (PostgreSQL_INCLUDE_DIR AND PostgreSQL_LIBRARY))
  set(TERRALIB_LIBPQ_ENABLED ON)
endif()

if(PROJ4_FOUND)
  set(TERRALIB_PROJ4_ENABLED ON)
endif()

if(QT4_FOUND)
  set(TERRALIB_QT4_ENABLED ON)
  set(TERRALIB_QT_ENABLED ON)
endif()

if(Qt5_FOUND)
  set(TERRALIB_QT5_ENABLED ON)
  set(TERRALIB_QT_ENABLED ON)
endif()

if(QTPROPERTYBROWSER_FOUND)
  set(TERRALIB_QTPROPERTYBROWSER_ENABLED ON)
endif()

if(QWT_FOUND)
  set(TERRALIB_QWT_ENABLED ON)
endif()

if(XERCES_FOUND)
  set(TERRALIB_XERCES_ENABLED ON)
endif()

if(CPPUNIT_FOUND)
  set(TERRALIB_CPPUNIT_ENABLED ON)
endif()


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

if(DOXYGEN_FOUND)
  option(TERRALIB_DOXYGEN_ENABLED  "Enable API documentation build?" ON)
endif()

option(TERRALIB_MOD_COLOR_ENABLED "Build Color module?" ON)

option(TERRALIB_MOD_XML_ENABLED "Build XML module?" ON)

option(TERRALIB_MOD_DATATYPE_ENABLED "Build Data Type module?" ON)

option(TERRALIB_MOD_SRS_ENABLED "Build Spatial Reference System module?" ON)

option(TERRALIB_MOD_XLINK_ENABLED "Build XLink module?" ON)

option(TERRALIB_MOD_XSD_ENABLED "Build XSD module?" ON)

CMAKE_DEPENDENT_OPTION(TERRALIB_MOD_GEOMETRY_ENABLED "Build Geometry module?" ON "TERRALIB_MOD_DATATYPE_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_MOD_SAM_ENABLED "Build Spatial Access Methods?" ON "TERRALIB_MOD_GEOMETRY_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_MOD_ANNOTATIONTEXT_ENABLED "Build Annotation Text module?" ON "TERRALIB_MOD_GEOMETRY_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_MOD_RASTER_ENABLED "Build Raster module?" ON "TERRALIB_MOD_DATATYPE_ENABLED;TERRALIB_MOD_SRS_ENABLED;TERRALIB_MOD_GEOMETRY_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_MOD_DATAACCESS_ENABLED "Build Data Access module?" ON "TERRALIB_MOD_DATATYPE_ENABLED;TERRALIB_MOD_RASTER_ENABLED;TERRALIB_MOD_GEOMETRY_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_MOD_PLUGIN_ENABLED "Build Plugin module?" ON "TERRALIB_MOD_XML_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_MOD_XERCES_ENABLED "Build Xerces support?" ON "TERRALIB_XERCES_ENABLED;TERRALIB_MOD_XML_ENABLED;TERRALIB_MOD_PLUGIN_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_MOD_POSTGIS_ENABLED "Build PostGIS support?" ON "TERRALIB_LIBPQ_ENABLED;TERRALIB_MOD_XML_ENABLED;TERRALIB_MOD_DATAACCESS_ENABLED;TERRALIB_MOD_DATATYPE_ENABLED;TERRALIB_MOD_GEOMETRY_ENABLED;TERRALIB_MOD_PLUGIN_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_MOD_MEMORY_ENABLED "Build Data Access in Memory support?" ON "TERRALIB_MOD_DATAACCESS_ENABLED;TERRALIB_MOD_DATATYPE_ENABLED;TERRALIB_MOD_GEOMETRY_ENABLED;TERRALIB_MOD_RASTER_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_MOD_ADO_ENABLED "Build Microsoft Access support?" ON "WIN32;ADO_FOUND;TERRALIB_MOD_MEMORY_ENABLED;TERRALIB_MOD_XML_ENABLED;TERRALIB_MOD_PLUGIN_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_MOD_OGR_ENABLED "Build OGR support?" ON "TERRALIB_GDAL_ENABLED;TERRALIB_MOD_DATAACCESS_ENABLED;TERRALIB_MOD_DATATYPE_ENABLED;TERRALIB_MOD_GEOMETRY_ENABLED;TERRALIB_MOD_PLUGIN_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_MOD_GDAL_ENABLED "Build GDAL support?" ON "TERRALIB_GDAL_ENABLED;TERRALIB_MOD_DATAACCESS_ENABLED;TERRALIB_MOD_DATATYPE_ENABLED;TERRALIB_MOD_GEOMETRY_ENABLED;TERRALIB_MOD_PLUGIN_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_MOD_GML_ENABLED "Build OGC GML module?" ON "TERRALIB_MOD_GEOMETRY_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_MOD_FILTER_ENABLED "Build OGC Filter module?" ON "TERRALIB_MOD_GEOMETRY_ENABLED;TERRALIB_MOD_GML_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_MOD_SYMBOLOGY_ENABLED "Build OGC Symbology module?" ON "TERRALIB_MOD_COLOR_ENABLED;TERRALIB_MOD_FILTER_ENABLED;TERRALIB_MOD_XLINK_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_MOD_MAPTOOLS_ENABLED "Build Map Tools module?" ON "TERRALIB_MOD_ANNOTATIONTEXT_ENABLED;TERRALIB_MOD_COLOR_ENABLED;TERRALIB_MOD_DATAACCESS_ENABLED;TERRALIB_MOD_DATATYPE_ENABLED;TERRALIB_MOD_FILTER_ENABLED;TERRALIB_MOD_GEOMETRY_ENABLED;TERRALIB_MOD_GML_ENABLED;TERRALIB_MOD_MEMORY_ENABLED;TERRALIB_MOD_RASTER_ENABLED;TERRALIB_MOD_SRS_ENABLED;TERRALIB_MOD_SYMBOLOGY_ENABLED;TERRALIB_MOD_XLINK_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_MOD_CLASSIFICATION_ENABLED "Build Classification module?" ON "TERRALIB_MOD_DATAACCESS_ENABLED;TERRALIB_MOD_DATATYPE_ENABLED;TERRALIB_MOD_GEOMETRY_ENABLED;TERRALIB_MOD_MEMORY_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_MOD_METADATA_ENABLED "Build Metadata module?" ON "TERRALIB_MOD_DATAACCESS_ENABLED;TERRALIB_MOD_DATATYPE_ENABLED;TERRALIB_MOD_GEOMETRY_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_MOD_GRAPH_ENABLED "Build Graph module?" ON "TERRALIB_MOD_DATAACCESS_ENABLED;TERRALIB_MOD_DATATYPE_ENABLED;TERRALIB_MOD_RASTER_ENABLED;TERRALIB_MOD_GEOMETRY_ENABLED;TERRALIB_MOD_MAPTOOLS_ENABLED;TERRALIB_MOD_MEMORY_ENABLED;TERRALIB_MOD_PLUGIN_ENABLED;TERRALIB_MOD_SYMBOLOGY_ENABLED;TERRALIB_MOD_SRS_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_MOD_STATISTICS_CORE_ENABLED "Build Statistics Core module?" ON "TERRALIB_MOD_RASTER_ENABLED;TERRALIB_MOD_GEOMETRY_ENABLED;TERRALIB_MOD_DATAACCESS_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_MOD_VP_CORE_ENABLED "Build Vector Processing Core module?" ON "TERRALIB_MOD_STATISTICS_CORE_ENABLED;TERRALIB_MOD_GEOMETRY_ENABLED;TERRALIB_MOD_DATAACCESS_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_MOD_RP_ENABLED "Build Raster Processing module?" ON "TERRALIB_MOD_RASTER_ENABLED;TERRALIB_MOD_GEOMETRY_ENABLED;TERRALIB_MOD_STATISTICS_CORE_ENABLED;TERRALIB_MOD_MEMORY_ENABLED;TERRALIB_MOD_SRS_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_MOD_STMEMORY_ENABLED "Build Spatio-Temporal Driver In-Memory module?" ON "TERRALIB_MOD_MEMORY_ENABLED;TERRALIB_MOD_RASTER_ENABLED;TERRALIB_MOD_GEOMETRY_ENABLED;TERRALIB_MOD_DATAACCESS_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_MOD_ST_ENABLED "Build Spatio-Temporal module?" ON "TERRALIB_MOD_STMEMORY_ENABLED;TERRALIB_MOD_RASTER_ENABLED;TERRALIB_MOD_GEOMETRY_ENABLED;TERRALIB_MOD_DATAACCESS_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_MOD_QT_WIDGETS_ENABLED "Build Qt Widgets?" ON "TERRALIB_QTPROPERTYBROWSER_ENABLED;TERRALIB_QWT_ENABLED;TERRALIB_QT_ENABLED;TERRALIB_MOD_MAPTOOLS_ENABLED;TERRALIB_MOD_DATAACCESS_ENABLED;TERRALIB_MOD_RP_ENABLED;TERRALIB_MOD_ST_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_MOD_QT_APF_ENABLED "Build Qt Application Framework?" ON "TERRALIB_QT_ENABLED;TERRALIB_MOD_QT_WIDGETS_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_MOD_WCS_ENABLED "Build the TerraLib Web Coverage Service?" OFF "TERRALIB_MOD_DATAACCESS_ENABLED;TERRALIB_MOD_DATATYPE_ENABLED;TERRALIB_MOD_PLUGIN_ENABLED;TERRALIB_MOD_GDAL_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_MOD_WFS_ENABLED "Build the TerraLib Web Feature Service?" ON "TERRALIB_MOD_DATAACCESS_ENABLED;TERRALIB_MOD_DATATYPE_ENABLED;TERRALIB_MOD_PLUGIN_ENABLED;TERRALIB_MOD_OGR_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_MOD_WMS_CORE_ENABLED "Build the TerraLib Web Map Service?" ON "TERRALIB_MOD_DATAACCESS_ENABLED;TERRALIB_MOD_GDAL_ENABLED;TERRALIB_MOD_MAPTOOLS_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_MOD_WMS_QT_ENABLED "Build the TerraLib Qt Web Map Service?" ON "TERRALIB_MOD_WMS_CORE_ENABLED;TERRALIB_MOD_QT_WIDGETS_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_MOD_STATISTICS_QT_ENABLED "Build Qt support for Statistics module?" ON "TERRALIB_QT_ENABLED;TERRALIB_MOD_STATISTICS_CORE_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_MOD_TERRALIB4_ENABLED "Build Terralib4 driver?" ON "WIN32;TERRALIB4_FOUND;TERRALIB_MOD_DATAACCESS_ENABLED;TERRALIB_MOD_DATATYPE_ENABLED;TERRALIB_MOD_GEOMETRY_ENABLED;TERRALIB_MOD_MEMORY_ENABLED;TERRALIB_MOD_PLUGIN_ENABLED;TERRALIB_MOD_RASTER_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_MOD_VP_QT_ENABLED "Build Vector Processing Qt module?" ON "TERRALIB_QT_ENABLED;TERRALIB_MOD_VP_CORE_ENABLED;TERRALIB_MOD_QT_WIDGETS_ENABLED" OFF)

if(QT_QCOLLECTIONGENERATOR_EXECUTABLE)
  CMAKE_DEPENDENT_OPTION(TERRALIB_QHELP_ENABLED  "Enable Qt-Help build?" ON "TERRALIB_QT_ENABLED;TERRALIB_MOD_QT_WIDGETS_ENABLED" OFF)
endif()

CMAKE_DEPENDENT_OPTION(TERRALIB_MOD_QT_PLUGINS_DATASOURCE_ADO_ENABLED "Build ADO Driver Qt plugin?" ON "TERRALIB_MOD_ADO_ENABLED;TERRALIB_MOD_QT_WIDGETS_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_MOD_QT_PLUGINS_DATASOURCE_GDAL_ENABLED "Build GDAL Driver Qt plugin?" ON "TERRALIB_MOD_GDAL_ENABLED;TERRALIB_MOD_QT_APF_ENABLED;TERRALIB_MOD_QT_WIDGETS_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_MOD_QT_PLUGINS_DATASOURCE_OGR_ENABLED "Build OGR Driver Qt plugin?" ON "TERRALIB_MOD_OGR_ENABLED;TERRALIB_MOD_QT_APF_ENABLED;TERRALIB_MOD_QT_WIDGETS_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_MOD_QT_PLUGINS_DATASOURCE_POSTGIS_ENABLED "Build PostGIS Driver Qt plugin?" ON "TERRALIB_MOD_POSTGIS_ENABLED;TERRALIB_MOD_QT_APF_ENABLED;TERRALIB_MOD_QT_WIDGETS_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_MOD_QT_PLUGINS_DATASOURCE_TERRALIB4_ENABLED "Build TerraLib4 Driver Qt plugin?" ON "TERRALIB_MOD_TERRALIB4_ENABLED;TERRALIB_MOD_QT_WIDGETS_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_MOD_QT_PLUGINS_DATASOURCE_WCS_ENABLED "Build WCS Driver Qt plugin?" OFF "TERRALIB_MOD_WCS_ENABLED;TERRALIB_MOD_QT_WIDGETS_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_MOD_QT_PLUGINS_DATASOURCE_WFS_ENABLED "Build WFS Driver Qt plugin?" ON "TERRALIB_MOD_WFS_ENABLED;TERRALIB_MOD_QT_WIDGETS_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_MOD_QT_PLUGINS_DATASOURCE_WMS_ENABLED "Build WMS Driver Qt plugin?" ON "TERRALIB_MOD_WMS_CORE_ENABLED;TERRALIB_MOD_WMS_QT_ENABLED;TERRALIB_MOD_QT_WIDGETS_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_MOD_QT_PLUGINS_VP_ENABLED "Build Vector Processing Driver Qt plugin?" ON "TERRALIB_MOD_VP_QT_ENABLED;TERRALIB_MOD_PLUGIN_ENABLED;TERRALIB_MOD_QT_APF_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_MOD_QT_PLUGINS_RP_ENABLED "Build Raster Processing Driver Qt plugin?" ON "TERRALIB_MOD_PLUGIN_ENABLED;TERRALIB_MOD_QT_APF_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_MOD_QT_PLUGINS_ST_ENABLED "Build Spatio-Temporal Driver Qt plugin?" OFF "TERRALIB_MOD_PLUGIN_ENABLED;TERRALIB_MOD_QT_WIDGETS_ENABLED;TERRALIB_MOD_QT_APF_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_TERRAVIEW_ENABLED "Build TerraView?" ON "TERRALIB_MOD_QT_APF_ENABLED" OFF)

#
# build options for the TerraLib examples
#

CMAKE_DEPENDENT_OPTION(TERRALIB_EXAMPLE_ADO_ENABLED "Build the ADO example?" ON "WIN32;TERRALIB_BUILD_EXAMPLES_ENABLED;TERRALIB_MOD_DATAACCESS_ENABLED;TERRALIB_MOD_PLUGIN_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_EXAMPLE_COLORBAR_ENABLED "Build the color bar example?" ON "TERRALIB_BUILD_EXAMPLES_ENABLED;TERRALIB_MOD_QT_WIDGETS_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_EXAMPLE_COMMON_ENABLED "Build the common module example?" ON "TERRALIB_BUILD_EXAMPLES_ENABLED;TERRALIB_MOD_SRS_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_EXAMPLE_CPPPLUGIN_ENABLED "Build the C++ plugins example" ON "TERRALIB_BUILD_EXAMPLES_ENABLED;TERRALIB_MOD_PLUGIN_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_EXAMPLE_DATAACCESS_ENABLED "Build the Data Access example?" ON "TERRALIB_BUILD_EXAMPLES_ENABLED;TERRALIB_MOD_DATAACCESS_ENABLED;TERRALIB_MOD_MEMORY_ENABLED;TERRALIB_MOD_PLUGIN_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_EXAMPLE_FACTORY_ENABLED "Build the factory example?" ON "TERRALIB_BUILD_EXAMPLES_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_EXAMPLE_GEOMETRY_ENABLED "Build the Geometry example?" ON "TERRALIB_BUILD_EXAMPLES_ENABLED;TERRALIB_MOD_GEOMETRY_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_EXAMPLE_GRAPH_ENABLED "Build the Graph example?" ON "TERRALIB_BUILD_EXAMPLES_ENABLED;TERRALIB_MOD_GRAPH_ENABLED;TERRALIB_MOD_PLUGIN_ENABLED;TERRALIB_MOD_QT_WIDGETS_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_EXAMPLE_HELP_ENABLED "Build the TerraLib Help example?" ON "TERRALIB_BUILD_EXAMPLES_ENABLED;TERRALIB_MOD_QT_WIDGETS_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_EXAMPLE_LAYEREXPLORER_ENABLED "Build the Layer Explorer example?" ON "TERRALIB_BUILD_EXAMPLES_ENABLED;TERRALIB_MOD_QT_WIDGETS_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_EXAMPLE_MAPTOOLS_ENABLED "Build the MapTools example?" ON "TERRALIB_BUILD_EXAMPLES_ENABLED;TERRALIB_MOD_MAPTOOLS_ENABLED;TERRALIB_MOD_QT_WIDGETS_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_EXAMPLE_PROGRESS_ENABLED "Build the Progress example?" ON "TERRALIB_BUILD_EXAMPLES_ENABLED;TERRALIB_MOD_QT_WIDGETS_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_EXAMPLE_QT_CANVAS_ENABLED "Build the Qt Canvas example?" ON "TERRALIB_BUILD_EXAMPLES_ENABLED;TERRALIB_MOD_QT_WIDGETS_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_EXAMPLE_QT_CHARTS_ENABLED "Build the Qt Charts example?" ON "TERRALIB_BUILD_EXAMPLES_ENABLED;TERRALIB_MOD_QT_WIDGETS_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_EXAMPLE_QT_DATASOURCE_ENABLED "Build the examples for the Qt Data Source?" ON "NOT WIN32;TERRALIB_BUILD_EXAMPLES_ENABLED;TERRALIB_MOD_OGR_ENABLED;TERRALIB_MOD_GDAL_ENABLED;TERRALIB_MOD_POSTGIS_ENABLED;TERRALIB_MOD_QT_PLUGINS_DATASOURCE_OGR_ENABLED;TERRALIB_MOD_QT_PLUGINS_DATASOURCE_GDAL_ENABLED;TERRALIB_MOD_QT_PLUGINS_DATASOURCE_POSTGIS_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_EXAMPLE_QT_QUERY_ENABLED "Build the Qt Query example?" ON "TERRALIB_BUILD_EXAMPLES_ENABLED;TERRALIB_MOD_DATAACCESS_ENABLED;TERRALIB_MOD_PLUGIN_ENABLED;TERRALIB_MOD_QT_WIDGETS_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_EXAMPLE_QT_RASTER_VISUAL_ENABLED "Build the Qt Raster Visual example?" ON "TERRALIB_BUILD_EXAMPLES_ENABLED;TERRALIB_MOD_RASTER_ENABLED;TERRALIB_MOD_QT_WIDGETS_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_EXAMPLE_QT_RP_ENABLED "Build the Qt Raster Processing example?" ON "TERRALIB_BUILD_EXAMPLES_ENABLED;TERRALIB_MOD_MAPTOOLS_ENABLED;TERRALIB_MOD_PLUGIN_ENABLED;TERRALIB_MOD_QT_WIDGETS_ENABLED;TERRALIB_MOD_RASTER_ENABLED;TERRALIB_MOD_SYMBOLOGY_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_EXAMPLE_QT_SE_ENABLED "Build the Qt Symbology Encoding example?" ON "TERRALIB_BUILD_EXAMPLES_ENABLED;TERRALIB_MOD_DATAACCESS_ENABLED;TERRALIB_MOD_SYMBOLOGY_ENABLED;TERRALIB_MOD_PLUGIN_ENABLED;TERRALIB_MOD_QT_WIDGETS_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_EXAMPLE_QT_SRS_ENABLED "Build the Qt SRS example?" ON "TERRALIB_BUILD_EXAMPLES_ENABLED;TERRALIB_MOD_QT_WIDGETS_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_EXAMPLE_QT_TOOLS_ENABLED "Build the Qt Tools example?" ON "TERRALIB_BUILD_EXAMPLES_ENABLED;TERRALIB_MOD_GEOMETRY_ENABLED;TERRALIB_MOD_MAPTOOLS_ENABLED;TERRALIB_MOD_PLUGIN_ENABLED;TERRALIB_MOD_QT_WIDGETS_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_EXAMPLE_QT_UTILS_ENABLED "Build the Qt Utils example?" ON "TERRALIB_BUILD_EXAMPLES_ENABLED;TERRALIB_MOD_QT_WIDGETS_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_EXAMPLE_RASTER_ENABLED "Build the Raster example?" ON "TERRALIB_BUILD_EXAMPLES_ENABLED;TERRALIB_MOD_DATAACCESS_ENABLED;TERRALIB_MOD_GDAL_ENABLED;TERRALIB_MOD_GEOMETRY_ENABLED;TERRALIB_MOD_MEMORY_ENABLED;TERRALIB_MOD_RASTER_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_EXAMPLE_RP_ENABLED "Build the Raster Processing example?" ON "TERRALIB_BUILD_EXAMPLES_ENABLED;TERRALIB_MOD_DATAACCESS_ENABLED;TERRALIB_MOD_DATATYPE_ENABLED;TERRALIB_MOD_GDAL_ENABLED;TERRALIB_MOD_GEOMETRY_ENABLED;TERRALIB_MOD_MEMORY_ENABLED;TERRALIB_MOD_RASTER_ENABLED;TERRALIB_MOD_RP_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_EXAMPLE_SAM_ENABLED "Build the SAM example?" ON "TERRALIB_BUILD_EXAMPLES_ENABLED;TERRALIB_MOD_DATATYPE_ENABLED;TERRALIB_MOD_GEOMETRY_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_EXAMPLE_SERIALIZATION_ENABLED "Build the Serialization example?" ON "TERRALIB_BUILD_EXAMPLES_ENABLED;TERRALIB_MOD_FILTER_ENABLED;TERRALIB_MOD_SYMBOLOGY_ENABLED;TERRALIB_MOD_XML_ENABLED;TERRALIB_MOD_XSD_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_EXAMPLE_SRS_ENABLED "Build the SRS example?" ON "TERRALIB_BUILD_EXAMPLES_ENABLED;TERRALIB_MOD_SRS_ENABLED;TERRALIB_MOD_GEOMETRY_ENABLED;TERRALIB_MOD_XERCES_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_EXAMPLE_ST_ENABLED "Build the Spatial Temporal example?" ON "TERRALIB_BUILD_EXAMPLES_ENABLED;TERRALIB_MOD_DATAACCESS_ENABLED;TERRALIB_MOD_DATATYPE_ENABLED;TERRALIB_MOD_GEOMETRY_ENABLED;TERRALIB_MOD_ST_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_EXAMPLE_VP_ENABLED "Build the Vector Processing example?" ON "TERRALIB_BUILD_EXAMPLES_ENABLED;TERRALIB_MOD_VP_CORE_ENABLED;TERRALIB_MOD_PLUGIN_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_EXAMPLE_XERCES_ENABLED "Build the Xerces example?" ON "TERRALIB_BUILD_EXAMPLES_ENABLED;TERRALIB_MOD_PLUGIN_ENABLED;TERRALIB_MOD_XML_ENABLED" OFF)


#
# build options for the TerraLib Unit Test
#

CMAKE_DEPENDENT_OPTION(TERRALIB_UNITTEST_COMMON_ENABLED "Build the unit test for the Common module?" ON "TERRALIB_CPPUNIT_ENABLED;TERRALIB_BUILD_UNITTEST_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_UNITTEST_DATAACCESS_ENABLED "Build the unit test for the Data Access module?" ON "TERRALIB_CPPUNIT_ENABLED;TERRALIB_BUILD_UNITTEST_ENABLED;TERRALIB_MOD_DATAACCESS_ENABLED;TERRALIB_MOD_GEOMETRY_ENABLED;TERRALIB_MOD_PLUGIN_ENABLED;TERRALIB_MOD_RASTER_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_UNITTEST_DATATYPE_ENABLED "Build the unit test for the Data Type module?" ON "TERRALIB_CPPUNIT_ENABLED;TERRALIB_BUILD_UNITTEST_ENABLED;TERRALIB_MOD_DATATYPE_ENABLED;TERRALIB_MOD_GEOMETRY_ENABLED;TERRALIB_MOD_RASTER_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_UNITTEST_GEOMETRY_ENABLED "Build the unit test for the Geometry module?" ON "TERRALIB_CPPUNIT_ENABLED;TERRALIB_BUILD_UNITTEST_ENABLED;TERRALIB_MOD_GEOMETRY_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_UNITTEST_MEMORY_ENABLED "Build the unit test for the Memory module?" ON "TERRALIB_CPPUNIT_ENABLED;TERRALIB_BUILD_UNITTEST_ENABLED;TERRALIB_MOD_MEMORY_ENABLED;TERRALIB_MOD_RASTER_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_UNITTEST_RASTER_ENABLED "Build the unit test for the Raster module?" ON "TERRALIB_CPPUNIT_ENABLED;TERRALIB_BUILD_UNITTEST_ENABLED;TERRALIB_MOD_GEOMETRY_ENABLED;TERRALIB_MOD_RASTER_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_UNITTEST_RP_BLENDER_ENABLED "Build the unit test for the RP Blender?" ON "TERRALIB_CPPUNIT_ENABLED;TERRALIB_BUILD_UNITTEST_ENABLED;TERRALIB_MOD_GEOMETRY_ENABLED;TERRALIB_MOD_PLUGIN_ENABLED;TERRALIB_MOD_RASTER_ENABLED;TERRALIB_MOD_RP_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_UNITTEST_RP_CLASSIFIER_ENABLED "Build the unit test for the RP Classifier?" ON "TERRALIB_CPPUNIT_ENABLED;TERRALIB_BUILD_UNITTEST_ENABLED;TERRALIB_MOD_GDAL_ENABLED;TERRALIB_MOD_RP_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_UNITTEST_RP_CONTRAST_ENABLED "Build the unit test for the RP Contrast?" ON "TERRALIB_CPPUNIT_ENABLED;TERRALIB_BUILD_UNITTEST_ENABLED;TERRALIB_MOD_PLUGIN_ENABLED;TERRALIB_MOD_RP_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_UNITTEST_RP_FILTER_ENABLED "Build the unit test for the RP Filter?" ON "TERRALIB_CPPUNIT_ENABLED;TERRALIB_BUILD_UNITTEST_ENABLED;TERRALIB_MOD_PLUGIN_ENABLED;TERRALIB_MOD_RP_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_UNITTEST_RP_FUNCTIONS_ENABLED "Build the unit test for the RP Functions?" ON "TERRALIB_CPPUNIT_ENABLED;TERRALIB_BUILD_UNITTEST_ENABLED;TERRALIB_MOD_PLUGIN_ENABLED;TERRALIB_MOD_RASTER_ENABLED;TERRALIB_MOD_RP_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_UNITTEST_RP_GEOMETRICREFINING_ENABLED "Build the unit test for the RP Geometric Refining?" ON "TERRALIB_CPPUNIT_ENABLED;TERRALIB_BUILD_UNITTEST_ENABLED;TERRALIB_MOD_GEOMETRY_ENABLED;TERRALIB_MOD_PLUGIN_ENABLED;TERRALIB_MOD_RASTER_ENABLED;TERRALIB_MOD_RP_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_UNITTEST_RP_IHSFUSION_ENABLED "Build the unit test for the RP IHS Fusion?" ON "TERRALIB_CPPUNIT_ENABLED;TERRALIB_BUILD_UNITTEST_ENABLED;TERRALIB_MOD_PLUGIN_ENABLED;TERRALIB_MOD_RASTER_ENABLED;TERRALIB_MOD_RP_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_UNITTEST_RP_MATRIX_ENABLED "Build the unit test for the RP Matrix?" ON "TERRALIB_CPPUNIT_ENABLED;TERRALIB_BUILD_UNITTEST_ENABLED;TERRALIB_MOD_PLUGIN_ENABLED;TERRALIB_MOD_RP_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_UNITTEST_RP_MIXTUREMODEL_ENABLED "Build the unit test for the RP Mixture model?" ON "TERRALIB_CPPUNIT_ENABLED;TERRALIB_BUILD_UNITTEST_ENABLED;TERRALIB_MOD_PLUGIN_ENABLED;TERRALIB_MOD_RASTER_ENABLED;TERRALIB_MOD_RP_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_UNITTEST_RP_MOSAIC_ENABLED "Build the unit test for the RP Mosaic?" ON "TERRALIB_CPPUNIT_ENABLED;TERRALIB_BUILD_UNITTEST_ENABLED;TERRALIB_MOD_PLUGIN_ENABLED;TERRALIB_MOD_RASTER_ENABLED;TERRALIB_MOD_RP_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_UNITTEST_RP_PCAFUSION_ENABLED "Build the unit test for the RP PCAFusion?" ON "TERRALIB_CPPUNIT_ENABLED;TERRALIB_BUILD_UNITTEST_ENABLED;TERRALIB_MOD_PLUGIN_ENABLED;TERRALIB_MOD_RASTER_ENABLED;TERRALIB_MOD_RP_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_UNITTEST_RP_REGISTER_ENABLED "Build the unit test for the RP Register?" ON "TERRALIB_CPPUNIT_ENABLED;TERRALIB_BUILD_UNITTEST_ENABLED;TERRALIB_MOD_PLUGIN_ENABLED;TERRALIB_MOD_RASTER_ENABLED;TERRALIB_MOD_RP_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_UNITTEST_RP_SEGMENTER_ENABLED "Build the unit test for the RP Segmenter?" ON "TERRALIB_CPPUNIT_ENABLED;TERRALIB_BUILD_UNITTEST_ENABLED;TERRALIB_MOD_PLUGIN_ENABLED;TERRALIB_MOD_RASTER_ENABLED;TERRALIB_MOD_RP_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_UNITTEST_RP_SKELETON_ENABLED "Build the unit test for the RP Skeleton?" ON "TERRALIB_CPPUNIT_ENABLED;TERRALIB_BUILD_UNITTEST_ENABLED;TERRALIB_MOD_PLUGIN_ENABLED;TERRALIB_MOD_RASTER_ENABLED;TERRALIB_MOD_RP_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_UNITTEST_RP_TIEPOINTSLOCATOR_ENABLED "Build the unit test for the RP Tie Points Locator?" ON "TERRALIB_CPPUNIT_ENABLED;TERRALIB_BUILD_UNITTEST_ENABLED;TERRALIB_MOD_PLUGIN_ENABLED;TERRALIB_MOD_RASTER_ENABLED;TERRALIB_MOD_RP_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_UNITTEST_SAM_ENABLED "Build the unit test for the SAM module?" ON "TERRALIB_CPPUNIT_ENABLED;TERRALIB_BUILD_UNITTEST_ENABLED;TERRALIB_MOD_GEOMETRY_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_UNITTEST_SRS_ENABLED "Build the unit test for the SRS module?" ON "TERRALIB_CPPUNIT_ENABLED;TERRALIB_BUILD_UNITTEST_ENABLED;TERRALIB_MOD_SRS_ENABLED" OFF)


#
# process TERRALIB configuration files
#

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

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

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

configure_file(${TERRALIB_ABSOLUTE_ROOT_DIR}/src/terralib/Config.h.in
               ${CMAKE_BINARY_DIR}/terralib_config.h @ONLY)

configure_file(${TERRALIB_ABSOLUTE_ROOT_DIR}/src/terralib/Defines.h.in
               ${CMAKE_BINARY_DIR}/terralib_defines.h @ONLY)

configure_file(${TERRALIB_ABSOLUTE_ROOT_DIR}/src/terralib/Version.h.in
               ${CMAKE_BINARY_DIR}/terralib_version.h @ONLY)

configure_file(${TERRALIB_ABSOLUTE_ROOT_DIR}/examples/Config.h.in
               ${CMAKE_BINARY_DIR}/terralib_examples_config.h @ONLY)

configure_file(${TERRALIB_ABSOLUTE_ROOT_DIR}/unittest/Config.h.in
               ${CMAKE_BINARY_DIR}/terralib_unittest_config.h @ONLY)

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

#
# build modules
#

if(TERRALIB_DOXYGEN_ENABLED)
  add_subdirectory(terralib_doxygen)
endif()

if(TERRALIB_QHELP_ENABLED)
  add_subdirectory(terralib_qhelp)
endif()

if(Qt5LinguistTools_FOUND)
  add_subdirectory(terralib_qtranslations)
endif()

if(TERRALIB_MOD_ADO_ENABLED)
  add_subdirectory(terralib_mod_ado)
endif()

if(TERRALIB_MOD_TERRALIB4_ENABLED)
  add_subdirectory(terralib_mod_terralib4)
endif()

# Turn on multi process compilation
if(MSVC)
  add_definitions(/MP)
endif()

if(TERRALIB_MOD_ANNOTATIONTEXT_ENABLED)
  add_subdirectory(terralib_mod_annotationtext)
endif()

if(TERRALIB_MOD_CLASSIFICATION_ENABLED)
  add_subdirectory(terralib_mod_classification)
endif()

if(TERRALIB_MOD_COLOR_ENABLED)
  add_subdirectory(terralib_mod_color)
endif()

add_subdirectory(terralib_mod_common)

if(TERRALIB_MOD_DATAACCESS_ENABLED)
  add_subdirectory(terralib_mod_dataaccess)
endif()

if(TERRALIB_MOD_DATATYPE_ENABLED)
  add_subdirectory(terralib_mod_datatype)
endif()

if(TERRALIB_MOD_FILTER_ENABLED)
  add_subdirectory(terralib_mod_filter)
endif()

if(TERRALIB_MOD_GDAL_ENABLED)
  add_subdirectory(terralib_mod_gdal)
endif()

if(TERRALIB_MOD_GEOMETRY_ENABLED)
  add_subdirectory(terralib_mod_geometry)
endif()

if(TERRALIB_MOD_GML_ENABLED)
  add_subdirectory(terralib_mod_gml)
endif()

if(TERRALIB_MOD_GRAPH_ENABLED)
  add_subdirectory(terralib_mod_graph)
endif()

if(TERRALIB_MOD_MAPTOOLS_ENABLED)
  add_subdirectory(terralib_mod_maptools)
endif()

if(TERRALIB_MOD_METADATA_ENABLED)
  add_subdirectory(terralib_mod_metadata)
endif()

if(TERRALIB_MOD_MEMORY_ENABLED)
  add_subdirectory(terralib_mod_memory)
endif()

if(TERRALIB_MOD_OGR_ENABLED)
  add_subdirectory(terralib_mod_ogr)
endif()

if(TERRALIB_MOD_PLUGIN_ENABLED)
  add_subdirectory(terralib_mod_plugin)
endif()

if(TERRALIB_MOD_POSTGIS_ENABLED)
  add_subdirectory(terralib_mod_postgis)
endif()

if(TERRALIB_MOD_QT_APF_ENABLED)
  add_subdirectory(terralib_mod_qt_apf)
endif()

if(TERRALIB_MOD_QT_PLUGINS_DATASOURCE_ADO_ENABLED)
  add_subdirectory(terralib_mod_qt_plugins_datasource_ado)
endif()

if(TERRALIB_MOD_QT_PLUGINS_DATASOURCE_GDAL_ENABLED)
  add_subdirectory(terralib_mod_qt_plugins_datasource_gdal)
endif()

if(TERRALIB_MOD_QT_PLUGINS_DATASOURCE_TERRALIB4_ENABLED)
  add_subdirectory(terralib_mod_qt_plugins_datasource_terralib4)
endif()

if(TERRALIB_MOD_QT_PLUGINS_DATASOURCE_OGR_ENABLED)
  add_subdirectory(terralib_mod_qt_plugins_datasource_ogr)
endif()

if(TERRALIB_MOD_QT_PLUGINS_DATASOURCE_POSTGIS_ENABLED)
  add_subdirectory(terralib_mod_qt_plugins_datasource_pgis)
endif()

if(TERRALIB_MOD_QT_PLUGINS_DATASOURCE_WCS_ENABLED)
  add_subdirectory(terralib_mod_qt_plugins_datasource_wcs)
endif()

if(TERRALIB_MOD_QT_PLUGINS_DATASOURCE_WFS_ENABLED)
  add_subdirectory(terralib_mod_qt_plugins_datasource_wfs)
endif()

if(TERRALIB_MOD_QT_PLUGINS_DATASOURCE_WMS_ENABLED)
  add_subdirectory(terralib_mod_qt_plugins_datasource_wms)
endif()

if(TERRALIB_MOD_QT_PLUGINS_VP_ENABLED)
  add_subdirectory(terralib_mod_qt_plugins_vp)
endif()

if(TERRALIB_MOD_QT_PLUGINS_RP_ENABLED)
  add_subdirectory(terralib_mod_qt_plugins_rp)
endif()

if(TERRALIB_MOD_QT_PLUGINS_ST_ENABLED)
  add_subdirectory(terralib_mod_qt_plugins_st)
endif()

if(TERRALIB_MOD_QT_WIDGETS_ENABLED)
  add_subdirectory(terralib_mod_qt_widgets)
endif()

if(TERRALIB_MOD_RASTER_ENABLED)
  add_subdirectory(terralib_mod_raster)
endif()

if(TERRALIB_MOD_RP_ENABLED)
  add_subdirectory(terralib_mod_rp)
endif()

if(TERRALIB_MOD_SAM_ENABLED)
  add_subdirectory(terralib_mod_sam)
endif()

if(TERRALIB_MOD_SRS_ENABLED)
  add_subdirectory(terralib_mod_srs)
endif()

if(TERRALIB_MOD_ST_ENABLED)
  add_subdirectory(terralib_mod_st)
endif()

if(TERRALIB_MOD_WCS_ENABLED)
  add_subdirectory(terralib_mod_wcs)
endif()

if(TERRALIB_MOD_WFS_ENABLED)
  add_subdirectory(terralib_mod_wfs)
endif()

if(TERRALIB_MOD_WMS_CORE_ENABLED)
  add_subdirectory(terralib_mod_wms_core)
endif()

if(TERRALIB_MOD_WMS_QT_ENABLED)
  add_subdirectory(terralib_mod_wms_qt)
endif()

if(TERRALIB_MOD_STATISTICS_CORE_ENABLED)
  add_subdirectory(terralib_mod_statistics_core)
endif()

if(TERRALIB_MOD_STMEMORY_ENABLED)
  add_subdirectory(terralib_mod_stmemory)
endif()

if(TERRALIB_MOD_STATISTICS_QT_ENABLED)
  add_subdirectory(terralib_mod_statistics_qt)
endif()

if(TERRALIB_MOD_SYMBOLOGY_ENABLED)
  add_subdirectory(terralib_mod_symbology)
endif()

if(TERRALIB_MOD_VP_CORE_ENABLED)
  add_subdirectory(terralib_mod_vp_core)
endif()

if(TERRALIB_MOD_VP_QT_ENABLED)
  add_subdirectory(terralib_mod_vp_qt)
endif()

if(TERRALIB_MOD_XERCES_ENABLED)
  add_subdirectory(terralib_mod_xerces)
endif()

if(TERRALIB_MOD_XLINK_ENABLED)
  add_subdirectory(terralib_mod_xlink)
endif()

if(TERRALIB_MOD_XML_ENABLED)
  add_subdirectory(terralib_mod_xml)
endif()

if(TERRALIB_MOD_XSD_ENABLED)
  add_subdirectory(terralib_mod_xsd)
endif()

if(TERRALIB_TERRAVIEW_ENABLED)
  add_subdirectory(terraview)
endif()


#
# build examples
#

if(TERRALIB_EXAMPLE_ADO_ENABLED)
  add_subdirectory(terralib_example_ado)
endif()
  
if(TERRALIB_EXAMPLE_COLORBAR_ENABLED)
  add_subdirectory(terralib_example_colorbar)
endif()

if(TERRALIB_EXAMPLE_COMMON_ENABLED)
  add_subdirectory(terralib_example_common)
endif()
  
if(TERRALIB_EXAMPLE_CPPPLUGIN_ENABLED)
  add_subdirectory(terralib_example_cppplugin)
endif()

if(TERRALIB_EXAMPLE_DATAACCESS_ENABLED)
  add_subdirectory(terralib_example_dataaccess)
endif()

if(TERRALIB_EXAMPLE_FACTORY_ENABLED)
  add_subdirectory(terralib_example_factory)
endif()

if(TERRALIB_EXAMPLE_GEOMETRY_ENABLED)
  add_subdirectory(terralib_example_geometry)
endif()

if(TERRALIB_EXAMPLE_GRAPH_ENABLED)
  add_subdirectory(terralib_example_graph)
endif()

if(TERRALIB_EXAMPLE_HELP_ENABLED)
  add_subdirectory(terralib_example_help)
endif()

if(TERRALIB_EXAMPLE_LAYEREXPLORER_ENABLED)
  add_subdirectory(terralib_example_layerexplorer)
endif()

if(TERRALIB_EXAMPLE_MAPTOOLS_ENABLED)
  add_subdirectory(terralib_example_maptools)
endif()

if(TERRALIB_EXAMPLE_PROGRESS_ENABLED)
  add_subdirectory(terralib_example_progress)
endif()

if(TERRALIB_EXAMPLE_QT_CANVAS_ENABLED)
  add_subdirectory(terralib_example_qt_canvas)
endif()

if(TERRALIB_EXAMPLE_QT_CHARTS_ENABLED)
  add_subdirectory(terralib_example_qt_charts)
endif()

if(TERRALIB_EXAMPLE_QT_DATASOURCE_ENABLED)
  add_subdirectory(terralib_example_qt_datasource)
endif()

if(TERRALIB_EXAMPLE_QT_QUERY_ENABLED)
  add_subdirectory(terralib_example_qt_query)
endif()

if(TERRALIB_EXAMPLE_QT_RASTER_VISUAL_ENABLED)
  add_subdirectory(terralib_example_qt_raster_visual)
endif()

if(TERRALIB_EXAMPLE_QT_RP_ENABLED)
  add_subdirectory(terralib_example_qt_rp)
endif()

if(TERRALIB_EXAMPLE_QT_SE_ENABLED)
  add_subdirectory(terralib_example_qt_se)
endif()

if(TERRALIB_EXAMPLE_QT_SRS_ENABLED)
  add_subdirectory(terralib_example_qt_srs)
endif()

if(TERRALIB_EXAMPLE_QT_TOOLS_ENABLED)
  add_subdirectory(terralib_example_qt_tools)
endif()

if(TERRALIB_EXAMPLE_QT_UTILS_ENABLED)
  add_subdirectory(terralib_example_qt_utils)
endif()

if(TERRALIB_EXAMPLE_RASTER_ENABLED)
  add_subdirectory(terralib_example_raster)
endif()

if(TERRALIB_EXAMPLE_RP_ENABLED)
  add_subdirectory(terralib_example_rp)
endif()

if(TERRALIB_EXAMPLE_SAM_ENABLED)
  add_subdirectory(terralib_example_sam)
endif()

if(TERRALIB_EXAMPLE_SERIALIZATION_ENABLED)
  add_subdirectory(terralib_example_serialization)
endif()

if(TERRALIB_EXAMPLE_SRS_ENABLED)
  add_subdirectory(terralib_example_srs)
endif()

if(TERRALIB_EXAMPLE_ST_ENABLED)
  add_subdirectory(terralib_example_st)
endif()

if(TERRALIB_EXAMPLE_VP_ENABLED)
  add_subdirectory(terralib_example_vp)
endif()

if(TERRALIB_EXAMPLE_XERCES_ENABLED)
  add_subdirectory(terralib_example_xerces)
endif()


#
# build unit test
#

if(TERRALIB_UNITTEST_COMMON_ENABLED)
  add_subdirectory(terralib_unittest_common)
endif()

if(TERRALIB_UNITTEST_DATAACCESS_ENABLED)
  add_subdirectory(terralib_unittest_dataaccess)
endif()

if(TERRALIB_UNITTEST_DATATYPE_ENABLED)
  add_subdirectory(terralib_unittest_datatype)
endif()

if(TERRALIB_UNITTEST_GEOMETRY_ENABLED)
  add_subdirectory(terralib_unittest_geometry)
endif()

if(TERRALIB_UNITTEST_MEMORY_ENABLED)
  add_subdirectory(terralib_unittest_memory)
endif()

if(TERRALIB_UNITTEST_RASTER_ENABLED)
  add_subdirectory(terralib_unittest_raster)
endif()

if(TERRALIB_UNITTEST_RP_BLENDER_ENABLED)
  add_subdirectory(terralib_unittest_rp_blender)
endif()

if(TERRALIB_UNITTEST_RP_CLASSIFIER_ENABLED)
  add_subdirectory(terralib_unittest_rp_classifier)
endif()

if(TERRALIB_UNITTEST_RP_CONTRAST_ENABLED)
  add_subdirectory(terralib_unittest_rp_contrast)
endif()

if(TERRALIB_UNITTEST_RP_FILTER_ENABLED)
  add_subdirectory(terralib_unittest_rp_filter)
endif()

if(TERRALIB_UNITTEST_RP_FUNCTIONS_ENABLED)
  add_subdirectory(terralib_unittest_rp_functions)
endif()

if(TERRALIB_UNITTEST_RP_GEOMETRICREFINING_ENABLED)
  add_subdirectory(terralib_unittest_rp_geometricrefining)
endif()

if(TERRALIB_UNITTEST_RP_IHSFUSION_ENABLED)
  add_subdirectory(terralib_unittest_rp_ihsfusion)
endif()

if(TERRALIB_UNITTEST_RP_MATRIX_ENABLED)
  add_subdirectory(terralib_unittest_rp_matrix)
endif()

if(TERRALIB_UNITTEST_RP_MIXTUREMODEL_ENABLED)
  add_subdirectory(terralib_unittest_rp_mixturemodel)
endif()

if(TERRALIB_UNITTEST_RP_MOSAIC_ENABLED)
  add_subdirectory(terralib_unittest_rp_mosaic)
endif()

if(TERRALIB_UNITTEST_RP_PCAFUSION_ENABLED)
  add_subdirectory(terralib_unittest_rp_pcafusion)
endif()

if(TERRALIB_UNITTEST_RP_REGISTER_ENABLED)
  add_subdirectory(terralib_unittest_rp_register)
endif()

if(TERRALIB_UNITTEST_RP_SEGMENTER_ENABLED)
  add_subdirectory(terralib_unittest_rp_segmenter)
endif()

if(TERRALIB_UNITTEST_RP_SKELETON_ENABLED)
  add_subdirectory(terralib_unittest_rp_skeleton)
endif()

if(TERRALIB_UNITTEST_RP_TIEPOINTSLOCATOR_ENABLED)
  add_subdirectory(terralib_unittest_rp_tiepointslocator)
endif()

if(TERRALIB_UNITTEST_SAM_ENABLED)
  add_subdirectory(terralib_unittest_sam)
endif()

if(TERRALIB_UNITTEST_SRS_ENABLED)
  add_subdirectory(terralib_unittest_srs)
endif()


#
# install and targets export
#

file(GLOB TERRALIB_HDR_FILES ${TERRALIB_ABSOLUTE_ROOT_DIR}/src/terralib/*.h)

install(FILES ${CMAKE_BINARY_DIR}/terralib_config.h
              ${CMAKE_BINARY_DIR}/terralib_defines.h
              ${CMAKE_BINARY_DIR}/terralib_version.h
              ${TERRALIB_HDR_FILES}
        DESTINATION ${TERRALIB_DESTINATION_HEADERS}/terralib COMPONENT devel)

install(FILES ${TERRALIB_ABSOLUTE_ROOT_DIR}/src/terralib.h
        DESTINATION ${TERRALIB_DESTINATION_HEADERS} COMPONENT devel)

if(TERRALIB_BUILD_EXAMPLES_ENABLED)
  install(FILES ${TERRALIB_ABSOLUTE_ROOT_DIR}/examples/Config.h.in
                ${TERRALIB_ABSOLUTE_ROOT_DIR}/examples/Config.h
          DESTINATION ${TERRALIB_DESTINATION_EXAMPLES} COMPONENT devel)
endif()

install(FILES ${terralib_BINARY_DIR}/pkg/terralib-config.cmake
              ${terralib_BINARY_DIR}/terralib-config-version.cmake
        DESTINATION ${TERRALIB_DESTINATION_LIBRARY}/cmake/terralib-${TERRALIB_PKG_VERSION} COMPONENT devel)

install(EXPORT terralib-targets
        DESTINATION ${TERRALIB_DESTINATION_LIBRARY}/cmake/terralib-${TERRALIB_PKG_VERSION}
        FILE terralib-exports.cmake
        COMPONENT devel)

install(DIRECTORY ${TERRALIB_ABSOLUTE_ROOT_DIR}/share/terralib/config
        DESTINATION ${TERRALIB_DESTINATION_SHARE}/terralib COMPONENT runtime)

install(DIRECTORY ${TERRALIB_ABSOLUTE_ROOT_DIR}/share/terralib/icons
        DESTINATION ${TERRALIB_DESTINATION_SHARE}/terralib COMPONENT runtime)

#install(DIRECTORY ${TERRALIB_ABSOLUTE_ROOT_DIR}/share/terralib/images
#        DESTINATION ${TERRALIB_DESTINATION_SHARE}/terralib COMPONENT runtime)

install ( # -- images folder
  DIRECTORY ${TERRALIB_ABSOLUTE_ROOT_DIR}/share/terralib/images
  DESTINATION ${TERRALIB_DESTINATION_SHARE}/terralib 
  COMPONENT runtime
  PATTERN "*icns*" EXCLUDE
)

if(WIN32)
  install ( # Application icon on windows system
    FILES ${TERRALIB_ABSOLUTE_ROOT_DIR}/resources/images/ico/terralib-globe.ico
    DESTINATION ${TERRALIB_DESTINATION_SHARE}/terralib/images/ico 
    COMPONENT runtime
  )
endif()

install(DIRECTORY ${TERRALIB_ABSOLUTE_ROOT_DIR}/share/terralib/json
        DESTINATION ${TERRALIB_DESTINATION_SHARE}/terralib COMPONENT runtime)

install(DIRECTORY ${TERRALIB_ABSOLUTE_ROOT_DIR}/share/terralib/schemas
        DESTINATION ${TERRALIB_DESTINATION_SHARE}/terralib COMPONENT runtime)

#
# Track dependencies
#
if(TERRALIB_TRACK_3RDPARTY_DEPENDENCIES)
  #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 "${TERRALIB_ABSOLUTE_ROOT_DIR};/")

configure_file(${terralib_SOURCE_DIR}/terralib-cpack-options.cmake.in
               ${terralib_BINARY_DIR}/terralibCPackOptions.cmake @ONLY)

set(CPACK_PROJECT_CONFIG_FILE ${terralib_BINARY_DIR}/terralibCPackOptions.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 "TerraLib ..."
                          EXPANDED)

cpack_add_component_group(devel_group
                          DISPLAY_NAME "Development Tools"
                          DESCRIPTION "Development Tools: header files, libraries and cmake stuffs"
                          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)

