<commit_before>cmake_minimum_required(VERSION 2.9)

# Shut up the warning about CMake policy CMP0042.
if(APPLE)
  set(CMAKE_MACOSX_RPATH ON)
endif()

project(color_coded)

# C++14
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++14" COMPILER_SUPPORTS_CXX14)
CHECK_CXX_COMPILER_FLAG("-std=c++1y" COMPILER_SUPPORTS_CXX1Y)
if(COMPILER_SUPPORTS_CXX14)
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
elseif(COMPILER_SUPPORTS_CXX1Y)
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1y")
else()
  message(FATAL_ERROR "${CMAKE_CXX_COMPILER} has no C++14 support")
endif()

# Lua
find_package(Lua REQUIRED)
if(${LUA_VERSION_STRING} VERSION_LESS "5.2")
  message(FATAL_ERROR "Lua 5.2 is required")
endif()

include_directories(${LUA_INCLUDE_DIR})

# Boost
include_directories(lib/boost)
set(BOOST_SRC
  lib/boost/filesystem/src/codecvt_error_category.cpp
  lib/boost/filesystem/src/operations.cpp
  lib/boost/filesystem/src/path.cpp
  lib/boost/filesystem/src/path_traits.cpp
  lib/boost/filesystem/src/portability.cpp
  lib/boost/filesystem/src/unique_path.cpp
  lib/boost/filesystem/src/utf8_codecvt_facet.cpp
  lib/boost/system/src/error_code.cpp
)

# Curses
find_package(Curses REQUIRED)

# ZLib
find_package(ZLIB REQUIRED)

# Clang
message("Downloading Clang/LLVM 3.6.0 ...")

set(CLANG_URL "http://llvm.org/releases/3.6.0" )
if(APPLE)
  set(CLANG_DIRNAME "clang+llvm-3.6.0-x86_64-apple-darwin")
  set(CLANG_MD5 "103e06006c88d391c9c369a4671e3363")
  set(CLANG_FILENAME "${CLANG_DIRNAME}.tar.xz")
else()
  if(64_BIT_PLATFORM)
    set(CLANG_DIRNAME "clang+llvm-3.6.0-x86_64-linux-gnu-ubuntu-14.04")
    set(CLANG_MD5 "cfb2ebc01573e666770b9c5f72deb04e")
    set(CLANG_FILENAME "${CLANG_DIRNAME}.tar.xz")
  else()
    message(FATAL_ERROR "No pre-built Clang 3.6.0 binaries for 32 bit Linux; this system is not supported")
  endif()
endif()

file(DOWNLOAD
  "${CLANG_URL}/${CLANG_FILENAME}" "./${CLANG_FILENAME}"
  SHOW_PROGRESS EXPECTED_MD5 "${CLANG_MD5}")

message("Extracting Clang/LLVM 3.6.0 ...")

if(CLANG_FILENAME MATCHES ".+bz2")
  execute_process(COMMAND tar -xjf ${CLANG_FILENAME})
elseif(CLANG_FILENAME MATCHES ".+xz")
  execute_process(COMMAND tar -xJf ${CLANG_FILENAME})
else()
  execute_process(COMMAND tar -xzf ${CLANG_FILENAME})
endif()

# We need to set PATH_TO_LLVM_ROOT. To do that, we first have to find the
# folder name the archive produced. It isn't the archive base name.
execute_process(COMMAND
  find ${CMAKE_CURRENT_BINARY_DIR} -maxdepth 1 -type d -name clang*
  OUTPUT_VARIABLE LLVM_ROOT_PATH
  OUTPUT_STRIP_TRAILING_WHITESPACE)

include_directories(
  include

  ${LLVM_ROOT_PATH}/include

  lib/boost/config/include
  lib/boost/core/include
  lib/boost/detail/include
  lib/boost/exception/include
  lib/boost/filesystem/include
  lib/boost/functional/include
  lib/boost/include
  lib/boost/io/include
  lib/boost/iterator/include
  lib/boost/mpl/include
  lib/boost/predef/include
  lib/boost/preprocessor/include
  lib/boost/range/include
  lib/boost/smart_ptr/include
  lib/boost/system/include
  lib/boost/type_traits/include
  lib/boost/utility/include

  ${CURSES_INCLUDE_PATH}
  ${ZLIB_INCLUDE_PATH}
)

