# Copyright 2006-2008 The FLWOR Foundation.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# specify the standard configuration here
# 1. set the variable you want to use and assign it a default value
#    make sure you specify the datatype and the keyword CACHE to
#    tell cmake that it needs to store the value in its cache
# 2. print out a message showing the status of your variable
# 3. add your configuration parameter to include/zorba/config.h.cmake
#    for example for string variables use
#    #define ZORBA_BATCHING_TYPE    ${ZORBA_BATCHING_TYPE}
#    ${VARIABLE} is replaced by cmake using the value
#    that is set for this variable
#    for booleans (e.g. SET (ZORBA_VARIABLE OFF CACHE BOOL "zorba variable")), use
#    #cmakedefine VARIABLE
# 4. if you want to change your variable value, execute
#    cmake -DVARIABLE=new_value
#    the variable will keep this value (i.e. store it in the cache file CMakeCache.txt)
#    until you set a new one or edit the CMakeCache.txt file
#

SET(ZORBA_NATIVE_STORE ON CACHE BOOL "Choose zorba native store")
MESSAGE(STATUS "ZORBA_NATIVE_STORE:                   " ${ZORBA_NATIVE_STORE})

# Adding store srcs
IF(ZORBA_NATIVE_STORE)
  SET(ZORBA_STORE_DIR "${CMAKE_SOURCE_DIR}/src/store/naive" CACHE PATH "Path to the store directory. Must contain CMakeLists.txt defining the variable ZORBA_STORE_IMPL_SRCS.")
  SET(ZORBA_STORE_NAME "simplestore" CACHE STRING "Names of the stores. Must have be in sync with ZORBA_STORE_DIR")
ENDIF(ZORBA_NATIVE_STORE)

MESSAGE(STATUS "ZORBA_STORE_DIR:                     " ${ZORBA_STORE_DIR})
MESSAGE(STATUS "ZORBA_STORE_NAME:                    " ${ZORBA_STORE_NAME})

# how should batching in the runtime system be done
SET(ZORBA_BATCHING_TYPE 0 CACHE STRING
    "0 = NO_BATCHING, 1 = SIMPLE_BATCHING, 2 = SUPER_BATCHING")
MESSAGE(STATUS "ZORBA_BATCHING_TYPE:                  " ${ZORBA_BATCHING_TYPE})

# number of items to batch if ZORBA_BATCHING_TYPE is SIMPLE_BATCHING or SUPER_BATCHING
IF (ZORBA_BATCHING_TYPE GREATER 0)
    SET(ZORBA_BATCHING_BATCHSIZE 100 CACHE STRING
        "the batchsize used if batching is used")
    MESSAGE(STATUS "ZORBA_BATCHING_BATCHSIZE:             " ${ZORBA_BATCHING_BATCHSIZE})
ENDIF (ZORBA_BATCHING_TYPE GREATER 0)

# float point precision
SET(ZORBA_FLOAT_POINT_PRECISION 18 CACHE STRING
   "number of decimal places in floating point serialization")
MESSAGE(STATUS "ZORBA_FLOAT_POINT_PRECISION:          " ${ZORBA_FLOAT_POINT_PRECISION})

# code coverage information
SET(ZORBA_WITH_CODE_COVERAGE OFF CACHE BOOL "compile the code with information for a code coverage analysis")
MESSAGE(STATUS "ZORBA_WITH_CODE_COVERAGE:             " ${ZORBA_WITH_CODE_COVERAGE})

# code profile information
SET(ZORBA_WITH_CODE_PROFILE OFF CACHE BOOL "compile the code with information for a code profiling analysis")
MESSAGE(STATUS "ZORBA_WITH_CODE_PROFILE:              " ${ZORBA_WITH_CODE_PROFILE})

SET(ZORBA_FOR_ONE_THREAD_ONLY ON CACHE BOOL "compile zorba for single threaded use")
MESSAGE(STATUS "ZORBA_FOR_ONE_THREAD_ONLY:            " ${ZORBA_FOR_ONE_THREAD_ONLY})

