<commit_before>cmake_minimum_required(VERSION 3.2)
project (CHAKRACORE)

# Keep CMake from caching static/shared library
# option. Otherwise, CMake fails to update cached
# references

# todo: create a sub cmake file to take care of _SH uncaching...
if(SHARED_LIBRARY_SH)
    unset(SHARED_LIBRARY_SH CACHE)
    unset(STATIC_LIBRARY_SH CACHE)
    unset(STATIC_LIBRARY CACHE)
    set(SHARED_LIBRARY 1)
endif()

if(STATIC_LIBRARY_SH)
    unset(SHARED_LIBRARY_SH CACHE)
    unset(STATIC_LIBRARY_SH CACHE)
    unset(SHARED_LIBRARY CACHE)
    set(STATIC_LIBRARY 1)
endif()

if(LIBS_ONLY_BUILD_SH)
    unset(LIBS_ONLY_BUILD_SH CACHE)
    set(CC_LIBS_ONLY_BUILD 1)
endif()

if(CC_USES_SYSTEM_ARCH_SH)
    if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
        set(CC_TARGETS_AMD64_SH 1)
    elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "armv7l")
        set(CC_TARGETS_ARM_SH 1)
    endif()
    unset(CC_USES_SYSTEM_ARCH_SH CACHE)
endif()

if(CC_TARGETS_AMD64_SH)
    set(CC_TARGETS_AMD64 1)
elseif(CC_TARGETS_ARM_SH)
    set(CC_TARGETS_ARM 1)
    add_definitions(-D_ARM_=1)
    set(CMAKE_SYSTEM_PROCESSOR "armv7l")
elseif(CC_TARGETS_X86_SH)
    set(CC_TARGETS_X86 1)
    set(CMAKE_SYSTEM_PROCESSOR "i386")
else()
    message(FATAL_ERROR "Couldn't detect target processor, try `--arch` argument with build.sh")
endif()

unset(CC_TARGETS_ARM_SH CACHE)
unset(CC_TARGETS_X86_SH CACHE)
unset(CC_TARGETS_AMD64_SH CACHE)

if(ENABLE_VALGRIND_SH)
    unset(ENABLE_VALGRIND_SH CACHE)
    if(NOT CC_TARGETS_X86)
        # Enable Valgrind is not needed for x86 builds. Already <= 32Gb address space
        set(ENABLE_VALGRIND 1)
        add_definitions(-DENABLE_VALGRIND=1)
    endif()
endif()

if(ICU_SETTINGS_RESET)
    unset(ICU_SETTINGS_RESET CACHE)
    unset(ICU_INCLUDE_PATH CACHE)
    unset(ICU_INCLUDE_PATH_SH CACHE)
    unset(NO_ICU_PATH_GIVEN_SH CACHE)
    unset(NO_ICU_PATH_GIVEN CACHE)
    unset(CC_EMBED_ICU_SH CACHE)
endif()

if(CC_TARGET_OS_ANDROID_SH)
    set(CC_TARGET_OS_ANDROID 1)
    set(CMAKE_SYSTEM_NAME Android)
    set(ANDROID_NDK "android-toolchain-arm/")
    set(ANDROID_ABI armeabi-v7a)
    set(CMAKE_SYSTEM_VERSION 21)
    set(CMAKE_ANDROID_ARCH_ABI armeabi)
    set(ANDROID_TOOLCHAIN_NAME arm-linux-androideabi-clang3.8)
    set(ANDROID_STL "c++_static")
    unset(CC_TARGET_OS_ANDROID_SH CACHE)
elseif(CMAKE_SYSTEM_NAME STREQUAL Linux)
    set(CC_TARGET_OS_LINUX 1)
elseif(CMAKE_SYSTEM_NAME STREQUAL Darwin)
    set(CC_TARGET_OS_OSX 1)
endif()

