<commit_before># ------------------------------------------------------------------------------
# General
# ------------------------------------------------------------------------------

cmake_minimum_required(VERSION 2.8)

if (APPLE)
  if (NOT DEFINED CMAKE_C_COMPILER)
    set(CMAKE_C_COMPILER /usr/bin/clang)
  endif ()
  
  if (NOT DEFINED CMAKE_CXX_COMPILER)
    set(CMAKE_CXX_COMPILER /usr/bin/clang++)
  endif ()
endif ()

project(ArangoDB)

if (POLICY CMP0037)
  cmake_policy(SET CMP0037 NEW)
endif ()


set(ARANGODB_DISPLAY_NAME       "ArangoDB")
set(ARANGODB_URL_INFO_ABOUT     "http://www.arangodb.org")
set(ARANGODB_CONTACT            "<EMAIL>")

set(ARANGODB_VERSION_MAJOR      "3")
set(ARANGODB_VERSION_MINOR      "0")
set(ARANGODB_VERSION_REVISION   "0-devel")

set(ARANGODB_VERSION
    "${ARANGODB_VERSION_MAJOR}.${ARANGODB_VERSION_MINOR}.${ARANGODB_VERSION_REVISION}")

configure_file (
  "${CMAKE_CURRENT_SOURCE_DIR}/lib/Basics/build.h.in"
  "${CMAKE_CURRENT_BINARY_DIR}/lib/Basics/build.h")

configure_file (
  "${CMAKE_CURRENT_SOURCE_DIR}/lib/Basics/VERSION.in"
  "${CMAKE_CURRENT_SOURCE_DIR}/VERSION")

set(ARANGODB_FRIENDLY_STRING    "ArangoDB - the multi-model database")
set(ARANGOB_FRIENDLY_STRING     "ArangoBench - stresstester")
set(ARANGO_DUMP_FRIENDLY_STRING
  "arangodump - export whole databases from ArangoDB to JSON") 
set(ARANGO_IMP_FRIENDLY_STRING  "arangoimp - import CSV files into ArangoDB")
set(ARANGO_RESTORE_HELP_LINK
  "arangrestore - import dumpfiles created with arangodump into ArangoDB")
set(ARANGOSH_HELP_LINK          "arangosh - commandline client of ArangoDB")

if (NOT CMAKE_BUILD_TYPE)
  set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE string
    "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel."
    FORCE)
endif ()

# Where 2 find CMAKE modules
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake)

# ArangoDB needs c++11
set(CMAKE_CXX_STANDARD 11)
include (CheckCXX11Features)

# Need threads
find_package(Threads REQUIRED)

option(AR_USE_SYSTEM_LIBS "use libraries provided by the system" OFF)

# Object archives
set(LIB_ARANGO        arango)
set(LIB_ARANGO_CLIENT arango_client)
set(LIB_ARANGO_V8     arango_v8)

# Binaries
set(BIN_ARANGOB       arangob)
set(BIN_ARANGOD       arangod)
set(BIN_ARANGODUMP    arangodump)
set(BIN_ARANGOIMP     arangoimp)
set(BIN_ARANGORESTORE arangorestore)
set(BIN_ARANGOSH      arangosh)

# Google V8 engine including ICU
set(V8_VERSION        4.3.61)

message(STATUS ${CMAKE_SYSTEM_TYPE})

# Architecture
math(EXPR BITS "8*${CMAKE_SIZEOF_VOID_P}")
add_definitions("-DTRI_BITS=${BITS}")

set(MAKE make)
set(USE_TCMALLOC, TRUE)
set(THIRDP_BUILDFLAGS "CC=${CMAKE_C_COMPILER}")
set(HOST_BITS ${BITS})
# OS type (Convenience) --------------------------------------------------------
if(WIN32)
  if(NOT WINDOWS)
    set(USE_TCMALLOC, FALSE)
    set(WINDOWS TRUE)
  endif()
elseif(UNIX AND NOT APPLE)
  if(CMAKE_SYSTEM_NAME MATCHES ".*Linux")
    set(LINUX TRUE)
  elseif (CMAKE_SYSTEM_NAME MATCHES "kFreeBSD.*")
    set(FREEBSD TRUE)
  elseif (CMAKE_SYSTEM_NAME MATCHES "kNetBSD.*|NetBSD.*")
    set(NETBSD TRUE)
  elseif (CMAKE_SYSTEM_NAME MATCHES "kOpenBSD.*|OpenBSD.*")
    set(OPENBSD TRUE)
  elseif (CMAKE_SYSTEM_NAME MATCHES ".*GNU.*")
    set(GNU TRUE)
  elseif (CMAKE_SYSTEM_NAME MATCHES ".*BSDI.*")
    set(BSDI TRUE)
  elseif (CMAKE_SYSTEM_NAME MATCHES "DragonFly.*|FreeBSD")
    set(FREEBSD TRUE)
  elseif (CMAKE_SYSTEM_NAME MATCHES "SYSV5.*")
    set(SYSV5 TRUE)
  elseif ((CMAKE_SYSTEM_NAME MATCHES "Solaris.*") OR (CMAKE_SYSTEM_NAME MATCHES "SunOS.*"))
    set(USE_TCMALLOC, FALSE)
    set(CMAKE_CXX_SIZEOF_DATA_PTR 8)
    set(CMAKE_SIZEOF_VOID_P 8)
    set(BITS 64)
    set(CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES /lib;/lib64;/lib64;/usr/lib;/usr/lib64;/usr/lib64)
    set(MAKE gmake)
    set(HOST_BITS 64)
    set(SOLARIS TRUE)
    list(APPEND CMAKE_C_FLAGS -I\ /opt/csw/include\ -D_REENTRANT\ -m64)
    list(APPEND CMAKE_CXX_FLAGS -I\ /opt/csw/include\ -D_REENTRANT\ -m64)
    set(THIRDP_BUILDFLAGS --target=x86_64-pc-solaris2.11
      --host=x86_64-pc-solaris2.11
      --build=x86_64-pc-solaris2.11
      # TODO: is this CMAKE_C_COMPILER? CC=/opt/csw/bin/gcc
      CC=/opt/csw/bin/gcc
      CXX=/opt/csw/bin/g++
      CFLAGS=-I\ /opt/csw/include\ -D_REENTRANT\ -m64
      CXXFLAGS=-I\ /opt/csw/include\ -D_REENTRANT\ -m64
      LDFLAGS=-L/opt/csw/lib\ -march=x86-64\ -m64
      )
   elseif (CMAKE_SYSTEM_NAME MATCHES "HP-UX.*")
    set(HPUX TRUE)
  elseif (CMAKE_SYSTEM_NAME MATCHES "AIX.*")
    set(AIX TRUE)
  elseif (CMAKE_SYSTEM_NAME MATCHES "Minix.*")
    set(MINIX TRUE)
  endif ()
