<commit_before>cmake_minimum_required(VERSION 2.8)

IF(DEFINED CMAKE_BUILD_TYPE)
   SET(CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE} CACHE STRING "Choose the type of build, options are: None Debug Release.")
ELSE()
   SET(CMAKE_BUILD_TYPE Debug CACHE STRING "Choose the type of build, options are: None Debug Release.")
ENDIF()

project(seec)

if(CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
  message(FATAL_ERROR "In-source builds are not allowed.")
endif()

#--------------------------------------------------------------------------------
# Cached variables.
#--------------------------------------------------------------------------------
set(BUNDLE_PREFIX "/Applications" CACHE PATH "Where to install application bundles (Mac OS X).")
set(LLVM_INSTALL "/usr/local" CACHE PATH "Root of LLVM install.")
set(ICU_INSTALL "/usr/local" CACHE PATH "Root of ICU install.")
set(WX_INSTALL "/usr/local" CACHE PATH "Root of wxWidgets install.")
set(GV_INSTALL "/usr" CACHE PATH "Root of graphviz install.") 
set(GV_LIBS "" CACHE STRING "Set the graphviz libraries to link with.")

#--------------------------------------------------------------------------------
# find LLVM
#--------------------------------------------------------------------------------

# A bit of a sanity check:
if( NOT EXISTS ${LLVM_INSTALL}/include/llvm )
  message(FATAL_ERROR "LLVM_INSTALL (${LLVM_INSTALL}) is not a valid LLVM installation.")
endif()

# Now set the header paths:
message("Using LLVM install at ${LLVM_INSTALL}")
include_directories( BEFORE ${LLVM_INSTALL}/include )

set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -L${LLVM_INSTALL}/lib")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -L${LLVM_INSTALL}/lib")

execute_process(
 COMMAND ${LLVM_INSTALL}/bin/llvm-config --cflags
 OUTPUT_VARIABLE LLVM_C_FLAGS
)
string(STRIP ${LLVM_C_FLAGS} LLVM_C_FLAGS)

execute_process(
 COMMAND ${LLVM_INSTALL}/bin/llvm-config --cxxflags
 OUTPUT_VARIABLE LLVM_CXX_FLAGS
)
string(STRIP ${LLVM_CXX_FLAGS} LLVM_CXX_FLAGS)

execute_process(
 COMMAND ${LLVM_INSTALL}/bin/llvm-config --ldflags
 COMMAND tr -s " " "\n"
 COMMAND grep "\\-l"
 COMMAND tr -s "\n-" " -"
 OUTPUT_VARIABLE LLVM_LIB_DEPS
)
string(STRIP ${LLVM_LIB_DEPS} LLVM_LIB_DEPS)
string(REPLACE "-l" "" LLVM_LIB_DEPS ${LLVM_LIB_DEPS})
string(REPLACE " " ";" LLVM_LIB_DEPS ${LLVM_LIB_DEPS})

message("LLVM_LIB_DEPS: ${LLVM_LIB_DEPS}")

# Copy Clang resources into our resources build directory:
file(COPY ${LLVM_INSTALL}/lib/clang DESTINATION ${CMAKE_BINARY_DIR}/resources/)

INSTALL(DIRECTORY ${CMAKE_BINARY_DIR}/resources/clang DESTINATION lib/seec/resources)

#--------------------------------------------------------------------------------
# find ICU
#--------------------------------------------------------------------------------
if( NOT EXISTS ${ICU_INSTALL}/include/unicode/unistr.h )
  message(FATAL_ERROR "ICU_INSTALL (${ICU_INSTALL}) is not a valid ICU installation.")
endif()

message("Using ICU at ${ICU_INSTALL}")
include_directories( BEFORE ${ICU_INSTALL}/include )

set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -L${ICU_INSTALL}/lib")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -L${ICU_INSTALL}/lib")