if (ENABLE_CC_XPLAT_TRACE_SH)
    unset(ENABLE_CC_XPLAT_TRACE_SH CACHE)
    set(ENABLE_CC_XPLAT_TRACE 1)
    if (CC_TARGET_OS_ANDROID)
        add_definitions(-DTRACE_OUTPUT_TO_LOGCAT=1)
    else()
        add_definitions(-DTRACE_OUTPUT_TARGET_FILE=1)
    endif()
    add_definitions(-DENABLE_CC_XPLAT_TRACE=1)
    add_compile_options(-finstrument-functions)
    add_compile_options(-g)
    add_compile_options(-ggdb)
    if(NOT STATIC_LIBRARY)
        message(FATAL_ERROR "Trace option is available only for --static builds")
    endif()
endif()

if(CC_EMBED_ICU_SH)
    unset(CC_EMBED_ICU_SH CACHE)
    set(CC_EMBED_ICU 1)
    set(ICU_INCLUDE_PATH "deps/icu/source/output/include/")
endif()

if(ICU_INCLUDE_PATH_SH)
    set(ICU_INCLUDE_PATH ${ICU_INCLUDE_PATH_SH})
    unset(NO_ICU_PATH_GIVEN_SH CACHE)
    unset(NO_ICU_PATH_GIVEN CACHE)
    unset(ICU_INCLUDE_PATH_SH CACHE)
endif()

if(NO_ICU_PATH_GIVEN_SH)
    set(NO_ICU_PATH_GIVEN ${NO_ICU_PATH_GIVEN_SH})
    unset(NO_ICU_PATH_GIVEN_SH CACHE)
    unset(ICU_INCLUDE_PATH_SH CACHE)
    unset(ICU_INCLUDE_PATH CACHE)
endif()

function(clr_unknown_arch)
    message(FATAL_ERROR "Only AMD64, ARM and I386 are supported")
endfunction()

if(INTL_ICU_SH)
    unset(INTL_ICU_SH CACHE)    # don't cache
    add_definitions(-DINTL_ICU=1)
    set(ICU_INTL_ENABLED 1)
endif()

if(ICU_INCLUDE_PATH)
    add_definitions(-DHAS_REAL_ICU=1)
    set(ICU_CC_PATH "${ICU_INCLUDE_PATH}/../lib/")
    find_library(ICUUC icuuc PATHS ${ICU_CC_PATH} NO_DEFAULT_PATH)
    if(ICU_INTL_ENABLED)
        find_library(ICU18 icui18n PATHS ${ICU_CC_PATH} NO_DEFAULT_PATH)
        # icu header files are either located under the same folder or i18n is under a relative path
        # TODO (unlikely): shall we add `--icu-intl` to build.sh ?
        set(ICU_INCLUDE_PATH
          "${ICU_INCLUDE_PATH}"
          "${ICU_INCLUDE_PATH}/../i18n/")
    endif()
    if(ICUUC)
      message("-- found ICU libs: ${ICU_CC_PATH}")
      find_library(ICUDATA icudata PATHS ${ICU_CC_PATH} NO_DEFAULT_PATH)
      if (NOT ICUDATA)
          set(ICUDATA "")
      endif()
      find_library(ICUTOOLS icutools PATHS ${ICU_CC_PATH} NO_DEFAULT_PATH)
      if (NOT ICUTOOLS)
          set(ICUTOOLS "")
      endif()
      set(ICULIB
        ${ICUUC}
        ${ICU18}
        ${ICUDATA}
        ${ICUTOOLS}
        )
    endif()
endif()

set(CLR_CMAKE_PLATFORM_XPLAT 1)
if(CC_TARGETS_AMD64)
    add_definitions(-D_M_X64_OR_ARM64)
    add_compile_options(-msse4.2)

    if(NOT CMAKE_BUILD_TYPE STREQUAL Release)
        set(CAN_BUILD_WABT 1)
    endif()
elseif(CC_TARGETS_X86)
    add_definitions(-D__i686__)
    add_definitions(-D_M_IX86_OR_ARM32)
    add_compile_options(-arch i386)
    add_compile_options(-msse3)

    set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} \
        -m32"
    )
elseif(CC_TARGETS_ARM)
    add_definitions(-D__arm__)<commit_msg>icu: remove unused icutools from cmake file<commit_after>cmake_minimum_required(VERSION 3.2)