elseif (APPLE)
  if (CMAKE_SYSTEM_NAME MATCHES ".*Darwin.*")
    set(DARWIN TRUE)
  elseif (CMAKE_SYSTEM_NAME MATCHES ".*MacOS.*")
    set(MACOSX TRUE)
  endif ()
endif ()

# TODO: Exclude non-supported?

# BISON&FLEX -------------------------------------------------------------------
find_package (BISON)

# FLEX -------------------------------------------------------------------------
find_package (FLEX)

# GO ---------------------------------------------------------------------------
find_package(Go 1.2)

# Python
find_package(PythonInterp 2)
set(ENV{PYTHON_EXECUTABLE} ${PYTHON_EXECUTABLE})

## Compiler flags --------------------------------------------------------------

################################################################################
# BUILD TYPES
################################################################################

string(TOLOWER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_TL)
message (${CMAKE_BUILD_TYPE_TL})
set(DEBUG FALSE)
if (CMAKE_BUILD_TYPE_TL MATCHES debug)
  set(DEBUG TRUE)
  set(WIN_RELEASE_TYPE Debug)
  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0 -g")
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0 -g")
elseif (CMAKE_BUILD_TYPE_TL MATCHES relwithdebinfo)
  set(WIN_RELEASE_TYPE RelWithDebInfo)
  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O2 -g")
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -g")
elseif (CMAKE_BUILD_TYPE_TL MATCHES release)
  set(WIN_RELEASE_TYPE Release)
  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3")
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
endif () 

################################################################################
# GCC 
################################################################################

if (CMAKE_COMPILER_IS_GNUCC)
  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu89")
  set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}")
endif ()
if (CMAKE_COMPILER_IS_GNUCXX)
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
endif ()

################################################################################
# OTHER COMPILERS
################################################################################

if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  set(CMAKE_COMPILER_IS_CLANG 1)
elseif (CMAKE_CXX_COMPILER_ID MATCHES "AppleClang")
  set(CMAKE_COMPILER_IS_CLANG 1)
elseif (CMAKE_CXX_COMPILER_ID MATCHES "Intel")
  set(CMAKE_COMPILER_IS_INTEL 1)
elseif (CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
  set(CMAKE_COMPILER_IS_INTEL 1)
endif ()

################################################################################
# OSX
################################################################################

if (APPLE)
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

  if (CMAKE_COMPILER_IS_CLANG)
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
    add_definitions("-Wno-deprecated-declarations")
  endif ()
endif ()

################################################################################
# Visual Studio
################################################################################

if (MSVC)
  add_definitions("-D_CRT_SECURE_NO_WARNINGS=1")
  add_definitions("-DFD_SETSIZE=2048")
  add_definitions("-DUSE_REGEX_STATIC=1")
  add_definitions("-DU_STATIC_IMPLEMENTATION=1")

  foreach (flag_var
	   CMAKE_C_FLAGS
	   CMAKE_C_FLAGS_DEBUG
	   CMAKE_C_FLAGS_RELEASE
	   CMAKE_C_FLAGS_MINSIZEREL
	   CMAKE_C_FLAGS_RELWITHDEBINFO
           CMAKE_CXX_FLAGS
           CMAKE_CXX_FLAGS_DEBUG
           CMAKE_CXX_FLAGS_RELEASE
           CMAKE_CXX_FLAGS_MINSIZEREL
           CMAKE_CXX_FLAGS_RELWITHDEBINFO)
    if (${flag_var} MATCHES "/MD")
      string(REGEX REPLACE "/MDd?" "" ${flag_var} "${${flag_var}}")
    endif ()

    if (flag_var MATCHES "DEBUG")
      set(${flag_var} "${${flag_var}} /MTd")
    else ()
      set(${flag_var} "${${flag_var}} /MT")
    endif ()
  endforeach()

  set(MSVC_LIBS crypt32.lib;WINMM.LIB;Ws2_32.lib;getopt;regex)

  set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SUBSYSTEM:CONSOLE /LTCG /SAFESEH:NO /ignore:4099")
endif ()

include (TargetArch)
target_architecture(CMAKE_TARGET_ARCHITECTURES)
list(LENGTH CMAKE_TARGET_ARCHITECTURES cmake_target_arch_len)
if (NOT "${cmake_target_arch_len}" STREQUAL "1")
  set(CMAKE_TARGET_ARCHITECTURE_UNIVERSAL TRUE)
  set(CMAKE_TARGET_ARCHITECTURE_CODE "universal")
else ()
  set(CMAKE_TARGET_ARCHITECTURE_UNIVERSAL FALSE)
  set(CMAKE_TARGET_ARCHITECTURE_CODE "${CMAKE_TARGET_ARCHITECTURES}")
endif ()

include (VcMacros)
include (OptimizeForArchitecture)
OptimizeForArchitecture()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Vc_ARCHITECTURE_FLAGS}")

# GO ---------------------------------------------------------------------------
find_package(Go 1.2)
if (NOT GO_FOUND)
  message ("Go version >=1.2 not found. etcd will not be built.")
endif ()

# Enable Backtrace -------------------------------------------------------------
option(USE_BACKTRACE "whether we should try to generate c-level stacktraces"
  OFF)
if (USE_BACKTRACE)
  if (MSVC)
    set(BT_LIBS "Dbghelp" CACHE path "Debug Helper libraries")
  else ()
    set(BT_LIBS "" CACHE path "Debug Helper libraries")
  endif ()
  add_definitions("-DHAVE_BACKTRACE=1")
else ()
  set(BT_LIBS "" CACHE path "Debug Helper libraries")
endif ()

# Maintainer mode (Assertions) -------------------------------------------------
option(USE_MAINTAINER_MODE
  "whether we want to have assertions and other development features" OFF)
if (USE_MAINTAINER_MODE)
  add_definitions("-DTRI_ENABLE_MAINTAINER_MODE=1")
endif ()

# Maintainer mode (Failure Tests) ----------------------------------------------
option(USE_FAILURE_TESTS
  "whether we want to have failure tests compiled in" OFF)
if (USE_FAILURE_TESTS)
  add_definitions("-DTRI_ENABLE_FAILURE_TESTS=1")
endif ()

# Enable relative paths to binaries --------------------------------------------
option(USE_RELATIVE "Do you want to have all path are relative to the binary" OFF)