#--------------------------------------------------------------------------------
# find wxWidgets
#--------------------------------------------------------------------------------
if( NOT EXISTS ${WX_INSTALL}/bin/wx-config )
  message(FATAL_ERROR "WX_INSTALL (${WX_INSTALL}) is not a valid wxWidgets installation.")
endif()

execute_process(
 COMMAND ${WX_INSTALL}/bin/wx-config --prefix=${WX_INSTALL} --cflags
 OUTPUT_VARIABLE WX_C_FLAGS
)
string(STRIP ${WX_C_FLAGS} WX_C_FLAGS)

execute_process(
 COMMAND ${WX_INSTALL}/bin/wx-config --prefix=${WX_INSTALL} --cxxflags
 OUTPUT_VARIABLE WX_CXX_FLAGS
)
string(STRIP ${WX_CXX_FLAGS} WX_CXX_FLAGS)


#--------------------------------------------------------------------------------
# find graphviz
#--------------------------------------------------------------------------------
if( NOT EXISTS ${GV_INSTALL}/include/graphviz/gvc.h )
  message(FATAL_ERROR "GV_INSTALL (${GV_INSTALL}) is not a valid Graphviz installation.")
endif()

message("Using Graphviz at ${GV_INSTALL}")
include_directories( BEFORE ${GV_INSTALL}/include/graphviz )

set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -L${GV_INSTALL}/lib")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -L${GV_INSTALL}/lib")

if (GV_LIBS)
  message("Using user-specified GV_LIBS: ${GV_LIBS}")
  
  set(REQ_GVC_LIBRARIES "")
  
  FOREACH (LIB ${GV_LIBS})
     list(APPEND REQ_GVC_LIBRARIES ${LIB})
  ENDFOREACH (LIB)
else()
  message("Getting graphviz libraries from libgvc.pc")
  
  execute_process(
    COMMAND cat ${GV_INSTALL}/lib/pkgconfig/libgvc.pc
    COMMAND grep "Libs:"
    COMMAND tr " \t" "\n"
    COMMAND grep "\\-l"
    COMMAND tr "\n" " "
    OUTPUT_VARIABLE REQ_GVC_LIBRARIES
  )
  
  string(STRIP ${REQ_GVC_LIBRARIES} REQ_GVC_LIBRARIES)
  string(REPLACE "-l" "" REQ_GVC_LIBRARIES ${REQ_GVC_LIBRARIES})
  string(REPLACE " " ";" REQ_GVC_LIBRARIES ${REQ_GVC_LIBRARIES})
endif()

message("Graphviz libraries: ${REQ_GVC_LIBRARIES}")

#--------------------------------------------------------------------------------
# setup compiler options
#--------------------------------------------------------------------------------

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${LLVM_C_FLAGS} -Wall -std=c99")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${LLVM_CXX_FLAGS} -Wall -std=c++11")

if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
  set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -stdlib=libc++")
  set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -stdlib=libc++")
endif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")

set (CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS} -g")
set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -g")

set (CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS} -O3")
set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -O3")

#--------------------------------------------------------------------------------
# Set build variables
#--------------------------------------------------------------------------------
set_property(GLOBAL PROPERTY SEEC_RESOURCE_FILES "")

#--------------------------------------------------------------------------------
# macro for generating ICU resources
# adapted from: http://www.cmake.org/pipermail/cmake/2009-March/027433.html
# note that, for icupkg to work correctly, resources must be specified BEFORE
# any other resource that they depend upon. e.g. en_AU en root.
#--------------------------------------------------------------------------------
macro(icu_resources package)
  # build directory for this package's resources
  set(${package}_res_dir ${CMAKE_BINARY_DIR}/resources/${package})

  # destination package (.dat file)
  set(${package}_icu_dat ${${package}_res_dir}/${package}.dat)<commit_msg>Use -Wno-strict-aliasing because some of the libraries that we use throw a lot of strict aliasing warnings.<commit_after>cmake_minimum_required(VERSION 2.8)