IF (DEFINED UNIX)
  IF (NOT DEFINED ZORBA_HAVE_PTHREAD_H AND NOT DEFINED ZORBA_FOR_ONE_THREAD_ONLY)
    MESSAGE(FATAL_ERROR "pthread is not available")
  ENDIF (NOT DEFINED ZORBA_HAVE_PTHREAD_H AND NOT DEFINED ZORBA_FOR_ONE_THREAD_ONLY)
ELSE (DEFINED UNIX)
  SET(ZORBA_WIN_PLATFORM "win32" CACHE STRING "win platform")
  MESSAGE(STATUS "ZORBA_WIN_PLATFORM [win32/pocketpc/smartphone]: " ${ZORBA_WIN_PLATFORM})
  IF("${ZORBA_WIN_PLATFORM}" STREQUAL "pocketpc" OR "${ZORBA_WIN_PLATFORM}" STREQUAL "smartphone")
    SET(WINCE ON)
    SET(WIN32 OFF)
  ENDIF("${ZORBA_WIN_PLATFORM}" STREQUAL "pocketpc" OR "${ZORBA_WIN_PLATFORM}" STREQUAL "smartphone")
ENDIF (DEFINED UNIX)

SET(ZORBA_WITH_FILE_ACCESS ON CACHE BOOL "compile zorba and allow loading documents from the filesystem")
MESSAGE(STATUS "ZORBA_WITH_FILE_ACCESS [ON/OFF]:      " ${ZORBA_WITH_FILE_ACCESS})

SET(ZORBA_WITH_DEBUGGER ON CACHE BOOL "compile zorba with debugger support")
MESSAGE(STATUS "ZORBA_WITH_DEBUGGER [ON/OFF]:         " ${ZORBA_WITH_DEBUGGER})

SET(ZORBA_TEST_TIMEOUT_VALUE 60 CACHE INTEGER "default test timeout value")
MESSAGE(STATUS "ZORBA_TEST_TIMEOUT_VALUE:             " ${ZORBA_TEST_TIMEOUT_VALUE})

SET(ZORBA_VERIFY_PEER_SSL_CERTIFICATE OFF CACHE BOOL "Disable root certificate validation")
MESSAGE(STATUS "ZORBA_VERIFY_PEER_SSL_CERTIFICATE:    " ${ZORBA_VERIFY_PEER_SSL_CERTIFICATE})

SET(ZORBA_WIN_DLL ON)
MESSAGE(STATUS "ZORBA_WIN_DLL:                        " ${ZORBA_WIN_DLL})

# We need the path to the zorba executable because it will be used during the
# build to generate source code and documentation.
SET(ZORBA_EXE "${CMAKE_BINARY_DIR}/bin/zorba")
IF(WIN32)
  SET(ZORBA_EXE "${ZORBA_EXE}.bat")
ENDIF(WIN32)
SET(ZORBA_EXE ${ZORBA_EXE} CACHE STRING "executable used for generating the runtime")
MESSAGE(STATUS "ZORBA_EXE:                            " ${ZORBA_EXE})

# flags for debugging the parser
SET(ZORBA_DEBUG_PARSER OFF CACHE BOOL "debug the parser")
MESSAGE(STATUS "ZORBA_DEBUG_PARSER:                   " ${ZORBA_DEBUG_PARSER})