if (USE_RELATIVE)
  # /etc -------------------------------
  set(ETCDIR_NATIVE "./etc/relative")
  set(ETCDIR_INSTALL "etc/relative")
  # etcd -------------------------------
  file(TO_NATIVE_PATH "${ETCDIR_NATIVE}" ETCDIR_NATIVE)
  STRING(REGEX REPLACE "\\\\" "\\\\\\\\" ETCDIR_ESCAPED
    "${ETCDIR_NATIVE}")
  # /var -------------------------------
  set(VARDIR "" CACHE path
    "System configuration directory (defaults to prefix/var/arangodb)")
  if (VARDIR STREQUAL "")
    set(VARDIR_NATIVE "${CMAKE_INSTALL_PREFIX}/var")
    set(VARDIR_INSTALL "var")
  else ()
    set(VARDIR_NATIVE "${VARDIR}")
    set(VARDIR_INSTALL "${VARDIR}")
  endif ()
  file(TO_NATIVE_PATH "${VARDIR_NATIVE}" VARDIR_NATIVE)
  # arango directories -----------------
  # database
  FILE(MAKE_DIRECTORY "${PROJECT_BINARY_DIR}/var/lib/arangodb")
  # apps
  FILE(MAKE_DIRECTORY "${PROJECT_BINARY_DIR}/var/lib/arangodb-apps")
  # logs
  FILE(MAKE_DIRECTORY "${PROJECT_BINARY_DIR}/var/log/arangodb")
  # tri_package
  set(TRI_PKGDATADIR "${CMAKE_INSTALL_PREFIX}/share/arangodb")
  # resources
  set(TRI_RESOURCEDIR "resources")
  # bin dir ----------------------------
  set(TRI_BINDIR_INSTALL "bin")
  set(TRI_BINDIR "${CMAKE_INSTALL_PREFIX}/bin")
  # MS stuff ---------------------------
  if (MSVC)
    set(TRI_SBINDIR_INSTALL "bin")
    set(TRI_SBINDIR "${CMAKE_INSTALL_PREFIX}/bin")
  else ()
    set(TRI_SBINDIR_INSTALL "sbin")
    set(TRI_SBINDIR "${CMAKE_INSTALL_PREFIX}/sbin")
  endif ()
  add_definitions("-D_SYSCONFDIR_=\"${ETCDIR_ESCAPED}\"")
else () 
  # etcd -------------------------------
  set(ETCDIR "" CACHE path "System configuration directory (defaults to prefix/etc)")
  # /etc -------------------------------
  if (ETCDIR STREQUAL "")
    set(ETCDIR_NATIVE "${CMAKE_INSTALL_PREFIX}/etc/arangodb")
    set(ETCDIR_INSTALL "etc/arangodb")
  else ()
    set(ETCDIR_NATIVE "${ETCDIR}/arangodb")
    set(ETCDIR_INSTALL "${ETCDIR}/arangodb")
  endif ()
  # MS stuff ---------------------------
  if (MSVC)
    file(TO_NATIVE_PATH "${ETCDIR_INSTALL}" ETCDIR_INSTALL)
    STRING(REGEX REPLACE "\\\\" "\\\\\\\\" ETCDIR_ESCAPED "${ETCDIR_INSTALL}")
  else ()
    file(TO_NATIVE_PATH "${ETCDIR_NATIVE}" ETCDIR_NATIVE)
    STRING(REGEX REPLACE "\\\\" "\\\\\\\\" ETCDIR_ESCAPED "${ETCDIR_NATIVE}")
  endif ()
  
  add_definitions("-D_SYSCONFDIR_=\"${ETCDIR_ESCAPED}\"")
  # arango directories -----------------
  # /var
  set(VARDIR "" CACHE path "System configuration directory (defaults to prefix/var/arangodb)")
  if (VARDIR STREQUAL "")
    set(VARDIR_NATIVE "${CMAKE_INSTALL_PREFIX}/var")
    set(VARDIR_INSTALL "var")
  else ()
    set(VARDIR_NATIVE "${VARDIR}")
    set(VARDIR_INSTALL "${VARDIR}")
  endif ()
  file(TO_NATIVE_PATH "${VARDIR_NATIVE}" VARDIR_NATIVE)
  # database directory 
  FILE(MAKE_DIRECTORY "${PROJECT_BINARY_DIR}/var/lib/arangodb")
  # apps
  FILE(MAKE_DIRECTORY "${PROJECT_BINARY_DIR}/var/lib/arangodb-apps")
  # logs
  FILE(MAKE_DIRECTORY "${PROJECT_BINARY_DIR}/var/log/arangodb")
  # package
  set(TRI_PKGDATADIR "${CMAKE_INSTALL_PREFIX}/share/arangodb")
  # resources
  set(TRI_RESOURCEDIR "resources")
  # binaries
  if (MSVC)
    set(TRI_BINDIR_INSTALL "bin")
    set(TRI_BINDIR "${CMAKE_INSTALL_PREFIX}/bin")
  else ()
    set(TRI_BINDIR_INSTALL "bin")
    set(TRI_BINDIR "${CMAKE_INSTALL_PREFIX}/bin")
  endif ()
  # sbinaries
  if (MSVC)
    set(TRI_SBINDIR_INSTALL "bin")
    set(TRI_SBINDIR "${CMAKE_INSTALL_PREFIX}/bin")
  else ()
    set(TRI_SBINDIR_INSTALL "sbin")
    set(TRI_SBINDIR "${CMAKE_INSTALL_PREFIX}/sbin")
  endif ()
endif (USE_RELATIVE)

# MS Windows -------------------------------------------------------------------
if (MSVC)
  # icon paths 
  file(TO_NATIVE_PATH "${TRI_RESOURCEDIR}/Icons/arangodb.ico"
    RELATIVE_ARANGO_ICON) 
  file(TO_NATIVE_PATH
    "${PROJECT_SOURCE_DIR}/Installation/Windows/Icons/arangodb.bmp"
    ARANGO_IMG) 
  file(TO_NATIVE_PATH
    "${PROJECT_SOURCE_DIR}/Installation/Windows/Icons/arangodb.ico"
    ARANGO_ICON) 
  STRING(REGEX REPLACE "\\\\" "\\\\\\\\" ARANGO_IMG "${ARANGO_IMG}")
  STRING(REGEX REPLACE "\\\\" "\\\\\\\\" ARANGO_ICON "${ARANGO_ICON}")
  STRING(REGEX REPLACE "\\\\" "\\\\\\\\" RELATIVE_ARANGO_ICON
    "${RELATIVE_ARANGO_ICON}") 
  # versioning
  set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH}
    ${PROJECT_SOURCE_DIR}/Installation/Windows/version) 
  include("${PROJECT_SOURCE_DIR}/Installation/Windows/version/generate_product_version.cmake")
endif ()

# etcd -------------------------------------------------------------------------
if (DARWIN)
  install(PROGRAMS ${PROJECT_SOURCE_DIR}/bin/etcd-arango DESTINATION
    ${TRI_BINDIR_INSTALL}) 
endif ()

