#
#  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.12)

project(terralib)

#
# main variables for the build script
#

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

set(TERRALIB_MODULES "")

# 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
get_filename_component(TERRALIB_ABSOLUTE_ROOT_DIR "../../" ABSOLUTE)

# 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_BUILD_AS_DEV)
  set(TERRALIB_BUILD_AS_DEV 0 CACHE BOOL "Prepare the TerraLib build for Developers")
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(UNIX AND TERRALIB_BUILD_AS_BUNDLE AND NOT DEFINED TERRALIB_BASE_DESTINATION_DIR)
  set(TERRALIB_BASE_DESTINATION_DIR ${CMAKE_INSTALL_PREFIX}/)
else(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_ITEST_ENABLED)
  set(TERRALIB_BUILD_ITEST_ENABLED OFF CACHE BOOL "If on, shows the list of integration 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()

if(NOT DEFINED TERRALIB_LOGGER_ENABLED)
  set(TERRALIB_LOGGER_ENABLED 1 CACHE BOOL "Enable logger in TerraLib?")
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)
add_definitions(-DBOOST_FILESYSTEM_VERSION=3)
add_definitions(-DBOOST_UBLAS_TYPE_CHECK=0)
add_definitions(-DBOOST_LOG_DYN_LINK)

if(WIN32)
  add_definitions(-D_CRT_SECURE_NO_WARNINGS)

  if(MINGW)
    add_definitions(-DTE_MINGW -D_WIN32_WINNT=0x601 -fpermissive)
  endif()
elseif(APPLE)
  add_definitions(-ftemplate-depth-1024)
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()

# 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 CMP0026 OLD)
  cmake_policy(SET CMP0042 NEW)
  cmake_policy(SET CMP0043 NEW)
endif()

if(${CMAKE_VERSION} VERSION_GREATER "3.1.2")
  cmake_policy(SET CMP0053 OLD)
endif()


include_directories(${CMAKE_BINARY_DIR})

include(CTest)

#
# 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(MSVC)
  set(CMAKE_DEBUG_POSTFIX "d")
endif()

if(APPLE AND TERRALIB_BUILD_AS_BUNDLE)
  set(CMAKE_INSTALL_NAME_DIR "@executable_path/../lib")
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.53.0 REQUIRED system date_time chrono timer filesystem thread log log_setup locale regex 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 COMPONENTS ado QUIET)

endif()

find_package(GDAL)

find_package(GEOS)

find_package(Gettext)

find_package(Lua)

find_package(R)

find_package(PythonLibs 2.7)

find_package(LibPQ)

find_package(SWIG)

find_package(Java COMPONENTS Development)

find_package(JNI)

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)
  find_package(Qscintilla)
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)

find_package(CURL)

find_package(GTest)

find_package(GMock)

#
# global includes
#
include_directories(${Boost_INCLUDE_DIR})


#
# some variables needed in config file
#

if(Boost_FOUND)
  set(TERRALIB_BOOST_ENABLED ON)
  include_directories(${Boost_INCLUDE_DIR})
endif()

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

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

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

if(LUA_FOUND)
  set(TERRALIB_LUA_ENABLED ON)
endif()

if(PYTHONLIBS_FOUND)
  set(TERRALIB_PYTHON_ENABLED ON)
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()

if(SWIG_FOUND)
  set(TERRALIB_SWIG_ENABLED ON)
endif()

if(JAVA_FOUND)
  set(TERRALIB_JAVA_ENABLED ON)
endif()

if(JNI_FOUND)
  set(TERRALIB_JNI_ENABLED ON)
endif()

if(CURL_FOUND)
  set(TERRALIB_CURL_ENABLED ON)
endif()

if (terralib4_FOUND)
  set (TERRALIB_TERRALIB4_ENABLED ON)
endif()

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

CMAKE_DEPENDENT_OPTION(TERRALIB_LOGGER_TRACE_ENABLED "" OFF "TERRALIB_LOGGER_ENABLED" OFF)
CMAKE_DEPENDENT_OPTION(TERRALIB_LOGGER_DEBUG_ENABLED "" OFF "TERRALIB_LOGGER_ENABLED" OFF)
CMAKE_DEPENDENT_OPTION(TERRALIB_LOGGER_INFO_ENABLED "" ON "TERRALIB_LOGGER_ENABLED" OFF)
CMAKE_DEPENDENT_OPTION(TERRALIB_LOGGER_WARN_ENABLED "" ON "TERRALIB_LOGGER_ENABLED" OFF)
CMAKE_DEPENDENT_OPTION(TERRALIB_LOGGER_ERROR_ENABLED "" ON "TERRALIB_LOGGER_ENABLED" OFF)
CMAKE_DEPENDENT_OPTION(TERRALIB_LOGGER_FATAL_ENABLED "" ON "TERRALIB_LOGGER_ENABLED" OFF)

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

option(TERRALIB_MOD_CORE_ENABLED "Build TerraLib Core Runtime Library?" ON)

option(TERRALIB_MOD_VM_ENABLED "Build TerraLib Virtual Machine Library?" OFF)

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_WS_CORE_ENABLED "Build WS Core module?" ON)

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