project (CHAKRACORE)

# Keep CMake from caching static/shared library
# option. Otherwise, CMake fails to update cached
# references

# todo: create a sub cmake file to take care of _SH uncaching...
if(SHARED_LIBRARY_SH)
    unset(SHARED_LIBRARY_SH CACHE)
    unset(STATIC_LIBRARY_SH CACHE)
    unset(STATIC_LIBRARY CACHE)
    set(SHARED_LIBRARY 1)
endif()

if(STATIC_LIBRARY_SH)
    unset(SHARED_LIBRARY_SH CACHE)
    unset(STATIC_LIBRARY_SH CACHE)
    unset(SHARED_LIBRARY CACHE)
    set(STATIC_LIBRARY 1)
endif()

if(LIBS_ONLY_BUILD_SH)
    unset(LIBS_ONLY_BUILD_SH CACHE)
    set(CC_LIBS_ONLY_BUILD 1)
endif()

if(CC_USES_SYSTEM_ARCH_SH)
    if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
        set(CC_TARGETS_AMD64_SH 1)
    elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "armv7l")
        set(CC_TARGETS_ARM_SH 1)
    endif()
    unset(CC_USES_SYSTEM_ARCH_SH CACHE)
endif()

if(CC_TARGETS_AMD64_SH)
    set(CC_TARGETS_AMD64 1)
elseif(CC_TARGETS_ARM_SH)
    set(CC_TARGETS_ARM 1)
    add_definitions(-D_ARM_=1)
    set(CMAKE_SYSTEM_PROCESSOR "armv7l")
elseif(CC_TARGETS_X86_SH)
    set(CC_TARGETS_X86 1)
    set(CMAKE_SYSTEM_PROCESSOR "i386")
else()
    message(FATAL_ERROR "Couldn't detect target processor, try `--arch` argument with build.sh")
endif()

unset(CC_TARGETS_ARM_SH CACHE)
unset(CC_TARGETS_X86_SH CACHE)
unset(CC_TARGETS_AMD64_SH CACHE)

if(ENABLE_VALGRIND_SH)
    unset(ENABLE_VALGRIND_SH CACHE)
    if(NOT CC_TARGETS_X86)
        # Enable Valgrind is not needed for x86 builds. Already <= 32Gb address space
        set(ENABLE_VALGRIND 1)
        add_definitions(-DENABLE_VALGRIND=1)
    endif()
endif()

if(ICU_SETTINGS_RESET)
    unset(ICU_SETTINGS_RESET CACHE)
    unset(ICU_INCLUDE_PATH CACHE)
    unset(ICU_INCLUDE_PATH_SH CACHE)
    unset(NO_ICU_PATH_GIVEN_SH CACHE)
    unset(NO_ICU_PATH_GIVEN CACHE)
    unset(CC_EMBED_ICU_SH CACHE)
endif()

if(CC_TARGET_OS_ANDROID_SH)
    set(CC_TARGET_OS_ANDROID 1)
    set(CMAKE_SYSTEM_NAME Android)
    set(ANDROID_NDK "android-toolchain-arm/")
    set(ANDROID_ABI armeabi-v7a)
    set(CMAKE_SYSTEM_VERSION 21)
    set(CMAKE_ANDROID_ARCH_ABI armeabi)
    set(ANDROID_TOOLCHAIN_NAME arm-linux-androideabi-clang3.8)
    set(ANDROID_STL "c++_static")
    unset(CC_TARGET_OS_ANDROID_SH CACHE)
elseif(CMAKE_SYSTEM_NAME STREQUAL Linux)
    set(CC_TARGET_OS_LINUX 1)
elseif(CMAKE_SYSTEM_NAME STREQUAL Darwin)
    set(CC_TARGET_OS_OSX 1)
endif()