# Global include directories ---------------------------------------------------
include_directories(${PROJECT_SOURCE_DIR})
include_directories(${PROJECT_BINARY_DIR}/lib)
if (CUSTOM_INCLUDES)
  include_directories(${CUSTOM_INCLUDES})
endif ()

# Libraries --------------------------------------------------------------------
option(USE_PRECOMPILED_V8
  "whether we want to use a precompiled V8" OFF)

# 3rd party libraries
add_subdirectory(3rdParty)

# Global macros ----------------------------------------------------------------
macro (generate_root_config name)
  FILE(READ ${PROJECT_SOURCE_DIR}/etc/arangodb/${name}.conf.in FileContent)
  STRING(REPLACE "@PKGDATADIR@" "@ROOTDIR@/share/arangodb"
    FileContent "${FileContent}") 
  STRING(REPLACE "@LOCALSTATEDIR@" "@ROOTDIR@/var"
    FileContent "${FileContent}")
  STRING(REPLACE "@SBINDIR@" "@ROOTDIR@/bin"
    FileContent "${FileContent}")
  STRING(REPLACE "@LIBEXECDIR@/arangodb" "@ROOTDIR@/bin"
    FileContent "${FileContent}")
  STRING(REPLACE "@SYSCONFDIR@" "@ROOTDIR@/etc/arangodb"
    FileContent "${FileContent}")
  if (MSVC)
    STRING(REPLACE "@PROGRAM_SUFFIX@" ".exe"
      FileContent "${FileContent}")
    STRING(REGEX REPLACE "[\r\n]file =" "\n# file =" 
      FileContent "${FileContent}")
  endif ()
  FILE(WRITE ${PROJECT_BINARY_DIR}/etc/arangodb/${name}.conf "${FileContent}")
endmacro ()

#  generates config file using the configured paths ----------------------------
macro (generate_path_config name)
  FILE(READ ${PROJECT_SOURCE_DIR}/etc/arangodb/${name}.conf.in FileContent)
  STRING(REPLACE "@PKGDATADIR@" "${TRI_PKGDATADIR}" 
    FileContent "${FileContent}")
  STRING(REPLACE "@LOCALSTATEDIR@" "${VARDIR_NATIVE}" 
    FileContent "${FileContent}")
  if ((${name} STREQUAL "arangod") AND RASPBIAN)
    STRING(REGEX REPLACE "[\r\n]threads =[^\r\n]*" "\nthreads = 1" 
      FileContent "${FileContent}")
    STRING(REGEX REPLACE "[\r\n]v8-contexts =[^\r\n]*" "\n8-contexts = 1" 
      FileContent "${FileContent}")
  endif ()
  FILE(WRITE ${PROJECT_BINARY_DIR}/etc/arangodb/${name}.conf "${FileContent}")
endmacro ()

# installs a config file -------------------------------------------------------
macro (install_config name)
  if (MSVC OR DARWIN)
    generate_root_config(${name})
  else ()
    generate_path_config(${name})
  endif ()
  install(
    FILES ${PROJECT_BINARY_DIR}/etc/arangodb/${name}.conf
    DESTINATION ${ETCDIR_INSTALL})
endmacro ()

# installs a readme file converting EOL ----------------------------------------
macro (install_readme input where output)
  FILE(READ ${PROJECT_SOURCE_DIR}/${input} FileContent)
  STRING(REPLACE "\r" "" FileContent "${FileContent}")
  if (MSVC)
    STRING(REPLACE "\n" "\r\n" FileContent "${FileContent}")
  endif ()
  FILE(WRITE ${PROJECT_BINARY_DIR}/${output} "${FileContent}")
  install(
    FILES ${PROJECT_BINARY_DIR}/${output}
    DESTINATION ${where})
endmacro ()

# installs a link to an executable ---------------------------------------------
macro (install_command_alias name where alias)
  if (MSVC)
    add_custom_command(
      TARGET ${name}
      POST_BUILD
      COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:${name}>
	      ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${alias}.exe)
    install(
      PROGRAMS ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${alias}.exe
      DESTINATION ${where})
  else ()
    add_custom_command(
      TARGET ${name}
      POST_BUILD
      COMMAND ${CMAKE_COMMAND} -E create_symlink ${name}
        ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${alias}) 
    install(
      PROGRAMS ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${alias}
      DESTINATION ${where})
  endif ()
endmacro ()

# Threads libraries -------------------------------------------------------------
find_package(Threads)

# Windows libraries -------------------------------------------------------------
if (MSVC)
  set(MSVC_INCLUDE
    ${PROJECT_SOURCE_DIR}/WindowsLibraries/${BITS}/include
    CACHE path "MSVC 3rd party include path") 
  set(MSVC_LIB_PATH ${PROJECT_SOURCE_DIR}/WindowsLibraries/${BITS}/lib
    CACHE path "MSVC 3rd party library path") 
endif ()
if (MSVC_INCLUDE)
  include_directories(${MSVC_INCLUDE})
endif ()
if (MSVC_LIB_PATH)
  link_directories(${MSVC_LIB_PATH})
endif ()


#--------------------------------------------------------------------------------
#get_cmake_property(_variableNames VARIABLES)
#foreach (_variableName ${_variableNames})
#    message(STATUS "${_variableName}=${${_variableName}}")
#endforeach ()
#--------------------------------------------------------------------------------

# ICU ---------------------------------------------------------------------------
if (MSVC)
  set(ICU_LIBS "icui18n;icuuc" CACHE path "ICU libraries")
  
  add_definitions("-DU_STATIC_IMPLEMENTATION=1")
elseif (RASPBIAN)
  set(ICU_LIBS icui18n;icuuc;icudata;pthread;dl;m CACHE path "ICU libraries")
else ()
  set(ICU_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/3rdParty/V8-${V8_VERSION}/third_party/icu/source/common;${PROJECT_SOURCE_DIR}/3rdParty/V8-${V8_VERSION}/third_party/icu/source/i18n;${PROJECT_SOURCE_DIR}/3rdParty/V8-${V8_VERSION}/third_party/icu/source/io CACHE path "ICU include path")
  set(ICU_LIB_PATH ${ICU_BIN_DIR} CACHE path "ICU library path")
  if (LINUX)
    set(ICU_LIB_PATH "${ICU_LIB_PATH}/obj.target/third_party/icu")
  endif ()
  set(ICU_LIBS icui18n;icuuc;icudata;pthread;dl;m CACHE path "ICU libraries")
endif ()

if (ICU_INCLUDE_DIR)
  include_directories(${ICU_INCLUDE_DIR})
endif ()

if (ICU_LIB_PATH)
  link_directories(${ICU_LIB_PATH})
endif ()
<commit_msg>Remove directory part that comes from the variable.<commit_after># ------------------------------------------------------------------------------
# General
# ------------------------------------------------------------------------------

