<commit_before># ------------------------------------------------------------------------------
# External Projects used by ArangoDB
# ------------------------------------------------------------------------------

include(ExternalProject)

macro(import_target tname tdep tinclude tpath)
  add_library(${tname} STATIC IMPORTED GLOBAL)
  add_dependencies(${tname} ${tdep})
  set_target_properties(${tname} PROPERTIES
    INTERFACE_INCLUDE_DIRECTORIES "${tinclude}"
    IMPORTED_LOCATION "${tpath}"
  )
endmacro()

################################################################################
## ETCD
################################################################################

if (GO_FOUND)
  if (MSVC)
    set (ETCD_BUILD_COMMAND build.bat)
  else ()
    set (ETCD_BUILD_COMMAND ./build)
  endif ()

  ExternalProject_Add(etcd_build
    SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/etcd
    CONFIGURE_COMMAND ""
    BUILD_IN_SOURCE TRUE
    BUILD_COMMAND "${ETCD_BUILD_COMMAND}"
    INSTALL_COMMAND "cp" ${CMAKE_CURRENT_SOURCE_DIR}/etcd/bin/etcd ${CMAKE_BINARY_DIR}/bin/etcd-arango
  )
endif ()

################################################################################
## ZLIB
################################################################################

add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/zlib/zlib-1.2.8)

################################################################################
## EV
################################################################################

add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/libev)

################################################################################
## V8 and ICU
################################################################################

set(V8_VERSION
  "4.3.61"
  CACHE INTERNAL
  "${PROJECT_NAME}: Version"
  FORCE
)

set(V8_DIR "${CMAKE_CURRENT_SOURCE_DIR}/V8-${V8_VERSION}")
# doesn't work?
set(V8_TARGET_DIR "${CMAKE_CURRENT_BINARY_DIR}/v8")
#set(V8_TARGET_DIR "out")

if ("${HOST_BITS}" STREQUAL "64")
  set(TARGET_ARCH "x64")
else()
  message(ERROR "WHAT THE FUCK!")
  set(TARGET_ARCH "ia32")
endif() # TODO: ARM? Win32?

if(DEBUG)
  list(APPEND V8_GYP_ARGS -Dv8_enable_backtrace=1)
  set(V8_TARGET_ARCH "${TARGET_ARCH}.debug")
else()
  set(V8_TARGET_ARCH "${TARGET_ARCH}.release")
endif()


list(APPEND V8_GYP_ARGS ${V8_DIR}/build/gyp/gyp_main.py --generator-output=${V8_TARGET_DIR} build/all.gyp)

  
if(WIN32)
  # TODO: get this from the main configure paramentrisation
  # CMAKE_BUILD_TYPE:STRING=RelWithDebInfo
  # -G\ msvs_version=2013
  #  -Dtarget_arch=x64
  # -Dmode=release
  list(APPEND V8_GYP_ARGS -Dcomponent=static_library -Dlibrary=static_library)
else()
  # -Dwerror='' breaks shit... rather...   -Dwerror= 
  list(APPEND V8_GYP_ARGS -Ibuild/standalone.gypi --depth=. -Dstandalone_static_library=1  -Dlinux_use_bundled_gold=0 -Dlinux_use_gold_flags=0-Dv8_no_strict_aliasing=1)
endif()


list(APPEND V8_GYP_ARGS -Dv8_target_arch=${TARGET_ARCH} -S.${V8_TARGET_ARCH})

if (UNIX)
  #set(V8_PLATFORM "native")
  set(V8_BIN_DIR "${V8_TARGET_DIR}/${V8_TARGET_ARCH}")
  set(ICU_BIN_DIR "${V8_BIN_DIR}")
  if (${CMAKE_SYSTEM_NAME} MATCHES "Linux" OR (CMAKE_SYSTEM_NAME MATCHES "Solaris.*") OR (CMAKE_SYSTEM_NAME MATCHES "SunOS.*"))
    set(V8_BIN_DIR "${V8_BIN_DIR}/obj.target/tools/gyp")
    set(ICU_BIN_DIR "${ICU_BIN_DIR}/obj.target/third_party/icu")
  endif ()
else ()
  message(ERROR "Not implemented for your OS")
endif ()

set (ICU_BIN_DIR ${ICU_BIN_DIR} PARENT_SCOPE)
set (V8_BIN_DIR ${V8_BIN_DIR} PARENT_SCOPE)