# if not set by the user, set ZORBA_DEBUG_STRING to ON for Debug and RelWithDebInfo builds
IF (NOT ZORBA_DEBUG_STRING)
  IF (CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
    SET (ZORBA_DEBUG_STRING ON)
  ELSE (CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
    SET (ZORBA_DEBUG_STRING OFF)
  ENDIF (CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
ENDIF (NOT ZORBA_DEBUG_STRING)
SET (ZORBA_DEBUG_STRING ${ZORBA_DEBUG_STRING} CACHE BOOL "debug strings")
MESSAGE (STATUS "ZORBA_DEBUG_STRING:                   " ${ZORBA_DEBUG_STRING})

SET(ZORBA_NO_ICU OFF CACHE BOOL "disable ICU")
MESSAGE(STATUS "ZORBA_NO_ICU:                         " ${ZORBA_NO_ICU})

IF (ZORBA_NO_ICU)
  SET (no_full_text ON)
ELSE (ZORBA_NO_ICU)
  SET (no_full_text OFF)
ENDIF (ZORBA_NO_ICU)
SET (ZORBA_NO_FULL_TEXT ${no_full_text} CACHE BOOL "disable XQuery Full-Text support")
MESSAGE(STATUS "ZORBA_NO_FULL_TEXT:                   " ${ZORBA_NO_FULL_TEXT})

SET(ZORBA_NO_XMLSCHEMA OFF CACHE BOOL "disable XMLSchema support")
MESSAGE(STATUS "ZORBA_NO_XMLSCHEMA:                   " ${ZORBA_NO_XMLSCHEMA})

SET(ZORBA_WITH_BIG_INTEGER OFF CACHE BOOL "enable arbitrary precision integers")
MESSAGE(STATUS "ZORBA_WITH_BIG_INTEGER:               " ${ZORBA_WITH_BIG_INTEGER})

SET(ZORBA_WITH_THESAURUS ON CACHE BOOL
    "enable installation of default English Wordnet thesaurus")
MESSAGE(STATUS "ZORBA_WITH_THESAURUS:                 " ${ZORBA_WITH_THESAURUS})

IF (ZORBA_SUPPRESS_SWIG)
  SET (no_swig ON)
ELSE (ZORBA_SUPPRESS_SWIG)
  SET (no_swig OFF)
ENDIF (ZORBA_SUPPRESS_SWIG)
SET(ZORBA_SUPPRESS_SWIG ${no_swig} CACHE BOOL "use Swig to generate api for Python, Php and Ruby")
MESSAGE(STATUS "ZORBA_SUPPRESS_SWIG [ON/OFF]:         " ${no_swig})

SET(ZORBA_XQUERYX OFF CACHE BOOL "Activate capability to compile XQueryX code (on/off)")
MESSAGE(STATUS "ZORBA_XQUERYX:                        " ${ZORBA_XQUERYX})

SET(ZORBA_TEST_XQUERYX OFF CACHE BOOL "Test only xqueryx (.xqx) tests")
MESSAGE(STATUS "ZORBA_TEST_XQUERYX:                   " ${ZORBA_TEST_XQUERYX})
IF(ZORBA_TEST_XQUERYX)
  SET(ZORBA_XQUERYX ON CACHE BOOL "Activate capability to compile XQueryX code (on/off)" FORCE)
ENDIF(ZORBA_TEST_XQUERYX)

IF(WIN32)
  SET(CMAKE_SKIP_RPATH ON CACHE BOOL "The rpath information is not added to compiled executables")
  MESSAGE(STATUS "CMAKE_SKIP_RPATH:                     " ${CMAKE_SKIP_RPATH})
ENDIF(WIN32)

# below we print some variables you might be interested in, when compiling

# if you are building in-source, this is the same as CMAKE_SOURCE_DIR, otherwise
# this is the top level directory of your build tree
MESSAGE(STATUS "CMAKE_BINARY_DIR:                     " ${CMAKE_BINARY_DIR})

# this is the directory, from which cmake was started, i.e. the top level source directory
MESSAGE(STATUS "CMAKE_SOURCE_DIR:                     " ${CMAKE_SOURCE_DIR})

# the complete system name, e.g. "Linux-2.4.22", "FreeBSD-5.4-RELEASE" or "Windows 5.1"
MESSAGE(STATUS "CMAKE_SYSTEM:                         " ${CMAKE_SYSTEM})

# the short system name, e.g. "Linux", "FreeBSD" or "Windows"
MESSAGE(STATUS "CMAKE_SYSTEM_NAME:                    " ${CMAKE_SYSTEM_NAME})

# only the version part of CMAKE_SYSTEM
MESSAGE(STATUS "CMAKE_SYSTEM_VERSION:                 " ${CMAKE_SYSTEM_VERSION})

# the processor name (e.g. "Intel(R) Pentium(R) M processor 2.00GHz")
MESSAGE(STATUS "CMAKE_SYSTEM_PROCESSOR:               " ${CMAKE_SYSTEM_PROCESSOR})

# is TRUE on all UNIX-like OS's, including Apple OS X and CygWin
MESSAGE(STATUS "UNIX:                                 " ${UNIX})

# is TRUE on Windows, including CygWin
MESSAGE(STATUS "WIN32:                                " ${WIN32})

# is TRUE on Apple OS X
MESSAGE(STATUS "APPLE:                                " ${APPLE})

# is TRUE when using the MinGW compiler in Windows
MESSAGE(STATUS "MINGW:                                " ${MINGW})

# is TRUE on Windows when using the CygWin version of cmake
MESSAGE(STATUS "CYGWIN:                               " ${CYGWIN})

# is TRUE on Windows when using a Borland compiler
MESSAGE(STATUS "BORLAND:                              " ${BORLAND})

# Microsoft compiler
MESSAGE(STATUS "MSVC:                                 " ${MSVC})
MESSAGE(STATUS "MSVC_IDE:                             " ${MSVC_IDE})
MESSAGE(STATUS "MSVC60:                               " ${MSVC60})
MESSAGE(STATUS "MSVC70:                               " ${MSVC70})
MESSAGE(STATUS "MSVC71:                               " ${MSVC71})
MESSAGE(STATUS "MSVC80:                               " ${MSVC80})
MESSAGE(STATUS "CMAKE_COMPILER_2005:                  " ${CMAKE_COMPILER_2005})

# A simple way to get switches to the compiler is to use ADD_DEFINITIONS().
# But there are also two variables exactly for this purpose:

IF(${ZORBA_WITH_CODE_PROFILE})
  IF(APPLE)
    SET(CMAKE_C_FLAGS "-finstrument-functions -Wl,-lSaturn ${CMAKE_C_FLAGS}")
    SET(CMAKE_CXX_FLAGS "-finstrument-functions -Wl,-lSaturn ${CMAKE_CXX_FLAGS}")
  ELSE(APPLE)
    SET(CMAKE_C_FLAGS "-pg ${CMAKE_C_FLAGS}")
    SET(CMAKE_CXX_FLAGS "-pg ${CMAKE_CXX_FLAGS}")
  ENDIF(APPLE)
ENDIF(${ZORBA_WITH_CODE_PROFILE})

# the compiler flags for compiling C sources
MESSAGE(STATUS "CMAKE_C_FLAGS:                        " ${CMAKE_C_FLAGS})

# the compiler flags for compiling C++ sources
MESSAGE(STATUS "CMAKE_CXX_FLAGS:                      " ${CMAKE_CXX_FLAGS})

# choose the type of build.  Example: SET(CMAKE_BUILD_TYPE Debug)
MESSAGE(STATUS "CMAKE_BUILD_TYPE:                     " ${CMAKE_BUILD_TYPE})

# where will install commands place their output
MESSAGE(STATUS "CMAKE_INSTALL_PREFIX:                 " ${CMAKE_INSTALL_PREFIX})

# if this is set to ON, then all libraries are built as shared libraries by default.
MESSAGE(STATUS "BUILD_SHARED_LIBS:                    " ${BUILD_SHARED_LIBS})

# the compiler used for C files
MESSAGE(STATUS "CMAKE_C_COMPILER:                     " ${CMAKE_C_COMPILER})

# the compiler used for C++ files
MESSAGE(STATUS "CMAKE_CXX_COMPILER:                   " ${CMAKE_CXX_COMPILER})

# if the compiler is a variant of gcc, this should be set to 1
MESSAGE(STATUS "CMAKE_COMPILER_IS_GNUCC:              " ${CMAKE_COMPILER_IS_GNUCC})

# if the compiler is a variant of g++, this should be set to 1
MESSAGE(STATUS "CMAKE_COMPILER_IS_GNUCXX:             " ${CMAKE_COMPILER_IS_GNUCXX})

# the tools for creating libraries
MESSAGE(STATUS "CMAKE_AR:                             " ${CMAKE_AR})
MESSAGE(STATUS "CMAKE_RANLIB:                         " ${CMAKE_RANLIB})

IF(LIBXML2_FOUND)
     SET(ZORBA_WITH_LIBXML2_SAX ON CACHE BOOL "compile with a sax parser for libxml2")
ELSE(LIBXML2_FOUND)
     SET(ZORBA_WITH_LIBXML2_SAX ON CACHE BOOL "compile with a sax parser for libxml2")
ENDIF(LIBXML2_FOUND)

IF(WIN32)
  SET(CPACK_INSTALL_PREFIX "" CACHE STRING "Set to empty string so that cpack can work")
ENDIF(WIN32)