cmake_minimum_required(VERSION 2.8)

if (APPLE)
  if (NOT DEFINED CMAKE_C_COMPILER)
    set(CMAKE_C_COMPILER /usr/bin/clang)
  endif ()
  
  if (NOT DEFINED CMAKE_CXX_COMPILER)
    set(CMAKE_CXX_COMPILER /usr/bin/clang++)
  endif ()
endif ()

project(ArangoDB)

if (POLICY CMP0037)
  cmake_policy(SET CMP0037 NEW)
endif ()


set(ARANGODB_DISPLAY_NAME       "ArangoDB")
set(ARANGODB_URL_INFO_ABOUT     "http://www.arangodb.org")
set(ARANGODB_CONTACT            "<EMAIL>")

set(ARANGODB_VERSION_MAJOR      "3")
set(ARANGODB_VERSION_MINOR      "0")
set(ARANGODB_VERSION_REVISION   "0-devel")

set(ARANGODB_VERSION
    "${ARANGODB_VERSION_MAJOR}.${ARANGODB_VERSION_MINOR}.${ARANGODB_VERSION_REVISION}")

configure_file (
  "${CMAKE_CURRENT_SOURCE_DIR}/lib/Basics/build.h.in"
  "${CMAKE_CURRENT_BINARY_DIR}/lib/Basics/build.h")

configure_file (
  "${CMAKE_CURRENT_SOURCE_DIR}/lib/Basics/VERSION.in"
  "${CMAKE_CURRENT_SOURCE_DIR}/VERSION")

set(ARANGODB_FRIENDLY_STRING    "ArangoDB - the multi-model database")
set(ARANGOB_FRIENDLY_STRING     "ArangoBench - stresstester")
set(ARANGO_DUMP_FRIENDLY_STRING
  "arangodump - export whole databases from ArangoDB to JSON") 
set(ARANGO_IMP_FRIENDLY_STRING  "arangoimp - import CSV files into ArangoDB")
set(ARANGO_RESTORE_HELP_LINK
  "arangrestore - import dumpfiles created with arangodump into ArangoDB")
set(ARANGOSH_HELP_LINK          "arangosh - commandline client of ArangoDB")

if (NOT CMAKE_BUILD_TYPE)
  set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE string
    "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel."
    FORCE)
endif ()

# Where 2 find CMAKE modules
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake)

# ArangoDB needs c++11
set(CMAKE_CXX_STANDARD 11)
include (CheckCXX11Features)

# Need threads
find_package(Threads REQUIRED)

option(AR_USE_SYSTEM_LIBS "use libraries provided by the system" OFF)

# Object archives
set(LIB_ARANGO        arango)
set(LIB_ARANGO_CLIENT arango_client)
set(LIB_ARANGO_V8     arango_v8)

# Binaries
set(BIN_ARANGOB       arangob)
set(BIN_ARANGOD       arangod)
set(BIN_ARANGODUMP    arangodump)
set(BIN_ARANGOIMP     arangoimp)
set(BIN_ARANGORESTORE arangorestore)
set(BIN_ARANGOSH      arangosh)

# Google V8 engine including ICU
set(V8_VERSION        4.3.61)

message(STATUS ${CMAKE_SYSTEM_TYPE})

# Architecture
math(EXPR BITS "8*${CMAKE_SIZEOF_VOID_P}")
add_definitions("-DTRI_BITS=${BITS}")

set(MAKE make)
set(USE_TCMALLOC, TRUE)
set(THIRDP_BUILDFLAGS "CC=${CMAKE_C_COMPILER}")
set(HOST_BITS ${BITS})
# OS type (Convenience) --------------------------------------------------------
if(WIN32)
  if(NOT WINDOWS)
    set(USE_TCMALLOC, FALSE)
    set(WINDOWS TRUE)
  endif()
elseif(UNIX AND NOT APPLE)
  if(CMAKE_SYSTEM_NAME MATCHES ".*Linux")
    set(LINUX TRUE)
  elseif (CMAKE_SYSTEM_NAME MATCHES "kFreeBSD.*")
    set(FREEBSD TRUE)
  elseif (CMAKE_SYSTEM_NAME MATCHES "kNetBSD.*|NetBSD.*")
    set(NETBSD TRUE)
  elseif (CMAKE_SYSTEM_NAME MATCHES "kOpenBSD.*|OpenBSD.*")
    set(OPENBSD TRUE)
  elseif (CMAKE_SYSTEM_NAME MATCHES ".*GNU.*")
    set(GNU TRUE)
  elseif (CMAKE_SYSTEM_NAME MATCHES ".*BSDI.*")
    set(BSDI TRUE)
  elseif (CMAKE_SYSTEM_NAME MATCHES "DragonFly.*|FreeBSD")
    set(FREEBSD TRUE)
  elseif (CMAKE_SYSTEM_NAME MATCHES "SYSV5.*")
    set(SYSV5 TRUE)
  elseif ((CMAKE_SYSTEM_NAME MATCHES "Solaris.*") OR (CMAKE_SYSTEM_NAME MATCHES "SunOS.*"))
    set(USE_TCMALLOC, FALSE)
    set(CMAKE_CXX_SIZEOF_DATA_PTR 8)
    set(CMAKE_SIZEOF_VOID_P 8)
    set(BITS 64)
    set(CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES /lib;/lib64;/lib64;/usr/lib;/usr/lib64;/usr/lib64)
    set(MAKE gmake)
    set(HOST_BITS 64)
    set(SOLARIS TRUE)
    list(APPEND CMAKE_C_FLAGS -I\ /opt/csw/include\ -D_REENTRANT\ -m64)
    list(APPEND CMAKE_CXX_FLAGS -I\ /opt/csw/include\ -D_REENTRANT\ -m64)
    set(THIRDP_BUILDFLAGS --target=x86_64-pc-solaris2.11
      --host=x86_64-pc-solaris2.11
      --build=x86_64-pc-solaris2.11
      # TODO: is this CMAKE_C_COMPILER? CC=/opt/csw/bin/gcc
      CC=/opt/csw/bin/gcc
      CXX=/opt/csw/bin/g++
      CFLAGS=-I\ /opt/csw/include\ -D_REENTRANT\ -m64
      CXXFLAGS=-I\ /opt/csw/include\ -D_REENTRANT\ -m64
      LDFLAGS=-L/opt/csw/lib\ -march=x86-64\ -m64
      )
   elseif (CMAKE_SYSTEM_NAME MATCHES "HP-UX.*")
    set(HPUX TRUE)
  elseif (CMAKE_SYSTEM_NAME MATCHES "AIX.*")
    set(AIX TRUE)
  elseif (CMAKE_SYSTEM_NAME MATCHES "Minix.*")
    set(MINIX TRUE)
  endif ()