include(ExternalProject)
set (V8_BUILD_COMMAND $(MAKE) -f Makefile-v8 strictaliasing=off
  snapshot=off werror=no "${V8_TARGET_ARCH}" CC="${CMAKE_C_COMPILER}"
  CXX="${CMAKE_CXX_COMPILER}"
  CXXFLAGS=${CMAKE_CXX_FLAGS})
if (APPLE AND CMAKE_COMPILER_IS_CLANG)
  set(V8_BUILD_COMMAND ${V8_BUILD_COMMAND} LDFLAGS=-stdlib=libc++ CXXFLAGS=-stdlib=libc++)
endif ()

set (V8_COMPILE_ARGS -C ${V8_TARGET_DIR} -f Makefile.${V8_TARGET_ARCH} BUILDTYPE=Release builddir=${V8_TARGET_DIR}/${V8_TARGET_ARCH} VERBOSE=1 V=1 CC=${CMAKE_C_COMPILER} CXX=${CMAKE_CXX_COMPILER} PYTHON_EXECUTABLE=${PYTHON_EXECUTABLE})

#set(RUN_V8_GYP "PYTHON_EXECUTABLE=${PYTHON_EXECUTABLE};\ ${PYTHON_EXECUTABLE}")
set(RUN_V8_GYP "${PYTHON_EXECUTABLE}")

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

if (NOT USE_PRECOMPILED_V8)
  ExternalProject_Add(v8_build
    BUILD_IN_SOURCE TRUE
    SOURCE_DIR "${V8_DIR}"
    CONFIGURE_COMMAND ${RUN_V8_GYP} ${V8_GYP_ARGS} --format make
    BUILD_COMMAND ${MAKE} ${V8_COMPILE_ARGS} LDFLAGS=-stdlib=libc++ CXXFLAGS=-stdlib=libc++
    INSTALL_COMMAND "")
endif ()

import_target(v8_base v8_build
  "${V8_DIR}/include"
  "${V8_BIN_DIR}/libv8_base.a"
)

import_target(v8_libbase v8_build
  "${V8_DIR}/include"
  "${V8_BIN_DIR}/libv8_libbase.a"
)

import_target(v8_libplatform v8_build
  "${V8_DIR}/include"
  "${V8_BIN_DIR}/libv8_libplatform.a"
)

import_target(v8_nosnapshot v8_build
  "${V8_DIR}/include"
  "${V8_BIN_DIR}/libv8_nosnapshot.a"
)<commit_msg>Move apple specific cflag modifications into a proper if clause.<commit_after># ------------------------------------------------------------------------------
# External Projects used by ArangoDB
# ------------------------------------------------------------------------------

include(ExternalProject)

macro(import_target tname tdep tinclude tpath)
  add_library(${tname} STATIC IMPORTED GLOBAL)
  add_dependencies(${tname} ${tdep})
  set_target_properties(${tname} PROPERTIES
    INTERFACE_INCLUDE_DIRECTORIES "${tinclude}"
    IMPORTED_LOCATION "${tpath}"
  )
endmacro()

################################################################################
## ETCD
################################################################################

if (GO_FOUND)
  if (MSVC)
    set (ETCD_BUILD_COMMAND build.bat)
  else ()
    set (ETCD_BUILD_COMMAND ./build)
  endif ()

  ExternalProject_Add(etcd_build
    SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/etcd
    CONFIGURE_COMMAND ""
    BUILD_IN_SOURCE TRUE
    BUILD_COMMAND "${ETCD_BUILD_COMMAND}"
    INSTALL_COMMAND "cp" ${CMAKE_CURRENT_SOURCE_DIR}/etcd/bin/etcd ${CMAKE_BINARY_DIR}/bin/etcd-arango
  )
endif ()

################################################################################
## ZLIB
################################################################################

add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/zlib/zlib-1.2.8)

################################################################################
## EV
################################################################################

add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/libev)

################################################################################
## V8 and ICU
################################################################################

set(V8_VERSION
  "4.3.61"
  CACHE INTERNAL
  "${PROJECT_NAME}: Version"
  FORCE
)

set(V8_DIR "${CMAKE_CURRENT_SOURCE_DIR}/V8-${V8_VERSION}")
# doesn't work?
set(V8_TARGET_DIR "${CMAKE_CURRENT_BINARY_DIR}/v8")
#set(V8_TARGET_DIR "out")

if ("${HOST_BITS}" STREQUAL "64")
  set(TARGET_ARCH "x64")
else()
  message(ERROR "WHAT THE FUCK!")
  set(TARGET_ARCH "ia32")
endif() # TODO: ARM? Win32?