IF(DEFINED CMAKE_BUILD_TYPE)
   SET(CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE} CACHE STRING "Choose the type of build, options are: None Debug Release.")
ELSE()
   SET(CMAKE_BUILD_TYPE Debug CACHE STRING "Choose the type of build, options are: None Debug Release.")
ENDIF()

project(seec)

if(CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
  message(FATAL_ERROR "In-source builds are not allowed.")
endif()

#--------------------------------------------------------------------------------
# Cached variables.
#--------------------------------------------------------------------------------
set(BUNDLE_PREFIX "/Applications" CACHE PATH "Where to install application bundles (Mac OS X).")
set(LLVM_INSTALL "/usr/local" CACHE PATH "Root of LLVM install.")
set(ICU_INSTALL "/usr/local" CACHE PATH "Root of ICU install.")
set(WX_INSTALL "/usr/local" CACHE PATH "Root of wxWidgets install.")
set(GV_INSTALL "/usr" CACHE PATH "Root of graphviz install.") 
set(GV_LIBS "" CACHE STRING "Set the graphviz libraries to link with.")

#--------------------------------------------------------------------------------
# find LLVM
#--------------------------------------------------------------------------------

# A bit of a sanity check:
if( NOT EXISTS ${LLVM_INSTALL}/include/llvm )
  message(FATAL_ERROR "LLVM_INSTALL (${LLVM_INSTALL}) is not a valid LLVM installation.")
endif()

# Now set the header paths:
message("Using LLVM install at ${LLVM_INSTALL}")
include_directories( BEFORE ${LLVM_INSTALL}/include )

set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -L${LLVM_INSTALL}/lib")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -L${LLVM_INSTALL}/lib")

execute_process(
 COMMAND ${LLVM_INSTALL}/bin/llvm-config --cflags
 OUTPUT_VARIABLE LLVM_C_FLAGS
)
string(STRIP ${LLVM_C_FLAGS} LLVM_C_FLAGS)

execute_process(
 COMMAND ${LLVM_INSTALL}/bin/llvm-config --cxxflags
 OUTPUT_VARIABLE LLVM_CXX_FLAGS
)
string(STRIP ${LLVM_CXX_FLAGS} LLVM_CXX_FLAGS)

execute_process(
 COMMAND ${LLVM_INSTALL}/bin/llvm-config --ldflags
 COMMAND tr -s " " "\n"
 COMMAND grep "\\-l"
 COMMAND tr -s "\n-" " -"
 OUTPUT_VARIABLE LLVM_LIB_DEPS
)
string(STRIP ${LLVM_LIB_DEPS} LLVM_LIB_DEPS)
string(REPLACE "-l" "" LLVM_LIB_DEPS ${LLVM_LIB_DEPS})
string(REPLACE " " ";" LLVM_LIB_DEPS ${LLVM_LIB_DEPS})

message("LLVM_LIB_DEPS: ${LLVM_LIB_DEPS}")

# Copy Clang resources into our resources build directory:
file(COPY ${LLVM_INSTALL}/lib/clang DESTINATION ${CMAKE_BINARY_DIR}/resources/)

INSTALL(DIRECTORY ${CMAKE_BINARY_DIR}/resources/clang DESTINATION lib/seec/resources)

#--------------------------------------------------------------------------------
# find ICU
#--------------------------------------------------------------------------------
if( NOT EXISTS ${ICU_INSTALL}/include/unicode/unistr.h )
  message(FATAL_ERROR "ICU_INSTALL (${ICU_INSTALL}) is not a valid ICU installation.")
endif()

message("Using ICU at ${ICU_INSTALL}")
include_directories( BEFORE ${ICU_INSTALL}/include )

set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -L${ICU_INSTALL}/lib")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -L${ICU_INSTALL}/lib")

#--------------------------------------------------------------------------------
# find wxWidgets
#--------------------------------------------------------------------------------
if( NOT EXISTS ${WX_INSTALL}/bin/wx-config )
  message(FATAL_ERROR "WX_INSTALL (${WX_INSTALL}) is not a valid wxWidgets installation.")