message("Generating sources ... ")
execute_process(
  COMMAND ${CMAKE_CURRENT_LIST_DIR}/lib/generate_sources ${CMAKE_CURRENT_LIST_DIR} ${LLVM_ROOT_PATH})

add_library(boost_parts STATIC ${BOOST_SRC})

add_library(color_coded SHARED src/main.cpp)

# Force the same naming across platforms
set_property(TARGET color_coded PROPERTY PREFIX "")
set_property(TARGET color_coded PROPERTY OUTPUT_NAME "color_coded.so")
set_property(TARGET color_coded PROPERTY SUFFIX "")

# Fix compilation problem: relocation R_X86_64_32 against `a local symbol' can not be
# used when making a shared object; recompile with -fPIC.
# See http://www.cmake.org/pipermail/cmake/2007-May/014350.html
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
  set_property(TARGET color_coded PROPERTY COMPILE_FLAGS "-fPIC")
  set(64_BIT_PLATFORM 1)
else()
  set(64_BIT_PLATFORM 0)
endif()

# Clang
set(LLVM_LIB_PATH ${LLVM_ROOT_PATH}/lib)
target_link_libraries(color_coded
  boost_parts
  ${LUA_LIBRARIES}

  ${LLVM_LIB_PATH}/libclang.a
  ${LLVM_LIB_PATH}/libclangIndex.a
  ${LLVM_LIB_PATH}/libclangFormat.a
  ${LLVM_LIB_PATH}/libclangFrontendTool.a
  ${LLVM_LIB_PATH}/libclangFrontend.a
  ${LLVM_LIB_PATH}/libclangDriver.a
  ${LLVM_LIB_PATH}/libclangSerialization.a
  ${LLVM_LIB_PATH}/libclangCodeGen.a
  ${LLVM_LIB_PATH}/libclangParse.a
  ${LLVM_LIB_PATH}/libclangSema.a
  ${LLVM_LIB_PATH}/libclangStaticAnalyzerFrontend.a
  ${LLVM_LIB_PATH}/libclangStaticAnalyzerCheckers.a
  ${LLVM_LIB_PATH}/libclangStaticAnalyzerCore.a<commit_msg>Change the x64 check #25<commit_after>cmake_minimum_required(VERSION 2.9)

# Shut up the warning about CMake policy CMP0042.
if(APPLE)
  set(CMAKE_MACOSX_RPATH ON)
endif()

project(color_coded)

# C++14
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++14" COMPILER_SUPPORTS_CXX14)
CHECK_CXX_COMPILER_FLAG("-std=c++1y" COMPILER_SUPPORTS_CXX1Y)
if(COMPILER_SUPPORTS_CXX14)
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
elseif(COMPILER_SUPPORTS_CXX1Y)
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1y")
else()
  message(FATAL_ERROR "${CMAKE_CXX_COMPILER} has no C++14 support")
endif()

# Lua
find_package(Lua REQUIRED)
if(${LUA_VERSION_STRING} VERSION_LESS "5.2")
  message(FATAL_ERROR "Lua 5.2 is required")
endif()

include_directories(${LUA_INCLUDE_DIR})

# Boost
include_directories(lib/boost)
set(BOOST_SRC
  lib/boost/filesystem/src/codecvt_error_category.cpp
  lib/boost/filesystem/src/operations.cpp
  lib/boost/filesystem/src/path.cpp
  lib/boost/filesystem/src/path_traits.cpp
  lib/boost/filesystem/src/portability.cpp
  lib/boost/filesystem/src/unique_path.cpp
  lib/boost/filesystem/src/utf8_codecvt_facet.cpp
  lib/boost/system/src/error_code.cpp
)

# Curses
find_package(Curses REQUIRED)

# ZLib
find_package(ZLIB REQUIRED)

# Clang
message("Downloading Clang/LLVM 3.6.0 ...")

set(CLANG_URL "http://llvm.org/releases/3.6.0" )
if(APPLE)
  set(CLANG_DIRNAME "clang+llvm-3.6.0-x86_64-apple-darwin")
  set(CLANG_MD5 "103e06006c88d391c9c369a4671e3363")
  set(CLANG_FILENAME "${CLANG_DIRNAME}.tar.xz")
else()
  if(64_BIT_PLATFORM)
    set(CLANG_DIRNAME "clang+llvm-3.6.0-x86_64-linux-gnu-ubuntu-14.04")
    set(CLANG_MD5 "cfb2ebc01573e666770b9c5f72deb04e")
    set(CLANG_FILENAME "${CLANG_DIRNAME}.tar.xz")
  else()
    message(FATAL_ERROR "No pre-built Clang 3.6.0 binaries for 32 bit Linux; this system is not supported")
  endif()
endif()

file(DOWNLOAD
  "${CLANG_URL}/${CLANG_FILENAME}" "./${CLANG_FILENAME}"
  SHOW_PROGRESS EXPECTED_MD5 "${CLANG_MD5}")

message("Extracting Clang/LLVM 3.6.0 ...")

if(CLANG_FILENAME MATCHES ".+bz2")
  execute_process(COMMAND tar -xjf ${CLANG_FILENAME})
elseif(CLANG_FILENAME MATCHES ".+xz")
  execute_process(COMMAND tar -xJf ${CLANG_FILENAME})
else()
  execute_process(COMMAND tar -xzf ${CLANG_FILENAME})
endif()

# We need to set PATH_TO_LLVM_ROOT. To do that, we first have to find the
# folder name the archive produced. It isn't the archive base name.
execute_process(COMMAND
  find ${CMAKE_CURRENT_BINARY_DIR} -maxdepth 1 -type d -name clang*
  OUTPUT_VARIABLE LLVM_ROOT_PATH
  OUTPUT_STRIP_TRAILING_WHITESPACE)

include_directories(
  include

  ${LLVM_ROOT_PATH}/include

  lib/boost/config/include
  lib/boost/core/include
  lib/boost/detail/include
  lib/boost/exception/include
  lib/boost/filesystem/include
  lib/boost/functional/include
  lib/boost/include
  lib/boost/io/include
  lib/boost/iterator/include
  lib/boost/mpl/include
  lib/boost/predef/include
  lib/boost/preprocessor/include
  lib/boost/range/include
  lib/boost/smart_ptr/include
  lib/boost/system/include
  lib/boost/type_traits/include
  lib/boost/utility/include

  ${CURSES_INCLUDE_PATH}
  ${ZLIB_INCLUDE_PATH}
)

message("Generating sources ... ")
execute_process(
  COMMAND ${CMAKE_CURRENT_LIST_DIR}/lib/generate_sources ${CMAKE_CURRENT_LIST_DIR} ${LLVM_ROOT_PATH})

add_library(boost_parts STATIC ${BOOST_SRC})

add_library(color_coded SHARED src/main.cpp)

# Force the same naming across platforms
set_property(TARGET color_coded PROPERTY PREFIX "")
set_property(TARGET color_coded PROPERTY OUTPUT_NAME "color_coded.so")
set_property(TARGET color_coded PROPERTY SUFFIX "")

# Fix compilation problem: relocation R_X86_64_32 against `a local symbol' can not be
# used when making a shared object; recompile with -fPIC.
# See http://www.cmake.org/pipermail/cmake/2007-May/014350.html
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
  set_property(TARGET color_coded PROPERTY COMPILE_FLAGS "-fPIC")
  set(64_BIT_PLATFORM 1)
else()
  set(64_BIT_PLATFORM 0)
endif()

# Clang
set(LLVM_LIB_PATH ${LLVM_ROOT_PATH}/lib)
target_link_libraries(color_coded
  boost_parts
  ${LUA_LIBRARIES}

  ${LLVM_LIB_PATH}/libclang.a
  ${LLVM_LIB_PATH}/libclangIndex.a
  ${LLVM_LIB_PATH}/libclangFormat.a
  ${LLVM_LIB_PATH}/libclangFrontendTool.a
  ${LLVM_LIB_PATH}/libclangFrontend.a
  ${LLVM_LIB_PATH}/libclangDriver.a
  ${LLVM_LIB_PATH}/libclangSerialization.a
  ${LLVM_LIB_PATH}/libclangCodeGen.a
  ${LLVM_LIB_PATH}/libclangParse.a
  ${LLVM_LIB_PATH}/libclangSema.a
  ${LLVM_LIB_PATH}/libclangStaticAnalyzerFrontend.a
  ${LLVM_LIB_PATH}/libclangStaticAnalyzerCheckers.a
  ${LLVM_LIB_PATH}/libclangStaticAnalyzerCore.a
{'fraction_non_alphanumeric': 0.11736230636833046, 'fraction_numerical': 0.029367469879518073, 'mean_word_length': 5.79108838568298, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5849573', 'n_tokens_mistral': 3931, 'n_tokens_neox': 3673, 'n_words': 567}