if (ENABLE_CC_XPLAT_TRACE_SH)
    unset(ENABLE_CC_XPLAT_TRACE_SH CACHE)
    set(ENABLE_CC_XPLAT_TRACE 1)
    if (CC_TARGET_OS_ANDROID)
        add_definitions(-DTRACE_OUTPUT_TO_LOGCAT=1)
    else()
        add_definitions(-DTRACE_OUTPUT_TARGET_FILE=1)
    endif()
    add_definitions(-DENABLE_CC_XPLAT_TRACE=1)
    add_compile_options(-finstrument-functions)
    add_compile_options(-g)
    add_compile_options(-ggdb)
    if(NOT STATIC_LIBRARY)
        message(FATAL_ERROR "Trace option is available only for --static builds")
    endif()
endif()

if(CC_EMBED_ICU_SH)
    unset(CC_EMBED_ICU_SH CACHE)
    set(CC_EMBED_ICU 1)
    set(ICU_INCLUDE_PATH "deps/icu/source/output/include/")
endif()

if(ICU_INCLUDE_PATH_SH)
    set(ICU_INCLUDE_PATH ${ICU_INCLUDE_PATH_SH})
    unset(NO_ICU_PATH_GIVEN_SH CACHE)
    unset(NO_ICU_PATH_GIVEN CACHE)
    unset(ICU_INCLUDE_PATH_SH CACHE)
endif()

if(NO_ICU_PATH_GIVEN_SH)
    set(NO_ICU_PATH_GIVEN ${NO_ICU_PATH_GIVEN_SH})
    unset(NO_ICU_PATH_GIVEN_SH CACHE)
    unset(ICU_INCLUDE_PATH_SH CACHE)
    unset(ICU_INCLUDE_PATH CACHE)
endif()

function(clr_unknown_arch)
    message(FATAL_ERROR "Only AMD64, ARM and I386 are supported")
endfunction()

if(INTL_ICU_SH)
    unset(INTL_ICU_SH CACHE)    # don't cache
    add_definitions(-DINTL_ICU=1)
    set(ICU_INTL_ENABLED 1)
endif()

if(ICU_INCLUDE_PATH)
    add_definitions(-DHAS_REAL_ICU=1)
    set(ICU_CC_PATH "${ICU_INCLUDE_PATH}/../lib/")
    find_library(ICUUC icuuc PATHS ${ICU_CC_PATH} NO_DEFAULT_PATH)
    if(ICU_INTL_ENABLED)
        find_library(ICU18 icui18n PATHS ${ICU_CC_PATH} NO_DEFAULT_PATH)
        # icu header files are either located under the same folder or i18n is under a relative path
        # TODO (unlikely): shall we add `--icu-intl` to build.sh ?
        set(ICU_INCLUDE_PATH
          "${ICU_INCLUDE_PATH}"
          "${ICU_INCLUDE_PATH}/../i18n/")
    endif()
    if(ICUUC)
      message("-- found ICU libs: ${ICU_CC_PATH}")
      find_library(ICUDATA icudata PATHS ${ICU_CC_PATH} NO_DEFAULT_PATH)
      if (NOT ICUDATA)
          set(ICUDATA "")
      endif()
      set(ICULIB
        ${ICUUC}
        ${ICU18}
        ${ICUDATA}
        )
    endif()
endif()

set(CLR_CMAKE_PLATFORM_XPLAT 1)
if(CC_TARGETS_AMD64)
    add_definitions(-D_M_X64_OR_ARM64)
    add_compile_options(-msse4.2)

    if(NOT CMAKE_BUILD_TYPE STREQUAL Release)
        set(CAN_BUILD_WABT 1)
    endif()
elseif(CC_TARGETS_X86)
    add_definitions(-D__i686__)
    add_definitions(-D_M_IX86_OR_ARM32)
    add_compile_options(-arch i386)
    add_compile_options(-msse3)

    set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} \
        -m32"
    )
elseif(CC_TARGETS_ARM)
    add_definitions(-D__arm__)
{'fraction_non_alphanumeric': 0.08911174785100287, 'fraction_numerical': 0.018720152817574023, 'mean_word_length': 4.217239661185849, 'pattern_counts': {'":': 0, '<': 5, '<?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': '2586766', 'n_tokens_mistral': 4546, 'n_tokens_neox': 4256, 'n_words': 684}