elseif (APPLE)
  if (CMAKE_SYSTEM_NAME MATCHES ".*Darwin.*")
    set(DARWIN TRUE)
  elseif (CMAKE_SYSTEM_NAME MATCHES ".*MacOS.*")
    set(MACOSX TRUE)
  endif ()
endif ()

# TODO: Exclude non-supported?

# BISON&FLEX -------------------------------------------------------------------
find_package (BISON)

# FLEX -------------------------------------------------------------------------
find_package (FLEX)

# GO ---------------------------------------------------------------------------
find_package(Go 1.2)

# Python
find_package(PythonInterp 2)
set(ENV{PYTHON_EXECUTABLE} ${PYTHON_EXECUTABLE})

## Compiler flags --------------------------------------------------------------

################################################################################
# BUILD TYPES
################################################################################

string(TOLOWER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_TL)
message (${CMAKE_BUILD_TYPE_TL})
set(DEBUG FALSE)
if (CMAKE_BUILD_TYPE_TL MATCHES debug)
  set(DEBUG TRUE)
  set(WIN_RELEASE_TYPE Debug)
  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0 -g")
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0 -g")
elseif (CMAKE_BUILD_TYPE_TL MATCHES relwithdebinfo)
  set(WIN_RELEASE_TYPE RelWithDebInfo)
  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O2 -g")
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -g")
elseif (CMAKE_BUILD_TYPE_TL MATCHES release)
  set(WIN_RELEASE_TYPE Release)
  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3")
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
endif () 

################################################################################
# GCC 
################################################################################

if (CMAKE_COMPILER_IS_GNUCC)
  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu89")
  set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}")
endif ()
if (CMAKE_COMPILER_IS_GNUCXX)
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
endif ()

################################################################################
# OTHER COMPILERS
################################################################################

if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  set(CMAKE_COMPILER_IS_CLANG 1)
elseif (CMAKE_CXX_COMPILER_ID MATCHES "AppleClang")
  set(CMAKE_COMPILER_IS_CLANG 1)
elseif (CMAKE_CXX_COMPILER_ID MATCHES "Intel")
  set(CMAKE_COMPILER_IS_INTEL 1)
elseif (CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
  set(CMAKE_COMPILER_IS_INTEL 1)
endif ()

################################################################################
# OSX
################################################################################

if (APPLE)
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

  if (CMAKE_COMPILER_IS_CLANG)
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
    add_definitions("-Wno-deprecated-declarations")
  endif ()
endif ()

################################################################################
# Visual Studio
################################################################################

if (MSVC)
  add_definitions("-D_CRT_SECURE_NO_WARNINGS=1")
  add_definitions("-DFD_SETSIZE=2048")
  add_definitions("-DUSE_REGEX_STATIC=1")
  add_definitions("-DU_STATIC_IMPLEMENTATION=1")

  foreach (flag_var
	   CMAKE_C_FLAGS
	   CMAKE_C_FLAGS_DEBUG
	   CMAKE_C_FLAGS_RELEASE
	   CMAKE_C_FLAGS_MINSIZEREL
	   CMAKE_C_FLAGS_RELWITHDEBINFO
           CMAKE_CXX_FLAGS
           CMAKE_CXX_FLAGS_DEBUG
           CMAKE_CXX_FLAGS_RELEASE
           CMAKE_CXX_FLAGS_MINSIZEREL
           CMAKE_CXX_FLAGS_RELWITHDEBINFO)
    if (${flag_var} MATCHES "/MD")
      string(REGEX REPLACE "/MDd?" "" ${flag_var} "${${flag_var}}")
    endif ()

    if (flag_var MATCHES "DEBUG")
      set(${flag_var} "${${flag_var}} /MTd")
    else ()
      set(${flag_var} "${${flag_var}} /MT")
    endif ()
  endforeach()

  set(MSVC_LIBS crypt32.lib;WINMM.LIB;Ws2_32.lib;getopt;regex)

  set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SUBSYSTEM:CONSOLE /LTCG /SAFESEH:NO /ignore:4099")
endif ()

include (TargetArch)
target_architecture(CMAKE_TARGET_ARCHITECTURES)
list(LENGTH CMAKE_TARGET_ARCHITECTURES cmake_target_arch_len)
if (NOT "${cmake_target_arch_len}" STREQUAL "1")
  set(CMAKE_TARGET_ARCHITECTURE_UNIVERSAL TRUE)
  set(CMAKE_TARGET_ARCHITECTURE_CODE "universal")
else ()
  set(CMAKE_TARGET_ARCHITECTURE_UNIVERSAL FALSE)
  set(CMAKE_TARGET_ARCHITECTURE_CODE "${CMAKE_TARGET_ARCHITECTURES}")
endif ()

include (VcMacros)
include (OptimizeForArchitecture)
OptimizeForArchitecture()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Vc_ARCHITECTURE_FLAGS}")

# GO ---------------------------------------------------------------------------
find_package(Go 1.2)
if (NOT GO_FOUND)
  message ("Go version >=1.2 not found. etcd will not be built.")
endif ()

# Enable Backtrace -------------------------------------------------------------
option(USE_BACKTRACE "whether we should try to generate c-level stacktraces"
  OFF)
if (USE_BACKTRACE)
  if (MSVC)
    set(BT_LIBS "Dbghelp" CACHE path "Debug Helper libraries")
  else ()
    set(BT_LIBS "" CACHE path "Debug Helper libraries")
  endif ()
  add_definitions("-DHAVE_BACKTRACE=1")
else ()
  set(BT_LIBS "" CACHE path "Debug Helper libraries")
endif ()

# Maintainer mode (Assertions) -------------------------------------------------
option(USE_MAINTAINER_MODE
  "whether we want to have assertions and other development features" OFF)
if (USE_MAINTAINER_MODE)
  add_definitions("-DTRI_ENABLE_MAINTAINER_MODE=1")
endif ()

# Maintainer mode (Failure Tests) ----------------------------------------------
option(USE_FAILURE_TESTS
  "whether we want to have failure tests compiled in" OFF)
if (USE_FAILURE_TESTS)
  add_definitions("-DTRI_ENABLE_FAILURE_TESTS=1")
endif ()

# Enable relative paths to binaries --------------------------------------------
option(USE_RELATIVE "Do you want to have all path are relative to the binary" OFF)