option(TERRALIB_MOD_XLINK_ENABLED "Build XLink 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_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_CEDITOR_ENABLED "Build CEditor support?" OFF "Qt5_FOUND;QSCINTILLA_FOUND" 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" 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" 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" 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" 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_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_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_SA_CORE_ENABLED "Build Spatial Analysis Core module?" ON "TERRALIB_MOD_GRAPH_ENABLED;TERRALIB_MOD_GEOMETRY_ENABLED;TERRALIB_MOD_DATAACCESS_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_QTRANSLATION_ENABLED "Enable translation for Qt Widgets?" ON "TERRALIB_MOD_QT_WIDGETS_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_WS_OGC_WCS_CLIENT_ENABLED "Build OGC WCS Client Support?" ON "TERRALIB_MOD_XML_ENABLED;TERRALIB_MOD_WS_CORE_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_MOD_WS_OGC_WCS_DATAACCESS_ENABLED "Build OGC WCS Data Access Driver?" ON "TERRALIB_MOD_WS_OGC_WCS_CLIENT_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_MOD_WS_OGC_WCS_QT_ENABLED "Build Qt Components for OGC WCS?" ON "TERRALIB_MOD_WS_OGC_WCS_DATAACCESS_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_MOD_WS_OGC_WCS_QT_PLUGIN_ENABLED "Build OGC WCS Plugin for TerraLib Qt Applications?" ON "TERRALIB_MOD_WS_OGC_WCS_QT_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_MOD_WS_OGC_WMS_CLIENT_ENABLED "Build OGC WMS Client Support?" ON "TERRALIB_MOD_XML_ENABLED;TERRALIB_MOD_WS_CORE_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_MOD_WS_OGC_WMS_DATAACCESS_ENABLED "Build OGC WMS Data Access Driver?" ON "TERRALIB_MOD_WS_OGC_WMS_CLIENT_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_MOD_WS_OGC_WMS_QT_ENABLED "Build Qt Components for OGC WMS?" ON "TERRALIB_MOD_WS_OGC_WMS_DATAACCESS_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_MOD_WS_OGC_WMS_QT_PLUGIN_ENABLED "Build OGC WMS Plugin for TerraLib Qt Applications?" ON "TERRALIB_MOD_WS_OGC_WMS_QT_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_OGR_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;TERRALIB_TERRALIB4_ENABLED;TERRALIB_MOD_DATAACCESS_ENABLED;TERRALIB_MOD_DATATYPE_ENABLED;TERRALIB_MOD_GEOMETRY_ENABLED;TERRALIB_MOD_MEMORY_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)

CMAKE_DEPENDENT_OPTION(TERRALIB_MOD_SA_QT_ENABLED "Build Spatial Analysis Qt module?" ON "TERRALIB_QT_ENABLED;TERRALIB_MOD_SA_CORE_ENABLED;TERRALIB_MOD_QT_WIDGETS_ENABLED" OFF)

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_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_VP_ENABLED "Build Vector Processing Driver Qt plugin?" ON "TERRALIB_MOD_VP_QT_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_QT_APF_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_MOD_QT_PLUGINS_SA_ENABLED "Build Spatial Analysis Driver Qt plugin?" ON "TERRALIB_MOD_SA_QT_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_QT_WIDGETS_ENABLED;TERRALIB_MOD_QT_APF_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_MOD_QT_PLUGINS_MOBILE_ENABLED "Build Mobile Qt plugin?" OFF "TERRALIB_MOD_QT_APF_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_MOD_QT_PLUGINS_WTSS_ENABLED "Build WTSS plugin?" ON "TERRALIB_MOD_QT_APF_ENABLED;" OFF)

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

CMAKE_DEPENDENT_OPTION(TERRALIB_MOD_BINDING_JAVA_ENABLED "Build TerraLib bindings?" ON "TERRALIB_MOD_QT_WIDGETS_ENABLED;TERRALIB_SWIG_ENABLED;TERRALIB_JAVA_ENABLED;TERRALIB_JNI_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_MOD_BINDING_LUA_ENABLED "Build TerraLib bindings?" ON "TERRALIB_SWIG_ENABLED;TERRALIB_LUA_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_MOD_BINDING_PYTHON_ENABLED "Build TerraLib bindings?" ON "TERRALIB_SWIG_ENABLED;TERRALIB_PYTHON_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_MOD_CELLSPACE_ENABLED "Build Cellular Spaces module?" ON "TERRALIB_MOD_GEOMETRY_ENABLED;TERRALIB_MOD_DATAACCESS_ENABLED;TERRALIB_MOD_MAPTOOLS_ENABLED;TERRALIB_MOD_MEMORY_ENABLED;TERRALIB_MOD_SRS_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_MOD_QT_PLUGINS_CELLSPACE_ENABLED "Build Cellular Spaces Qt Plugin?" ON "TERRALIB_MOD_CELLSPACE_ENABLED;TERRALIB_MOD_QT_APF_ENABLED;TERRALIB_MOD_SRS_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_MOD_ATTRIBUTEFILL_CORE_ENABLED "Build Attribute Fill Core module?" ON "TERRALIB_MOD_STATISTICS_CORE_ENABLED;TERRALIB_MOD_GEOMETRY_ENABLED;TERRALIB_MOD_DATAACCESS_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_MOD_ATTRIBUTEFILL_QT_ENABLED "Build Attribute Fill Qt module?" ON "TERRALIB_QT_ENABLED;TERRALIB_MOD_ATTRIBUTEFILL_CORE_ENABLED;TERRALIB_MOD_QT_WIDGETS_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_MOD_QT_PLUGINS_ATTRIBUTEFILL_ENABLED "Build Attribute Fill Driver Qt plugin?" ON "TERRALIB_MOD_ATTRIBUTEFILL_QT_ENABLED;TERRALIB_MOD_QT_APF_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_MOD_ADDRESSGEOCODING_CORE_ENABLED "Build Address Geocoding Core module?" OFF "TERRALIB_MOD_GEOMETRY_ENABLED;TERRALIB_MOD_DATAACCESS_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_MOD_ADDRESSGEOCODING_QT_ENABLED "Build Address Geocoding Qt module?" OFF "TERRALIB_QT_ENABLED;TERRALIB_MOD_ADDRESSGEOCODING_CORE_ENABLED;TERRALIB_MOD_QT_WIDGETS_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_MOD_QT_PLUGINS_ADDRESSGEOCODING_ENABLED "Build Address Geocoding Driver Qt plugin?" OFF "TERRALIB_MOD_ADDRESSGEOCODING_QT_ENABLED;TERRALIB_MOD_QT_APF_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_MOD_EDIT_CORE_ENABLED "Build Edit module?" ON "TERRALIB_MOD_DATAACCESS_ENABLED;TERRALIB_MOD_GEOMETRY_ENABLED;TERRALIB_MOD_MAPTOOLS_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_MOD_EDIT_QT_ENABLED "Build Edit Qt module?" ON "TERRALIB_MOD_EDIT_CORE_ENABLED;TERRALIB_MOD_QT_WIDGETS_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_MOD_QT_PLUGINS_EDIT_ENABLED "Build Edit Qt plugin?" ON "TERRALIB_MOD_QT_APF_ENABLED;TERRALIB_MOD_EDIT_QT_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_MOD_MNT_CORE_ENABLED "Build MNT Processing Core module?" ON "TERRALIB_MOD_GEOMETRY_ENABLED;TERRALIB_MOD_DATAACCESS_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_MOD_MNT_QT_ENABLED "Build MNT Processing Qt module?" ON "TERRALIB_QT_ENABLED;TERRALIB_MOD_MNT_CORE_ENABLED;TERRALIB_MOD_QT_WIDGETS_ENABLED;TERRALIB_MOD_EDIT_QT_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_MOD_QT_PLUGINS_MNT_ENABLED "Build MNT Processing Driver Qt plugin?" ON "TERRALIB_MOD_MNT_QT_ENABLED;TERRALIB_MOD_QT_APF_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_MOD_VM_LUA_ENABLED "Build TerraLib Lua Virtual Machine Library?" ON "TERRALIB_LUA_ENABLED;TERRALIB_MOD_VM_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_MOD_VM_PYTHON_ENABLED "Build TerraLib Python Virtual Machine Library?" ON "TERRALIB_PYTHON_ENABLED;TERRALIB_MOD_VM_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()

#
# 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" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_EXAMPLE_GAP_ENABLED "Build the GAP Processing example?" OFF "TERRALIB_BUILD_EXAMPLES_ENABLED;TERRALIB_MOD_VP_CORE_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_EXAMPLE_ATTRIBUTEFILL_ENABLED "Build the Attribute Fill example?" ON "TERRALIB_BUILD_EXAMPLES_ENABLED;TERRALIB_MOD_ATTRIBUTEFILL_CORE_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_EXAMPLE_CEDITOR_ENABLED "Build Code Editor example?" ON "TERRALIB_MOD_CEDITOR_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_EXAMPLE_CELLSPACE_ENABLED "Build the Cellular Space example?" ON "TERRALIB_BUILD_EXAMPLES_ENABLED;TERRALIB_MOD_CELLSPACE_ENABLED;TERRALIB_MOD_DATAACCESS_ENABLED;TERRALIB_MOD_GEOMETRY_ENABLED;TERRALIB_MOD_MAPTOOLS_ENABLED;TERRALIB_MOD_SRS_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" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_EXAMPLE_CORE_ENABLED "Build Core Runtime examples?" ON "TERRALIB_BUILD_EXAMPLES_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_EXAMPLE_BINDING_LUA_ENABLED "Build the lua binding module example?" ON "TERRALIB_MOD_BINDING_LUA_ENABLED" OFF)#TERRALIB_BUILD_EXAMPLES_ENABLED)

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" 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_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_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_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_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_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" 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_XML_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" OFF)

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

CMAKE_DEPENDENT_OPTION(TERRALIB_EXAMPLE_TIN_ENABLED "Build the TIN Processing example?" ON "TERRALIB_BUILD_EXAMPLES_ENABLED;TERRALIB_MOD_MNT_CORE_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_EXAMPLE_WS_OGC_WCS_ENABLED "Build OGC WCS examples?" ON "TERRALIB_BUILD_EXAMPLES_ENABLED;TERRALIB_MOD_WS_OGC_WCS_QT_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_EXAMPLE_WS_OGC_WMS_ENABLED "Build OGC WMS examples?" ON "TERRALIB_BUILD_EXAMPLES_ENABLED;TERRALIB_MOD_WS_OGC_WMS_QT_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_EXAMPLE_VM_ENABLED "Build Virtual Machine examples?" ON "TERRALIB_MOD_VM_LUA_ENABLED" OFF)


#
# build options for the TerraLib Unit Test
#

CMAKE_DEPENDENT_OPTION(TERRALIB_UNITTEST_CORE_ENABLED "Build the unit test for the Core module?" ON "TERRALIB_BUILD_UNITTEST_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_UNITTEST_COMMON_ENABLED "Build the unit test for the Common module?" OFF "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_RASTER_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_UNITTEST_DATATYPE_ENABLED "Build the unit test for the Data Type module?" OFF "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_EDIT_ENABLED "Build the unit test for the Edit module?" ON "TERRALIB_BUILD_UNITTEST_ENABLED;TERRALIB_MOD_EDIT_CORE_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_UNITTEST_FIXGEOMETRIES_ENABLED "Build the unit test for the fix geometries?" OFF "TERRALIB_CPPUNIT_ENABLED;TERRALIB_BUILD_UNITTEST_ENABLED;TERRALIB_MOD_GEOMETRY_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_UNITTEST_GEOMETRY_ENABLED "Build the unit test for the Geometry module?" OFF "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?" OFF "TERRALIB_CPPUNIT_ENABLED;TERRALIB_BUILD_UNITTEST_ENABLED;TERRALIB_MOD_MEMORY_ENABLED;TERRALIB_MOD_RASTER_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_UNITTEST_POSTGIS_ENABLED "Build the unit test for the Postgis module?" ON 
"TERRALIB_CPPUNIT_ENABLED;TERRALIB_BUILD_UNITTEST_ENABLED;TERRALIB_MOD_POSTGIS_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_ENABLED "Build the unit test for the RP module?" ON "TERRALIB_BUILD_UNITTEST_ENABLED;TERRALIB_MOD_GEOMETRY_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?" OFF "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)

CMAKE_DEPENDENT_OPTION(TERRALIB_UNITTEST_VP_ENABLED "Build the unit test for the vector processing?" OFF "TERRALIB_CPPUNIT_ENABLED;TERRALIB_BUILD_UNITTEST_ENABLED;TERRALIB_MOD_GEOMETRY_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_UNITTEST_WS_CORE_ENABLED "Build unit-test for WS Core support?" ON "TERRALIB_BUILD_UNITTEST_ENABLED;TERRALIB_MOD_WS_CORE_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_UNITTEST_WS_OGC_WCS_ENABLED "Build unit-test for OGC WCS support?" ON "TERRALIB_BUILD_UNITTEST_ENABLED;TERRALIB_MOD_WS_OGC_WCS_DATAACCESS_ENABLED" OFF)

CMAKE_DEPENDENT_OPTION(TERRALIB_UNITTEST_WS_OGC_WMS_ENABLED "Build unit-test for OGC WMS support?" ON "TERRALIB_BUILD_UNITTEST_ENABLED;TERRALIB_MOD_WS_OGC_WMS_DATAACCESS_ENABLED" OFF)

#
# build options for the TerraLib Integration Tests
#

CMAKE_DEPENDENT_OPTION(TERRALIB_ITEST_DATAACCESS_ENABLED "Build the integration test for the Data Access module?" OFF "TERRALIB_BUILD_ITEST_ENABLED" OFF "GMOCK_FOUND" OFF)

#
# process TERRALIB configuration files
#

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

configure_file(${TERRALIB_ABSOLUTE_ROOT_DIR}/src/terralib/BuildConfig.h.in
               ${CMAKE_BINARY_DIR}/terralib_buildconfig.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 AND TERRALIB_MOD_QT_WIDGETS_ENABLED AND TERRALIB_QTRANSLATION_ENABLED)
  add_subdirectory(terralib_qtranslations)
endif()

if(TERRALIB_MOD_ADO_ENABLED)
  add_subdirectory(terralib_mod_ado)
  list(APPEND TERRALIB_PLUGINS ado)
endif()

if(TERRALIB_MOD_TERRALIB4_ENABLED)
  add_subdirectory(terralib_mod_terralib4)
  list(APPEND TERRALIB_PLUGINS terralib4)
endif()

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

add_subdirectory(terralib_mod_core)
list(APPEND TERRALIB_MODULES core)

if(TERRALIB_MOD_BINDING_JAVA_ENABLED)
  add_subdirectory(terralib_mod_binding_java)
  list(APPEND TERRALIB_MODULES binding_java)
endif()

if(TERRALIB_MOD_BINDING_LUA_ENABLED)
  add_subdirectory(terralib_mod_binding_lua)
  list(APPEND TERRALIB_MODULES binding_lua)
endif()

if(TERRALIB_MOD_BINDING_PYTHON_ENABLED)
  add_subdirectory(terralib_mod_binding_python)
endif()

if(TERRALIB_MOD_BINDING_R_ENABLED)
  add_subdirectory(terralib_mod_binding_r)
  list(APPEND TERRALIB_MODULES binding_r)
endif()

if(TERRALIB_MOD_CELLSPACE_ENABLED)
  add_subdirectory(terralib_mod_cellspace)
  list(APPEND TERRALIB_MODULES cellspace)
endif()

if(TERRALIB_MOD_CLASSIFICATION_ENABLED)
  add_subdirectory(terralib_mod_classification)
  list(APPEND TERRALIB_MODULES classification)
endif()

if(TERRALIB_MOD_COLOR_ENABLED)
  add_subdirectory(terralib_mod_color)
  list(APPEND TERRALIB_MODULES color)
endif()

add_subdirectory(terralib_mod_common)
list(APPEND TERRALIB_MODULES common)

if(TERRALIB_MOD_CEDITOR_ENABLED)
  add_subdirectory(terralib_mod_ceditor)
  list(APPEND TERRALIB_MODULES ceditor)
endif()

if(TERRALIB_MOD_DATAACCESS_ENABLED)
  add_subdirectory(terralib_mod_dataaccess)
  list(APPEND TERRALIB_MODULES dataaccess)
endif()

if(TERRALIB_MOD_DATATYPE_ENABLED)
  add_subdirectory(terralib_mod_datatype)
  list(APPEND TERRALIB_MODULES datatype)
endif()

if(TERRALIB_MOD_FILTER_ENABLED)
  add_subdirectory(terralib_mod_filter)
  list(APPEND TERRALIB_MODULES filter)
endif()

if(TERRALIB_MOD_GDAL_ENABLED)
  add_subdirectory(terralib_mod_gdal)
  list(APPEND TERRALIB_PLUGINS gdal)
endif()

if(TERRALIB_MOD_GEOMETRY_ENABLED)
  add_subdirectory(terralib_mod_geometry)
  list(APPEND TERRALIB_MODULES geometry)
endif()

if(TERRALIB_MOD_GML_ENABLED)
  add_subdirectory(terralib_mod_gml)
  list(APPEND TERRALIB_MODULES gml)
endif()

if(TERRALIB_MOD_GRAPH_ENABLED)
  add_subdirectory(terralib_mod_graph)
  list(APPEND TERRALIB_MODULES graph)
endif()

if(TERRALIB_MOD_MAPTOOLS_ENABLED)
  add_subdirectory(terralib_mod_maptools)
  list(APPEND TERRALIB_MODULES maptools)
endif()

if(TERRALIB_MOD_METADATA_ENABLED)
  add_subdirectory(terralib_mod_metadata)
  list(APPEND TERRALIB_MODULES metadata)
endif()

if(TERRALIB_MOD_MEMORY_ENABLED)
  add_subdirectory(terralib_mod_memory)
  list(APPEND TERRALIB_MODULES memory)
endif()

if(TERRALIB_MOD_OGR_ENABLED)
  add_subdirectory(terralib_mod_ogr)
  list(APPEND TERRALIB_PLUGINS ogr)
endif()

if(TERRALIB_MOD_POSTGIS_ENABLED)
  add_subdirectory(terralib_mod_postgis)
  list(APPEND TERRALIB_PLUGINS postgis)
endif()

if(TERRALIB_MOD_ATTRIBUTEFILL_CORE_ENABLED)
  add_subdirectory(terralib_mod_attributefill_core)
  list(APPEND TERRALIB_MODULES attributefill_core)
endif()

if(TERRALIB_MOD_ATTRIBUTEFILL_QT_ENABLED)
  add_subdirectory(terralib_mod_attributefill_qt)
  list(APPEND TERRALIB_MODULES attributefill_qt)
endif()

if(TERRALIB_MOD_ADDRESSGEOCODING_CORE_ENABLED)
  add_subdirectory(terralib_mod_addressgeocoding_core)
  list(APPEND TERRALIB_MODULES addressgeocoding_core)
endif()

if(TERRALIB_MOD_ADDRESSGEOCODING_QT_ENABLED)
  add_subdirectory(terralib_mod_addressgeocoding_qt)
  list(APPEND TERRALIB_MODULES addressgeocoding_qt)
endif()

if(TERRALIB_MOD_QT_APF_ENABLED)
  add_subdirectory(terralib_mod_qt_apf)
  list(APPEND TERRALIB_MODULES qt_apf)
endif()

if(TERRALIB_MOD_QT_PLUGINS_CELLSPACE_ENABLED)
  add_subdirectory(terralib_mod_qt_plugins_cellspace)
  list(APPEND TERRALIB_PLUGINS qt_plugins_cellspace)
endif()

if(TERRALIB_MOD_QT_PLUGINS_DATASOURCE_ADO_ENABLED)
  add_subdirectory(terralib_mod_qt_plugins_datasource_ado)
  list(APPEND TERRALIB_PLUGINS qt_plugins_datasource_ado)
endif()

if(TERRALIB_MOD_QT_PLUGINS_DATASOURCE_GDAL_ENABLED)
  add_subdirectory(terralib_mod_qt_plugins_datasource_gdal)
  list(APPEND TERRALIB_PLUGINS qt_plugins_datasource_gdal)
endif()

if(TERRALIB_MOD_QT_PLUGINS_DATASOURCE_TERRALIB4_ENABLED)
  add_subdirectory(terralib_mod_qt_plugins_datasource_terralib4)
  list(APPEND TERRALIB_PLUGINS qt_plugins_datasource_terralib4)
endif()

if(TERRALIB_MOD_QT_PLUGINS_DATASOURCE_OGR_ENABLED)
  add_subdirectory(terralib_mod_qt_plugins_datasource_ogr)
  list(APPEND TERRALIB_PLUGINS qt_plugins_datasource_ogr)
endif()

if(TERRALIB_MOD_QT_PLUGINS_DATASOURCE_POSTGIS_ENABLED)
  add_subdirectory(terralib_mod_qt_plugins_datasource_pgis)
  list(APPEND TERRALIB_PLUGINS qt_plugins_datasource_pgis)
endif()

if(TERRALIB_MOD_QT_PLUGINS_DATASOURCE_WFS_ENABLED)
  add_subdirectory(terralib_mod_qt_plugins_datasource_wfs)
  list(APPEND TERRALIB_PLUGINS qt_plugins_datasource_wfs)
endif()

if(TERRALIB_MOD_QT_PLUGINS_ADDRESSGEOCODING_ENABLED)
  add_subdirectory(terralib_mod_qt_plugins_addressgeocoding)
  list(APPEND TERRALIB_PLUGINS qt_plugins_addressgeocoding)
endif()

if(TERRALIB_MOD_QT_PLUGINS_ATTRIBUTEFILL_ENABLED)
  add_subdirectory(terralib_mod_qt_plugins_attributefill)
  list(APPEND TERRALIB_PLUGINS qt_plugins_attributefill)
endif()

if(TERRALIB_MOD_QT_PLUGINS_VP_ENABLED)
  add_subdirectory(terralib_mod_qt_plugins_vp)
  list(APPEND TERRALIB_PLUGINS qt_plugins_vp)
endif()

if(TERRALIB_MOD_QT_PLUGINS_RP_ENABLED)
  add_subdirectory(terralib_mod_qt_plugins_rp)
  list(APPEND TERRALIB_PLUGINS qt_plugins_rp)
endif()

if(TERRALIB_MOD_QT_PLUGINS_SA_ENABLED)
  add_subdirectory(terralib_mod_qt_plugins_sa)
  list(APPEND TERRALIB_PLUGINS qt_plugins_sa)
endif()

if(TERRALIB_MOD_QT_PLUGINS_ST_ENABLED)
  add_subdirectory(terralib_mod_qt_plugins_st)
  list(APPEND TERRALIB_PLUGINS qt_plugins_st)
endif()

if(TERRALIB_MOD_QT_PLUGINS_MOBILE_ENABLED)
  add_subdirectory(terralib_mod_qt_plugins_mobile)
  list(APPEND TERRALIB_PLUGINS qt_plugins_mobile)
endif()

if(TERRALIB_MOD_QT_PLUGINS_WTSS_ENABLED)
  add_subdirectory(terralib_mod_qt_plugins_wtss)
  list(APPEND TERRALIB_PLUGINS qt_plugins_wtss)
endif()

if(TERRALIB_MOD_QT_WIDGETS_ENABLED)
  add_subdirectory(terralib_mod_qt_widgets)
  list(APPEND TERRALIB_MODULES qt_widgets)
endif()

if(TERRALIB_MOD_RASTER_ENABLED)
  add_subdirectory(terralib_mod_raster)
  list(APPEND TERRALIB_MODULES raster)
endif()

if(TERRALIB_MOD_RP_ENABLED)
  add_subdirectory(terralib_mod_rp)
  list(APPEND TERRALIB_MODULES rp)
endif()

if(TERRALIB_MOD_SA_CORE_ENABLED)
  add_subdirectory(terralib_mod_sa_core)
  list(APPEND TERRALIB_MODULES sa_core)
endif()

if(TERRALIB_MOD_SAM_ENABLED)
  add_subdirectory(terralib_mod_sam)
  list(APPEND TERRALIB_MODULES sam)
endif()

if(TERRALIB_MOD_SRS_ENABLED)
  add_subdirectory(terralib_mod_srs)
  list(APPEND TERRALIB_MODULES srs)
endif()

if(TERRALIB_MOD_ST_ENABLED)
  add_subdirectory(terralib_mod_st)
  list(APPEND TERRALIB_MODULES st)
endif()

if(TERRALIB_MOD_WFS_ENABLED)
  add_subdirectory(terralib_mod_wfs)
  list(APPEND TERRALIB_PLUGINS wfs)
endif()

if(TERRALIB_MOD_STATISTICS_CORE_ENABLED)
  add_subdirectory(terralib_mod_statistics_core)
  list(APPEND TERRALIB_MODULES statistics_core)
endif()

if(TERRALIB_MOD_STMEMORY_ENABLED)
  add_subdirectory(terralib_mod_stmemory)
  list(APPEND TERRALIB_MODULES stmemory)
endif()

if(TERRALIB_MOD_STATISTICS_QT_ENABLED)
  add_subdirectory(terralib_mod_statistics_qt)
  list(APPEND TERRALIB_MODULES statistics_qt)
endif()

if(TERRALIB_MOD_SYMBOLOGY_ENABLED)
  add_subdirectory(terralib_mod_symbology)
  list(APPEND TERRALIB_MODULES symbology)
endif()

if(TERRALIB_MOD_VP_CORE_ENABLED)
  add_subdirectory(terralib_mod_vp_core)
  list(APPEND TERRALIB_MODULES vp_core)
endif()

if(TERRALIB_MOD_VP_QT_ENABLED)
  add_subdirectory(terralib_mod_vp_qt)
  list(APPEND TERRALIB_MODULES vp_qt)
endif()

if(TERRALIB_MOD_SA_QT_ENABLED)
  add_subdirectory(terralib_mod_sa_qt)
  list(APPEND TERRALIB_MODULES sa_qt)
endif()

if(TERRALIB_MOD_XLINK_ENABLED)
  add_subdirectory(terralib_mod_xlink)
  list(APPEND TERRALIB_MODULES xlink)
endif()

if(TERRALIB_MOD_XML_ENABLED)
  add_subdirectory(terralib_mod_xml)
  list(APPEND TERRALIB_MODULES xml)
endif()

if(TERRALIB_MOD_EDIT_CORE_ENABLED)
  add_subdirectory(terralib_mod_edit_core)
  list(APPEND TERRALIB_MODULES edit_core)
endif()

if(TERRALIB_MOD_EDIT_QT_ENABLED)
  add_subdirectory(terralib_mod_edit_qt)
  list(APPEND TERRALIB_MODULES edit_qt)
endif()

if(TERRALIB_MOD_QT_PLUGINS_EDIT_ENABLED)
  add_subdirectory(terralib_mod_qt_plugins_edit)
  list(APPEND TERRALIB_PLUGINS qt_plugins_edit)
endif()

if(TERRALIB_TERRAVIEW_ENABLED)
  add_subdirectory(terraview)
endif()

if(TERRALIB_MOD_MNT_CORE_ENABLED)
  add_subdirectory(terralib_mod_mnt_core)
  list(APPEND TERRALIB_MODULES mnt_core)
endif()

if(TERRALIB_MOD_MNT_QT_ENABLED)
  add_subdirectory(terralib_mod_mnt_qt)
  list(APPEND TERRALIB_MODULES mnt_qt)
endif()

if(TERRALIB_MOD_QT_PLUGINS_MNT_ENABLED)
  add_subdirectory(terralib_mod_qt_plugins_mnt)
  list(APPEND TERRALIB_PLUGINS qt_plugins_mnt)
endif()

if(TERRALIB_MOD_VM_ENABLED)
  add_subdirectory(terralib_mod_vm)
  list(APPEND TERRALIB_MODULES vm)
endif()

if(TERRALIB_MOD_VM_LUA_ENABLED)
  add_subdirectory(terralib_mod_vm_lua)
  list(APPEND TERRALIB_PLUGINS vm_lua)
endif()

if(TERRALIB_MOD_VM_PYTHON_ENABLED)
  add_subdirectory(terralib_mod_vm_python)
  list(APPEND TERRALIB_PLUGINS vm_python)
endif()

if(TERRALIB_MOD_WS_CORE_ENABLED)
  add_subdirectory(terralib_mod_ws_core)
  list(APPEND TERRALIB_MODULES ws_core)
endif()

if(TERRALIB_MOD_WS_OGC_WCS_CLIENT_ENABLED)
  add_subdirectory(terralib_mod_ws_ogc_wcs_client)
  list(APPEND TERRALIB_MODULES ws_ogc_wcs_client)
endif()

if(TERRALIB_MOD_WS_OGC_WCS_DATAACCESS_ENABLED)
  add_subdirectory(terralib_mod_ws_ogc_wcs_dataaccess)
  list(APPEND TERRALIB_PLUGINS ws_ogc_wcs_dataaccess)
endif()

if(TERRALIB_MOD_WS_OGC_WCS_QT_ENABLED)
  add_subdirectory(terralib_mod_ws_ogc_wcs_qt)
  list(APPEND TERRALIB_MODULES ws_ogc_wcs_qt)
endif()

if(TERRALIB_MOD_WS_OGC_WCS_QT_PLUGIN_ENABLED)
  add_subdirectory(terralib_mod_ws_ogc_wcs_qt_plugin)
  list(APPEND TERRALIB_PLUGINS ws_ogc_wcs_qt_plugin)
endif()

if(TERRALIB_MOD_WS_OGC_WMS_CLIENT_ENABLED)
  add_subdirectory(terralib_mod_ws_ogc_wms_client)
  list(APPEND TERRALIB_MODULES ws_ogc_wms_client)
endif()

if(TERRALIB_MOD_WS_OGC_WMS_DATAACCESS_ENABLED)
  add_subdirectory(terralib_mod_ws_ogc_wms_dataaccess)
  list(APPEND TERRALIB_PLUGINS ws_ogc_wms_dataaccess)
endif()

if(TERRALIB_MOD_WS_OGC_WMS_QT_ENABLED)
  add_subdirectory(terralib_mod_ws_ogc_wms_qt)
  list(APPEND TERRALIB_MODULES ws_ogc_wms_qt)
endif()

if(TERRALIB_MOD_WS_OGC_WMS_QT_PLUGIN_ENABLED)
  add_subdirectory(terralib_mod_ws_ogc_wms_qt_plugin)
  list(APPEND TERRALIB_PLUGINS ws_ogc_wms_qt_plugin)
endif()

add_subdirectory(terralib_mod_binding_c)

#
# build examples
#

if(TERRALIB_EXAMPLE_CORE_ENABLED)
  add_subdirectory(terralib_example_core)
endif()

if(TERRALIB_EXAMPLE_CEDITOR_ENABLED)
  add_subdirectory(terralib_example_ceditor)
endif()

if(TERRALIB_EXAMPLE_ADO_ENABLED)
  add_subdirectory(terralib_example_ado)
endif()

if(TERRALIB_EXAMPLE_GAP_ENABLED)
  add_subdirectory(terralib_example_gap)
endif()

if(TERRALIB_EXAMPLE_ATTRIBUTEFILL_ENABLED)
  add_subdirectory(terralib_example_attributefill)
endif()

if(TERRALIB_EXAMPLE_BINDING_LUA_ENABLED)
  add_subdirectory(terralib_example_bind_lua)
endif()

if(TERRALIB_EXAMPLE_CELLSPACE_ENABLED)
  add_subdirectory(terralib_example_cellspace)
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_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()

if(TERRALIB_EXAMPLE_TIN_ENABLED)
  add_subdirectory(terralib_example_TIN)
endif()

if(TERRALIB_EXAMPLE_VM_ENABLED)
  add_subdirectory(terralib_example_vm)
endif()

if(TERRALIB_EXAMPLE_WS_OGC_WCS_ENABLED)
  add_subdirectory(terralib_example_ws_ogc_wcs)
endif()

if(TERRALIB_EXAMPLE_WS_OGC_WMS_ENABLED)
  add_subdirectory(terralib_example_ws_ogc_wms)
endif()

#
# build unit test
#

if(TERRALIB_BUILD_UNITTEST_ENABLED AND CPPUNIT_FOUND)
  set (DEPS_DIR ${CMAKE_PREFIX_PATH}/lib)

  set (BIN_DIR ${CMAKE_BINARY_DIR}/Debug)

  configure_file(${CMAKE_SOURCE_DIR}/unittest.bat.in ${CMAKE_BINARY_DIR}/unittest.debug.bat)

  set (BIN_DIR ${CMAKE_BINARY_DIR}/Release)

  configure_file(${CMAKE_SOURCE_DIR}/unittest.bat.in ${CMAKE_BINARY_DIR}/unittest.release.bat)
endif()

if(TERRALIB_UNITTEST_CORE_ENABLED)
  add_subdirectory(terralib_unittest_core)
endif()

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_EDIT_ENABLED)
  add_subdirectory(terralib_unittest_edit)
endif()

if(TERRALIB_UNITTEST_GEOMETRY_ENABLED)
  add_subdirectory(terralib_unittest_geometry)
endif()

if(TERRALIB_UNITTEST_FIXGEOMETRIES_ENABLED)
  add_subdirectory(terralib_unittest_fixgeometries)
endif()

if(TERRALIB_UNITTEST_MEMORY_ENABLED)
  add_subdirectory(terralib_unittest_memory)
endif()

if(TERRALIB_UNITTEST_POSTGIS_ENABLED)
  add_subdirectory(terralib_unittest_postgis)
endif()

if(TERRALIB_UNITTEST_RASTER_ENABLED)
  add_subdirectory(terralib_unittest_raster)
endif()

if(TERRALIB_UNITTEST_RP_ENABLED)
  add_subdirectory(terralib_unittest_rp)
endif()

if(TERRALIB_UNITTEST_SAM_ENABLED)
  add_subdirectory(terralib_unittest_sam)
endif()

if(TERRALIB_UNITTEST_SRS_ENABLED)
  add_subdirectory(terralib_unittest_srs)
endif()

if(TERRALIB_UNITTEST_VP_ENABLED)
  add_subdirectory(terralib_unittest_vp)
endif()

if(TERRALIB_UNITTEST_WS_CORE_ENABLED)
  add_subdirectory(terralib_unittest_ws_core)
endif()

if(TERRALIB_UNITTEST_WS_OGC_WCS_ENABLED)
  add_subdirectory(terralib_unittest_ws_ogc_wcs)
endif()

if(TERRALIB_UNITTEST_WS_OGC_WMS_ENABLED)
  add_subdirectory(terralib_unittest_ws_ogc_wms)
endif()

#
# build integration test
#

if(TERRALIB_ITEST_DATAACCESS_ENABLED)
  add_subdirectory(terralib_itest_dataaccess)
endif()

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

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

#
# install and targets export
#

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

install(FILES ${CMAKE_BINARY_DIR}/terralib_buildconfig.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
              ${terralib_SOURCE_DIR}/terralib_macros.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)

if(TERRALIB_TRANSLATOR_ENABLED)
  install(DIRECTORY ${CMAKE_BINARY_DIR}/share/terralib/translations/
          DESTINATION ${TERRALIB_DESTINATION_SHARE}/terralib/translations
          COMPONENT runtime)
endif()

#
# 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()

set(_mods "")

GetTerraLibModules(_mods)

export( TARGETS ${_mods} FILE ${CMAKE_BINARY_DIR}/terralib-exports.cmake)

#
# 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)

if(UNIX AND TERRALIB_BUILD_AS_BUNDLE AND DEFINED TERRALIB_BASE_DESTINATION_DIR AND CPACK_BINARY_DEB)
  configure_file(${CMAKE_SOURCE_DIR}/../../packages/linux/terraview.desktop.in
                 ${CMAKE_BINARY_DIR}/terraview.desktop @ONLY)
  install(FILES ${terralib_BINARY_DIR}/terraview.desktop
          DESTINATION /usr/share/applications COMPONENT runtime)
endif()

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)

#
# 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)
