<commit_before>cmake_minimum_required(VERSION 2.8.12.2)

# find out on which system cmake runs (should be defined with CMakeDetermineSystem.cmake, but not done at this point yet)
if(CMAKE_HOST_UNIX)
  find_program(CMAKE_UNAME uname /bin /usr/bin /usr/local/bin )
  if(CMAKE_UNAME)
    exec_program(uname ARGS -m OUTPUT_VARIABLE CMAKE_HOST_SYSTEM_PROCESSOR RETURN_VALUE val)
  endif()
elseif(CMAKE_HOST_WIN32)
  if (DEFINED ENV{PROCESSOR_ARCHITEW6432})
    set (CMAKE_HOST_SYSTEM_PROCESSOR "$ENV{PROCESSOR_ARCHITEW6432}")
  else()
    set (CMAKE_HOST_SYSTEM_PROCESSOR "$ENV{PROCESSOR_ARCHITECTURE}")
  endif()
endif()


# Detect 32 vs 64 bit
if(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "x86_64" OR CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "AMD64")
  set(SHARPLANG_TRIPLE_CPU "x86_64")
  set(SHARPLANG_MINGW "mingw64")
  set(LLVM_BUILD_SUBFOLDER "build_x64")
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86")
  set(SHARPLANG_TRIPLE_CPU "i686")
  set(SHARPLANG_MINGW "mingw32")
  set(LLVM_BUILD_SUBFOLDER "build_x32")
else()
  message(FATAL_ERROR "Unknown CMAKE_HOST_SYSTEM_PROCESSOR: ${CMAKE_HOST_SYSTEM_PROCESSOR}")
endif()

# Redefine few things to use LLVM compiler instead
if(WIN32)
set(LLVM_BUILD_PATH "${CMAKE_CURRENT_SOURCE_DIR}/deps/llvm/${LLVM_BUILD_SUBFOLDER}/RelWithDebInfo/bin")
find_program(CMAKE_MAKE_PROGRAM NAMES mingw32-make PATHS "${CMAKE_CURRENT_SOURCE_DIR}/deps/${SHARPLANG_MINGW}/bin" NO_DEFAULT_PATH)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/deps/${SHARPLANG_MINGW}/${SHARPLANG_TRIPLE_CPU}-w64-mingw32/include)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/deps/${SHARPLANG_MINGW}/${SHARPLANG_TRIPLE_CPU}-w64-mingw32/include/c++)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/deps/${SHARPLANG_MINGW}/${SHARPLANG_TRIPLE_CPU}-w64-mingw32/include/c++/${SHARPLANG_TRIPLE_CPU}-w64-mingw32)
set(SHARPLANG_TARGET   "${SHARPLANG_TRIPLE_CPU}-pc-windows-gnu")
else()
set(LLVM_BUILD_PATH "${CMAKE_CURRENT_SOURCE_DIR}/deps/llvm/${LLVM_BUILD_SUBFOLDER}/bin")
set(SHARPLANG_TARGET   "${SHARPLANG_TRIPLE_CPU}-linux-gnu")
endif()

find_program(CMAKE_C_COMPILER NAMES clang PATHS "${LLVM_BUILD_PATH}" NO_DEFAULT_PATH)
find_program(CMAKE_CXX_COMPILER NAMES clang++ PATHS "${LLVM_BUILD_PATH}" NO_DEFAULT_PATH)
find_program(CMAKE_LINKER NAMES llvm-link PATHS "${LLVM_BUILD_PATH}" NO_DEFAULT_PATH)
find_program(CMAKE_CXX_LINKER NAMES llvm-link PATHS "${LLVM_BUILD_PATH}" NO_DEFAULT_PATH)
find_program(CMAKE_C_LINK_EXECUTABLE NAMES llvm-link PATHS "${LLVM_BUILD_PATH}" NO_DEFAULT_PATH)
find_program(CMAKE_CXX_LINK_EXECUTABLE NAMES llvm-link PATHS "${LLVM_BUILD_PATH}" NO_DEFAULT_PATH)