if (USE_RELATIVE)
  # /etc -------------------------------
  set(ETCDIR_NATIVE "./etc/relative")
  set(ETCDIR_INSTALL "etc/relative")
  # etcd -------------------------------
  file(TO_NATIVE_PATH "${ETCDIR_NATIVE}" ETCDIR_NATIVE)
  STRING(REGEX REPLACE "\\\\" "\\\\\\\\" ETCDIR_ESCAPED
    "${ETCDIR_NATIVE}")
  # /var -------------------------------
  set(VARDIR "" CACHE path
    "System configuration directory (defaults to prefix/var/arangodb)")
  if (VARDIR STREQUAL "")
    set(VARDIR_NATIVE "${CMAKE_INSTALL_PREFIX}/var")
    set(VARDIR_INSTALL "var")
  else ()
    set(VARDIR_NATIVE "${VARDIR}")
    set(VARDIR_INSTALL "${VARDIR}")
  endif ()
  file(TO_NATIVE_PATH "${VARDIR_NATIVE}" VARDIR_NATIVE)
  # arango directories -----------------
  # database
  FILE(MAKE_DIRECTORY "${PROJECT_BINARY_DIR}/var/lib/arangodb")
  # apps
  FILE(MAKE_DIRECTORY "${PROJECT_BINARY_DIR}/var/lib/arangodb-apps")
  # logs
  FILE(MAKE_DIRECTORY "${PROJECT_BINARY_DIR}/var/log/arangodb")
  # tri_package
  set(TRI_PKGDATADIR "${CMAKE_INSTALL_PREFIX}/share/arangodb")
  # resources
  set(TRI_RESOURCEDIR "resources")
  # bin dir ----------------------------
  set(TRI_BINDIR_INSTALL "bin")
  set(TRI_BINDIR "${CMAKE_INSTALL_PREFIX}/bin")
  # MS stuff ---------------------------
  if (MSVC)
    set(TRI_SBINDIR_INSTALL "bin")
    set(TRI_SBINDIR "${CMAKE_INSTALL_PREFIX}/bin")
  else ()
    set(TRI_SBINDIR_INSTALL "sbin")
    set(TRI_SBINDIR "${CMAKE_INSTALL_PREFIX}/sbin")
  endif ()
  add_definitions("-D_SYSCONFDIR_=\"${ETCDIR_ESCAPED}\"")
else () 
  # etcd -------------------------------
  set(ETCDIR "" CACHE path "System configuration directory (defaults to prefix/etc)")
  # /etc -------------------------------
  if (ETCDIR STREQUAL "")
    set(ETCDIR_NATIVE "${CMAKE_INSTALL_PREFIX}/etc/arangodb")
    set(ETCDIR_INSTALL "etc/arangodb")
  else ()
    set(ETCDIR_NATIVE "${ETCDIR}/arangodb")
    set(ETCDIR_INSTALL "${ETCDIR}/arangodb")
  endif ()
  # MS stuff ---------------------------
  if (MSVC)
    file(TO_NATIVE_PATH "${ETCDIR_INSTALL}" ETCDIR_INSTALL)
    STRING(REGEX REPLACE "\\\\" "\\\\\\\\" ETCDIR_ESCAPED "${ETCDIR_INSTALL}")
  else ()
    file(TO_NATIVE_PATH "${ETCDIR_NATIVE}" ETCDIR_NATIVE)
    STRING(REGEX REPLACE "\\\\" "\\\\\\\\" ETCDIR_ESCAPED "${ETCDIR_NATIVE}")
  endif ()
  
  add_definitions("-D_SYSCONFDIR_=\"${ETCDIR_ESCAPED}\"")
  # arango directories -----------------
  # /var
  set(VARDIR "" CACHE path "System configuration directory (defaults to prefix/var/arangodb)")
  if (VARDIR STREQUAL "")
    set(VARDIR_NATIVE "${CMAKE_INSTALL_PREFIX}/var")
    set(VARDIR_INSTALL "var")
  else ()
    set(VARDIR_NATIVE "${VARDIR}")
    set(VARDIR_INSTALL "${VARDIR}")
  endif ()
  file(TO_NATIVE_PATH "${VARDIR_NATIVE}" VARDIR_NATIVE)
  # database directory 
  FILE(MAKE_DIRECTORY "${PROJECT_BINARY_DIR}/var/lib/arangodb")
  # apps
  FILE(MAKE_DIRECTORY "${PROJECT_BINARY_DIR}/var/lib/arangodb-apps")
  # logs
  FILE(MAKE_DIRECTORY "${PROJECT_BINARY_DIR}/var/log/arangodb")
  # package
  set(TRI_PKGDATADIR "${CMAKE_INSTALL_PREFIX}/share/arangodb")
  # resources
  set(TRI_RESOURCEDIR "resources")
  # binaries
  if (MSVC)
    set(TRI_BINDIR_INSTALL "bin")
    set(TRI_BINDIR "${CMAKE_INSTALL_PREFIX}/bin")
  else ()
    set(TRI_BINDIR_INSTALL "bin")
    set(TRI_BINDIR "${CMAKE_INSTALL_PREFIX}/bin")
  endif ()
  # sbinaries
  if (MSVC)
    set(TRI_SBINDIR_INSTALL "bin")
    set(TRI_SBINDIR "${CMAKE_INSTALL_PREFIX}/bin")
  else ()
    set(TRI_SBINDIR_INSTALL "sbin")
    set(TRI_SBINDIR "${CMAKE_INSTALL_PREFIX}/sbin")
  endif ()
endif (USE_RELATIVE)

# MS Windows -------------------------------------------------------------------
if (MSVC)
  # icon paths 
  file(TO_NATIVE_PATH "${TRI_RESOURCEDIR}/Icons/arangodb.ico"
    RELATIVE_ARANGO_ICON) 
  file(TO_NATIVE_PATH
    "${PROJECT_SOURCE_DIR}/Installation/Windows/Icons/arangodb.bmp"
    ARANGO_IMG) 
  file(TO_NATIVE_PATH
    "${PROJECT_SOURCE_DIR}/Installation/Windows/Icons/arangodb.ico"
    ARANGO_ICON) 
  STRING(REGEX REPLACE "\\\\" "\\\\\\\\" ARANGO_IMG "${ARANGO_IMG}")
  STRING(REGEX REPLACE "\\\\" "\\\\\\\\" ARANGO_ICON "${ARANGO_ICON}")
  STRING(REGEX REPLACE "\\\\" "\\\\\\\\" RELATIVE_ARANGO_ICON
    "${RELATIVE_ARANGO_ICON}") 
  # versioning
  set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH}
    ${PROJECT_SOURCE_DIR}/Installation/Windows/version) 
  include("${PROJECT_SOURCE_DIR}/Installation/Windows/version/generate_product_version.cmake")
endif ()

# etcd -------------------------------------------------------------------------
if (DARWIN)
  install(PROGRAMS ${PROJECT_SOURCE_DIR}/bin/etcd-arango DESTINATION
    ${TRI_BINDIR_INSTALL}) 
endif ()

# Global include directories ---------------------------------------------------
include_directories(${PROJECT_SOURCE_DIR})
include_directories(${PROJECT_BINARY_DIR}/lib)
if (CUSTOM_INCLUDES)
  include_directories(${CUSTOM_INCLUDES})
