<commit_before>cmake_minimum_required(VERSION 2.8)

#------------------------------------------------------------------------------
# PREREQUISITES
#------------------------------------------------------------------------------
enable_language(C)
enable_language(CXX)

include(${CMAKE_ROOT}/Modules/CheckIncludeFile.cmake)

find_package(PythonInterp REQUIRED)
find_program(BISON bison)
find_program(LLVM_CONFIG_EXE NAMES "llvm-config" "llvm-config-3.0")

set(memc_BUILT ${CMAKE_CURRENT_BINARY_DIR}/src.built)
set(memc_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src)
set(memc_UTILS ${CMAKE_CURRENT_SOURCE_DIR}/utils)
set(gtest_SRC ${memc_UTILS}/gtest)

file(MAKE_DIRECTORY ${memc_BUILT})
file(MAKE_DIRECTORY ${memc_BUILT}/langmem)

if(${LLVM_CONFIG_EXE} STREQUAL "LLVM_CONFIG_EXE-NOTFOUND")
	message(WARNING "llvm-config executable not found, compiling without native code generation")
else()
	#SET(HAVE_LLVM 1)
	execute_process(COMMAND ${LLVM_CONFIG_EXE} --cppflags OUTPUT_VARIABLE LLVM_CPP_FLAGS)
	STRING(REPLACE "\n" " " LLVM_CPP_FLAGS "${LLVM_CPP_FLAGS}")
	STRING(REPLACE "\r" " " LLVM_CPP_FLAGS "${LLVM_CPP_FLAGS}")
	execute_process(COMMAND ${LLVM_CONFIG_EXE}  --libs native codegen OUTPUT_VARIABLE LLVM_LIBS)
	STRING(REPLACE "\n" " " LLVM_LIBS "${LLVM_LIBS}")
	STRING(REPLACE "\r" " " LLVM_LIBS "${LLVM_LIBS}")
	STRING(REGEX REPLACE " $" "" LLVM_LIBS "${LLVM_LIBS}")
	#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${LLVM_CPP_FLAGS}")
	#set(CMAKE_EXE_LINKER_FLAGS "-lpthread -lffi -ldl ${CMAKE_EXE_LINKER_FLAGS}")
	INCLUDE(CheckLibraryExists)
	find_library(LIB_DL NAMES dl dld)
	CHECK_LIBRARY_EXISTS(dl dladdr "" HAVE_LIBDL)
	CHECK_LIBRARY_EXISTS(dl dlopen "" HAVE_LIBDL)
endif()

CHECK_INCLUDE_FILE("stdint.h" HAVE_STDINT_H)

#------------------------------------------------------------------------------
# CUSTOM COMMANDS
#------------------------------------------------------------------------------
# Testing
add_custom_target(
	test
	COMMAND
		cd ${CMAKE_CURRENT_SOURCE_DIR}/tests && ${PYTHON_EXECUTABLE}
		${memc_UTILS}/RunTests.py
		--memc-exe=${CMAKE_CURRENT_BINARY_DIR}/memc
		--test-dir=${CMAKE_CURRENT_SOURCE_DIR}/tests
		--report-dir=${CMAKE_CURRENT_BINARY_DIR})

# Node kinds
add_custom_command(
	OUTPUT
		${memc_BUILT}/mem/ast/node/Kind.hpp
		${memc_BUILT}/mem/ast/node/Kind.cpp
	COMMAND<commit_msg>Run both blackbox and whitebox on `make test`<commit_after>cmake_minimum_required(VERSION 2.8)

#------------------------------------------------------------------------------
# PREREQUISITES
#------------------------------------------------------------------------------
enable_language(C)
enable_language(CXX)

include(${CMAKE_ROOT}/Modules/CheckIncludeFile.cmake)

find_package(PythonInterp REQUIRED)
find_program(BISON bison)
find_program(LLVM_CONFIG_EXE NAMES "llvm-config" "llvm-config-3.0")

set(memc_BUILT ${CMAKE_CURRENT_BINARY_DIR}/src.built)
set(memc_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src)
set(memc_UTILS ${CMAKE_CURRENT_SOURCE_DIR}/utils)
set(gtest_SRC ${memc_UTILS}/gtest)

file(MAKE_DIRECTORY ${memc_BUILT})
file(MAKE_DIRECTORY ${memc_BUILT}/langmem)

if(${LLVM_CONFIG_EXE} STREQUAL "LLVM_CONFIG_EXE-NOTFOUND")
	message(WARNING "llvm-config executable not found, compiling without native code generation")
else()
	#SET(HAVE_LLVM 1)
	execute_process(COMMAND ${LLVM_CONFIG_EXE} --cppflags OUTPUT_VARIABLE LLVM_CPP_FLAGS)
	STRING(REPLACE "\n" " " LLVM_CPP_FLAGS "${LLVM_CPP_FLAGS}")
	STRING(REPLACE "\r" " " LLVM_CPP_FLAGS "${LLVM_CPP_FLAGS}")
	execute_process(COMMAND ${LLVM_CONFIG_EXE}  --libs native codegen OUTPUT_VARIABLE LLVM_LIBS)
	STRING(REPLACE "\n" " " LLVM_LIBS "${LLVM_LIBS}")
	STRING(REPLACE "\r" " " LLVM_LIBS "${LLVM_LIBS}")
	STRING(REGEX REPLACE " $" "" LLVM_LIBS "${LLVM_LIBS}")
	#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${LLVM_CPP_FLAGS}")
	#set(CMAKE_EXE_LINKER_FLAGS "-lpthread -lffi -ldl ${CMAKE_EXE_LINKER_FLAGS}")
	INCLUDE(CheckLibraryExists)
	find_library(LIB_DL NAMES dl dld)
	CHECK_LIBRARY_EXISTS(dl dladdr "" HAVE_LIBDL)
	CHECK_LIBRARY_EXISTS(dl dlopen "" HAVE_LIBDL)
endif()

CHECK_INCLUDE_FILE("stdint.h" HAVE_STDINT_H)

#------------------------------------------------------------------------------
# CUSTOM COMMANDS
#------------------------------------------------------------------------------
# Testing
add_custom_target(
	run-whitebox-test
	COMMAND
		cd ${CMAKE_CURRENT_SOURCE_DIR}/tests && ${PYTHON_EXECUTABLE}
		${memc_UTILS}/RunTests.py
		--memc-exe=${CMAKE_CURRENT_BINARY_DIR}/memc
		--test-dir=${CMAKE_CURRENT_SOURCE_DIR}/tests
		--report-dir=${CMAKE_CURRENT_BINARY_DIR})
add_custom_target(
	run-blackbox-test
	COMMAND
		memc-test
	DEPENDS memc-test)
add_custom_target(
	test
	DEPENDS run-blackbox-test run-whitebox-test)

# Node kinds
add_custom_command(
	OUTPUT
		${memc_BUILT}/mem/ast/node/Kind.hpp
		${memc_BUILT}/mem/ast/node/Kind.cpp
	COMMAND
{'fraction_non_alphanumeric': 0.24411580920641532, 'fraction_numerical': 0.002082899395959175, 'mean_word_length': 3.272241992882562, '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': '3339494', 'n_tokens_mistral': 1816, 'n_tokens_neox': 1733, 'n_words': 249}