if(DEBUG)
  list(APPEND V8_GYP_ARGS -Dv8_enable_backtrace=1)
  set(V8_TARGET_ARCH "${TARGET_ARCH}.debug")
else()
  set(V8_TARGET_ARCH "${TARGET_ARCH}.release")
endif()


list(APPEND V8_GYP_ARGS ${V8_DIR}/build/gyp/gyp_main.py --generator-output=${V8_TARGET_DIR} build/all.gyp)
set (V8_COMPILE_ARGS -C ${V8_TARGET_DIR} -f Makefile.${V8_TARGET_ARCH} BUILDTYPE=Release builddir=${V8_TARGET_DIR}/${V8_TARGET_ARCH} VERBOSE=1 V=1 CC=${CMAKE_C_COMPILER} CXX=${CMAKE_CXX_COMPILER} PYTHON_EXECUTABLE=${PYTHON_EXECUTABLE})

  
if(WIN32)
  # TODO: get this from the main configure paramentrisation
  # CMAKE_BUILD_TYPE:STRING=RelWithDebInfo
  # -G\ msvs_version=2013
  #  -Dtarget_arch=x64
  # -Dmode=release
  list(APPEND V8_GYP_ARGS -Dcomponent=static_library -Dlibrary=static_library)
else()
  # -Dwerror='' breaks shit... rather...   -Dwerror= 
  list(APPEND V8_GYP_ARGS -Ibuild/standalone.gypi --depth=. -Dstandalone_static_library=1  -Dlinux_use_bundled_gold=0 -Dlinux_use_gold_flags=0-Dv8_no_strict_aliasing=1)

  if (APPLE AND CMAKE_COMPILER_IS_CLANG)
    list(APPEND V8_COMPILE_ARGS LDFLAGS=-stdlib=libc++ CXXFLAGS=-stdlib=libc++)
  endif ()
endif()


list(APPEND V8_GYP_ARGS -Dv8_target_arch=${TARGET_ARCH} -S.${V8_TARGET_ARCH})

if (UNIX)
  #set(V8_PLATFORM "native")
  set(V8_BIN_DIR "${V8_TARGET_DIR}/${V8_TARGET_ARCH}")
  set(ICU_BIN_DIR "${V8_BIN_DIR}")
  if (${CMAKE_SYSTEM_NAME} MATCHES "Linux" OR (CMAKE_SYSTEM_NAME MATCHES "Solaris.*") OR (CMAKE_SYSTEM_NAME MATCHES "SunOS.*"))
    set(V8_BIN_DIR "${V8_BIN_DIR}/obj.target/tools/gyp")
    set(ICU_BIN_DIR "${ICU_BIN_DIR}/obj.target/third_party/icu")
  endif ()
else ()
  message(ERROR "Not implemented for your OS")
endif ()

set (ICU_BIN_DIR ${ICU_BIN_DIR} PARENT_SCOPE)
set (V8_BIN_DIR ${V8_BIN_DIR} PARENT_SCOPE)


include(ExternalProject)



#set(RUN_V8_GYP "PYTHON_EXECUTABLE=${PYTHON_EXECUTABLE};\ ${PYTHON_EXECUTABLE}")
set(RUN_V8_GYP "${PYTHON_EXECUTABLE}")

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

if (NOT USE_PRECOMPILED_V8)
  ExternalProject_Add(v8_build
    BUILD_IN_SOURCE TRUE
    SOURCE_DIR "${V8_DIR}"
    CONFIGURE_COMMAND ${RUN_V8_GYP} ${V8_GYP_ARGS} --format make
    BUILD_COMMAND ${MAKE} ${V8_COMPILE_ARGS} 
    INSTALL_COMMAND "")
endif ()

import_target(v8_base v8_build
  "${V8_DIR}/include"
  "${V8_BIN_DIR}/libv8_base.a"
)

import_target(v8_libbase v8_build
  "${V8_DIR}/include"
  "${V8_BIN_DIR}/libv8_libbase.a"
)

import_target(v8_libplatform v8_build
  "${V8_DIR}/include"
  "${V8_BIN_DIR}/libv8_libplatform.a"
)

import_target(v8_nosnapshot v8_build
  "${V8_DIR}/include"
  "${V8_BIN_DIR}/libv8_nosnapshot.a"
)
{'fraction_non_alphanumeric': 0.2986560959102775, 'fraction_numerical': 0.01856327951271391, 'mean_word_length': 4.633986928104576, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '3674335', 'n_tokens_mistral': 3729, 'n_tokens_neox': 3562, 'n_words': 527}