set(SHARPLANG_BUILD_SUBDIR "${CMAKE_BINARY_DIR}/../../lib")

# Set default compilation flags
set(CMAKE_BITCODE_FLAGS   "${CMAKE_BITCODE_FLAGS} -emit-llvm --target=${SHARPLANG_TARGET}")

# Set bitcode output directory
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${SHARPLANG_BUILD_SUBDIR}/runtime/${SHARPLANG_TARGET})

set(CMAKE_C_COMPILER_ID "GNU")
set(CMAKE_C_COMPILER_ID_RUN TRUE)
set(CMAKE_C_COMPILER_FORCED TRUE)
set(CMAKE_CXX_COMPILER_ID "GNU")
set(CMAKE_CXX_COMPILER_ID_RUN TRUE)
set(CMAKE_CXX_COMPILER_FORCED TRUE)
set(CMAKE_COMPILER_IS_GNUCC 1)
set(CMAKE_COMPILER_IS_GNUCXX 1)

# Not sure why those flags need to be defined after project
set(CMAKE_C_ARCHIVE_CREATE "${CMAKE_C_LINK_EXECUTABLE} -o <TARGET> <LINK_FLAGS> <OBJECTS>")
set(CMAKE_CXX_ARCHIVE_CREATE "${CMAKE_CXX_LINK_EXECUTABLE} -o <TARGET> <LINK_FLAGS> <OBJECTS>")
set(CMAKE_C_ARCHIVE_FINISH "")
set(CMAKE_CXX_ARCHIVE_FINISH "")

project(SharpLang)

set(CMAKE_C_OUTPUT_EXTENSION ".bc")
set(CMAKE_CXX_OUTPUT_EXTENSION ".bc")
set(CMAKE_STATIC_LIBRARY_SUFFIX ".bc")
set(CMAKE_STATIC_LIBRARY_PREFIX "")

add_subdirectory(src)<commit_msg>[Build] Properly detect which version of LLVM was built.<commit_after>cmake_minimum_required(VERSION 2.8.12.2)

#if(NOT SHARPLANG_TARGET)
#  message(FATAL_ERROR "SHARPLANG_TARGET is not defined")
#endif()