endif()

execute_process(
 COMMAND ${WX_INSTALL}/bin/wx-config --prefix=${WX_INSTALL} --cflags
 OUTPUT_VARIABLE WX_C_FLAGS
)
string(STRIP ${WX_C_FLAGS} WX_C_FLAGS)

execute_process(
 COMMAND ${WX_INSTALL}/bin/wx-config --prefix=${WX_INSTALL} --cxxflags
 OUTPUT_VARIABLE WX_CXX_FLAGS
)
string(STRIP ${WX_CXX_FLAGS} WX_CXX_FLAGS)


#--------------------------------------------------------------------------------
# find graphviz
#--------------------------------------------------------------------------------
if( NOT EXISTS ${GV_INSTALL}/include/graphviz/gvc.h )
  message(FATAL_ERROR "GV_INSTALL (${GV_INSTALL}) is not a valid Graphviz installation.")
endif()

message("Using Graphviz at ${GV_INSTALL}")
include_directories( BEFORE ${GV_INSTALL}/include/graphviz )

set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -L${GV_INSTALL}/lib")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -L${GV_INSTALL}/lib")

if (GV_LIBS)
  message("Using user-specified GV_LIBS: ${GV_LIBS}")
  
  set(REQ_GVC_LIBRARIES "")
  
  FOREACH (LIB ${GV_LIBS})
     list(APPEND REQ_GVC_LIBRARIES ${LIB})
  ENDFOREACH (LIB)
else()
  message("Getting graphviz libraries from libgvc.pc")
  
  execute_process(
    COMMAND cat ${GV_INSTALL}/lib/pkgconfig/libgvc.pc
    COMMAND grep "Libs:"
    COMMAND tr " \t" "\n"
    COMMAND grep "\\-l"
    COMMAND tr "\n" " "
    OUTPUT_VARIABLE REQ_GVC_LIBRARIES
  )
  
  string(STRIP ${REQ_GVC_LIBRARIES} REQ_GVC_LIBRARIES)
  string(REPLACE "-l" "" REQ_GVC_LIBRARIES ${REQ_GVC_LIBRARIES})
  string(REPLACE " " ";" REQ_GVC_LIBRARIES ${REQ_GVC_LIBRARIES})
endif()

message("Graphviz libraries: ${REQ_GVC_LIBRARIES}")

#--------------------------------------------------------------------------------
# setup compiler options
#--------------------------------------------------------------------------------

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${LLVM_C_FLAGS} -Wall -Wno-strict-aliasing -std=c99")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${LLVM_CXX_FLAGS} -Wall -Wno-strict-aliasing -std=c++11")

if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
  set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -stdlib=libc++")
  set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -stdlib=libc++")
endif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")

set (CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS} -g")
set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -g")

set (CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS} -O3")
set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -O3")

#--------------------------------------------------------------------------------
# Set build variables
#--------------------------------------------------------------------------------
set_property(GLOBAL PROPERTY SEEC_RESOURCE_FILES "")

#--------------------------------------------------------------------------------
# macro for generating ICU resources
# adapted from: http://www.cmake.org/pipermail/cmake/2009-March/027433.html
# note that, for icupkg to work correctly, resources must be specified BEFORE
# any other resource that they depend upon. e.g. en_AU en root.
#--------------------------------------------------------------------------------
macro(icu_resources package)
  # build directory for this package's resources
  set(${package}_res_dir ${CMAKE_BINARY_DIR}/resources/${package})

  # destination package (.dat file)
  set(${package}_icu_dat ${${package}_res_dir}/${package}.dat)
{'fraction_non_alphanumeric': 0.28991114932645456, 'fraction_numerical': 0.0025795356835769563, 'mean_word_length': 2.3381966036833295, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2074729', 'n_tokens_mistral': 4745, 'n_tokens_neox': 4335, 'n_words': 921}