endif ()

# Libraries --------------------------------------------------------------------
option(USE_PRECOMPILED_V8
  "whether we want to use a precompiled V8" OFF)

# 3rd party libraries
add_subdirectory(3rdParty)

# Global macros ----------------------------------------------------------------
macro (generate_root_config name)
  FILE(READ ${PROJECT_SOURCE_DIR}/etc/arangodb/${name}.conf.in FileContent)
  STRING(REPLACE "@PKGDATADIR@" "@ROOTDIR@/share/arangodb"
    FileContent "${FileContent}") 
  STRING(REPLACE "@LOCALSTATEDIR@" "@ROOTDIR@/var"
    FileContent "${FileContent}")
  STRING(REPLACE "@SBINDIR@" "@ROOTDIR@/bin"
    FileContent "${FileContent}")
  STRING(REPLACE "@LIBEXECDIR@/arangodb" "@ROOTDIR@/bin"
    FileContent "${FileContent}")
  STRING(REPLACE "@SYSCONFDIR@" "@ROOTDIR@/etc/arangodb"
    FileContent "${FileContent}")
  if (MSVC)
    STRING(REPLACE "@PROGRAM_SUFFIX@" ".exe"
      FileContent "${FileContent}")
    STRING(REGEX REPLACE "[\r\n]file =" "\n# file =" 
      FileContent "${FileContent}")
  endif ()
  FILE(WRITE ${PROJECT_BINARY_DIR}/etc/arangodb/${name}.conf "${FileContent}")
endmacro ()

#  generates config file using the configured paths ----------------------------
macro (generate_path_config name)
  FILE(READ ${PROJECT_SOURCE_DIR}/etc/arangodb/${name}.conf.in FileContent)
  STRING(REPLACE "@PKGDATADIR@" "${TRI_PKGDATADIR}" 
    FileContent "${FileContent}")
  STRING(REPLACE "@LOCALSTATEDIR@" "${VARDIR_NATIVE}" 
    FileContent "${FileContent}")
  if ((${name} STREQUAL "arangod") AND RASPBIAN)
    STRING(REGEX REPLACE "[\r\n]threads =[^\r\n]*" "\nthreads = 1" 
      FileContent "${FileContent}")
    STRING(REGEX REPLACE "[\r\n]v8-contexts =[^\r\n]*" "\n8-contexts = 1" 
      FileContent "${FileContent}")
  endif ()
  FILE(WRITE ${PROJECT_BINARY_DIR}/etc/arangodb/${name}.conf "${FileContent}")
endmacro ()

# installs a config file -------------------------------------------------------
macro (install_config name)
  if (MSVC OR DARWIN)
    generate_root_config(${name})
  else ()
    generate_path_config(${name})
  endif ()
  install(
    FILES ${PROJECT_BINARY_DIR}/etc/arangodb/${name}.conf
    DESTINATION ${ETCDIR_INSTALL})
endmacro ()

# installs a readme file converting EOL ----------------------------------------
macro (install_readme input where output)
  FILE(READ ${PROJECT_SOURCE_DIR}/${input} FileContent)
  STRING(REPLACE "\r" "" FileContent "${FileContent}")
  if (MSVC)
    STRING(REPLACE "\n" "\r\n" FileContent "${FileContent}")
  endif ()
  FILE(WRITE ${PROJECT_BINARY_DIR}/${output} "${FileContent}")
  install(
    FILES ${PROJECT_BINARY_DIR}/${output}
    DESTINATION ${where})
endmacro ()

# installs a link to an executable ---------------------------------------------
macro (install_command_alias name where alias)
  if (MSVC)
    add_custom_command(
      TARGET ${name}
      POST_BUILD
      COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:${name}>
	      ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${alias}.exe)
    install(
      PROGRAMS ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${alias}.exe
      DESTINATION ${where})
  else ()
    add_custom_command(
      TARGET ${name}
      POST_BUILD
      COMMAND ${CMAKE_COMMAND} -E create_symlink ${name}
        ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${alias}) 
    install(
      PROGRAMS ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${alias}
      DESTINATION ${where})
  endif ()
endmacro ()

# Threads libraries -------------------------------------------------------------
find_package(Threads)

# Windows libraries -------------------------------------------------------------
if (MSVC)
  set(MSVC_INCLUDE
    ${PROJECT_SOURCE_DIR}/WindowsLibraries/${BITS}/include
    CACHE path "MSVC 3rd party include path") 
  set(MSVC_LIB_PATH ${PROJECT_SOURCE_DIR}/WindowsLibraries/${BITS}/lib
    CACHE path "MSVC 3rd party library path") 
endif ()
if (MSVC_INCLUDE)
  include_directories(${MSVC_INCLUDE})
endif ()
if (MSVC_LIB_PATH)
  link_directories(${MSVC_LIB_PATH})
endif ()


#--------------------------------------------------------------------------------
#get_cmake_property(_variableNames VARIABLES)
#foreach (_variableName ${_variableNames})
#    message(STATUS "${_variableName}=${${_variableName}}")
#endforeach ()
#--------------------------------------------------------------------------------

# ICU ---------------------------------------------------------------------------
if (MSVC)
  set(ICU_LIBS "icui18n;icuuc" CACHE path "ICU libraries")
  
  add_definitions("-DU_STATIC_IMPLEMENTATION=1")
elseif (RASPBIAN)
  set(ICU_LIBS icui18n;icuuc;icudata;pthread;dl;m CACHE path "ICU libraries")
else ()
  set(ICU_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/3rdParty/V8-${V8_VERSION}/third_party/icu/source/common;${PROJECT_SOURCE_DIR}/3rdParty/V8-${V8_VERSION}/third_party/icu/source/i18n;${PROJECT_SOURCE_DIR}/3rdParty/V8-${V8_VERSION}/third_party/icu/source/io CACHE path "ICU include path")
  set(ICU_LIB_PATH ${ICU_BIN_DIR} CACHE path "ICU library path")
  if (LINUX)
    set(ICU_LIB_PATH "${ICU_LIB_PATH}")
  endif ()
  set(ICU_LIBS icui18n;icuuc;icudata;pthread;dl;m CACHE path "ICU libraries")
endif ()

if (ICU_INCLUDE_DIR)
  include_directories(${ICU_INCLUDE_DIR})
endif ()

if (ICU_LIB_PATH)
  link_directories(${ICU_LIB_PATH})
endif ()

{'fraction_non_alphanumeric': 0.24414086070816537, 'fraction_numerical': 0.0073857739373898775, 'mean_word_length': 3.1469322390151135, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2827255', 'n_tokens_mistral': 15299, 'n_tokens_neox': 14299, 'n_words': 2443}