# Detect existence of 32 or 64 bit compiler
if(WIN32)
  if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/deps/llvm/build_x64")
    set(SHARPLANG_MINGW "mingw64")
    set(SHARPLANG_MINGW_CPU "x86_64")
    set(LLVM_BUILD_SUBFOLDER "build_x64")
  elseif(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/deps/llvm/build_x32")
    set(SHARPLANG_MINGW "mingw32")
    set(SHARPLANG_MINGW_CPU "i686")
    set(LLVM_BUILD_SUBFOLDER "build_x32")
  else()
    message(FATAL_ERROR "Could not find a valid LLVM/Clang build (should be located under deps/llvm/build_x64 or deps/llvm/build_x32)")
  endif()
else()
  set(LLVM_BUILD_SUBFOLDER "build")
endif()

# Redefine few things to use LLVM compiler instead
if(WIN32)
  set(LLVM_BUILD_PATH "${CMAKE_CURRENT_SOURCE_DIR}/deps/llvm/${LLVM_BUILD_SUBFOLDER}/RelWithDebInfo/bin")
  find_program(CMAKE_MAKE_PROGRAM NAMES mingw32-make PATHS "${CMAKE_CURRENT_SOURCE_DIR}/deps/${SHARPLANG_MINGW}/bin" NO_DEFAULT_PATH)
  include_directories(${CMAKE_CURRENT_SOURCE_DIR}/deps/${SHARPLANG_MINGW}/${SHARPLANG_MINGW_CPU}-w64-mingw32/include)
  include_directories(${CMAKE_CURRENT_SOURCE_DIR}/deps/${SHARPLANG_MINGW}/${SHARPLANG_MINGW_CPU}-w64-mingw32/include/c++)
  include_directories(${CMAKE_CURRENT_SOURCE_DIR}/deps/${SHARPLANG_MINGW}/${SHARPLANG_MINGW_CPU}-w64-mingw32/include/c++/${SHARPLANG_MINGW_CPU}-w64-mingw32)
  if (NOT SHARPLANG_TARGET)
    set(SHARPLANG_TARGET   "${SHARPLANG_MINGW_CPU}-pc-windows-gnu")
  endif()
else()
  set(LLVM_BUILD_SUBFOLDER "build") # on Linux, x86/x64 matches host, so no need to have separate folders
  set(LLVM_BUILD_PATH "${CMAKE_CURRENT_SOURCE_DIR}/deps/llvm/${LLVM_BUILD_SUBFOLDER}/bin")
endif()

find_program(CMAKE_C_COMPILER NAMES clang PATHS "${LLVM_BUILD_PATH}" NO_DEFAULT_PATH)
find_program(CMAKE_CXX_COMPILER NAMES clang++ PATHS "${LLVM_BUILD_PATH}" NO_DEFAULT_PATH)
find_program(CMAKE_LINKER NAMES llvm-link PATHS "${LLVM_BUILD_PATH}" NO_DEFAULT_PATH)
find_program(CMAKE_CXX_LINKER NAMES llvm-link PATHS "${LLVM_BUILD_PATH}" NO_DEFAULT_PATH)
find_program(CMAKE_C_LINK_EXECUTABLE NAMES llvm-link PATHS "${LLVM_BUILD_PATH}" NO_DEFAULT_PATH)
find_program(CMAKE_CXX_LINK_EXECUTABLE NAMES llvm-link PATHS "${LLVM_BUILD_PATH}" NO_DEFAULT_PATH)

set(SHARPLANG_BUILD_SUBDIR "${CMAKE_BINARY_DIR}/../../lib")

# Set default compilation flags
set(CMAKE_BITCODE_FLAGS   "${CMAKE_BITCODE_FLAGS} -emit-llvm ")

if (SHARPLANG_TARGET)
  set(CMAKE_BITCODE_FLAGS   "${CMAKE_BITCODE_FLAGS} --target=${SHARPLANG_TARGET}")
endif()

# Set bitcode output directory
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${SHARPLANG_BUILD_SUBDIR}/runtime/${SHARPLANG_TARGET})

set(CMAKE_C_COMPILER_ID "GNU")
set(CMAKE_C_COMPILER_ID_RUN TRUE)
set(CMAKE_C_COMPILER_FORCED TRUE)
set(CMAKE_CXX_COMPILER_ID "GNU")
set(CMAKE_CXX_COMPILER_ID_RUN TRUE)
set(CMAKE_CXX_COMPILER_FORCED TRUE)
set(CMAKE_COMPILER_IS_GNUCC 1)
set(CMAKE_COMPILER_IS_GNUCXX 1)

# Not sure why those flags need to be defined after project
set(CMAKE_C_ARCHIVE_CREATE "${CMAKE_C_LINK_EXECUTABLE} -o <TARGET> <LINK_FLAGS> <OBJECTS>")
set(CMAKE_CXX_ARCHIVE_CREATE "${CMAKE_CXX_LINK_EXECUTABLE} -o <TARGET> <LINK_FLAGS> <OBJECTS>")
set(CMAKE_C_ARCHIVE_FINISH "")
set(CMAKE_CXX_ARCHIVE_FINISH "")

project(SharpLang)

set(CMAKE_C_OUTPUT_EXTENSION ".bc")
set(CMAKE_CXX_OUTPUT_EXTENSION ".bc")
set(CMAKE_STATIC_LIBRARY_SUFFIX ".bc")
set(CMAKE_STATIC_LIBRARY_PREFIX "")

add_subdirectory(src)
{'fraction_non_alphanumeric': 0.11214048672566372, 'fraction_numerical': 0.017146017699115043, 'mean_word_length': 8.814111261872457, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '452572', 'n_tokens_mistral': 3135, 'n_tokens_neox': 2932, 'n_words': 426}