<commit_before># transform defines to -D<definition> string
foreach(D IN LISTS DEFINES)
	SET(CMAKE_DEFINITIONS "${CMAKE_DEFINITIONS} -D${D}")
endforeach()

# Find GTEST and GMOCK frameworks
include(external/GoogleTestNMock)
ExternalProject_Get_Property(GoogleMock source_dir)
if(SYSTEM_INCLUDES)
	INCLUDE_DIRECTORIES(SYSTEM ${SYSTEM_INCLUDES})
endif()
include_directories(${source_dir}/include ${INCLUDES} ${source_dir}/gtest/include ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/src)
LINK_DIRECTORIES(${THIRD_PARTY_DIR}/libs/gmock)

# Generate automatic unittest from jinja2 templates
FILE(GLOB_RECURSE UNITTEST_SRC_TMP RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *${EXT_SRC_TEST_TMP})
FOREACH(template ${UNITTEST_SRC_TMP})
	STRING(REGEX REPLACE "(.*).jinja2$" "\\1.py" script ${template})
	STRING(REGEX REPLACE ".*/(.*).jinja2$" "\\1" out_cxx ${template})
	
	ADD_CUSTOM_COMMAND(OUTPUT ${out_cxx}
			COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/${script} 
				${CMAKE_CURRENT_SOURCE_DIR}/${template} ${out_cxx} ${LIBSHOGUN_SRC_DIR}/base/class_list.cpp
			WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
			COMMENT "Generating ${out_cxx}")
	LIST(APPEND TEMPLATE_GENERATED_UNITTEST ${out_cxx})
	UNSET(${script})
ENDFOREACH()

# collect the unittests
FILE(GLOB_RECURSE UNITTEST_SRC *_unittest.cc)

ADD_EXECUTABLE(shogun-unit-test ${UNITTEST_SRC} ${TEMPLATE_GENERATED_UNITTEST})<commit_msg>Refactor autogenerated unit test creation in cmake one will have to add manually the generation command this way we support more flexible autogeneration<commit_after># transform defines to -D<definition> string
foreach(D IN LISTS DEFINES)
	SET(CMAKE_DEFINITIONS "${CMAKE_DEFINITIONS} -D${D}")
endforeach()

# Find GTEST and GMOCK frameworks
include(external/GoogleTestNMock)
ExternalProject_Get_Property(GoogleMock source_dir)
if(SYSTEM_INCLUDES)
	INCLUDE_DIRECTORIES(SYSTEM ${SYSTEM_INCLUDES})
endif()
include_directories(${source_dir}/include ${INCLUDES} ${source_dir}/gtest/include ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/src)
LINK_DIRECTORIES(${THIRD_PARTY_DIR}/libs/gmock)

# Generate automatic unittest from jinja2 templates
SET(clone_unittest.cc_CMD
	${CMAKE_CURRENT_SOURCE_DIR}/base/clone_unittest.cc.py 
	${CMAKE_CURRENT_SOURCE_DIR}/base/clone_unittest.cc.jinja2 
	clone_unittest.cc 
	${LIBSHOGUN_SRC_DIR}/base/class_list.cpp)
LIST(APPEND UNITTEST_TEMPLATES clone_unittest.cc)

SET(SerializationAscii_unittest.cc_CMD 
	${CMAKE_CURRENT_SOURCE_DIR}/base/clone_unittest.cc.py 
	${CMAKE_CURRENT_SOURCE_DIR}/io/SerializationAscii_unittest.cc.jinja2 
	SerializationAscii_unittest.cc
	${LIBSHOGUN_SRC_DIR}/base/class_list.cpp)
LIST(APPEND UNITTEST_TEMPLATES SerializationAscii_unittest.cc)

SET(SerializationJSON_unittest.cc_CMD 
	${CMAKE_CURRENT_SOURCE_DIR}/base/clone_unittest.cc.py
	${CMAKE_CURRENT_SOURCE_DIR}/io/SerializationJSON_unittest.cc.jinja2 
	SerializationJSON_unittest.cc 
	${LIBSHOGUN_SRC_DIR}/base/class_list.cpp)
LIST(APPEND UNITTEST_TEMPLATES SerializationJSON_unittest.cc)

SET(SerializationXML_unittest.cc_CMD 
	${CMAKE_CURRENT_SOURCE_DIR}/base/clone_unittest.cc.py
	${CMAKE_CURRENT_SOURCE_DIR}/io/SerializationXML_unittest.cc.jinja2 
	SerializationXML_unittest.cc 
	${LIBSHOGUN_SRC_DIR}/base/class_list.cpp)
LIST(APPEND UNITTEST_TEMPLATES SerializationXML_unittest.cc)

SET(SerializationHDF5_unittest.cc_CMD 
	${CMAKE_CURRENT_SOURCE_DIR}/base/clone_unittest.cc.py
	${CMAKE_CURRENT_SOURCE_DIR}/io/SerializationHDF5_unittest.cc.jinja2 
	SerializationHDF5_unittest.cc 
	${LIBSHOGUN_SRC_DIR}/base/class_list.cpp)
LIST(APPEND UNITTEST_TEMPLATES SerializationHDF5_unittest.cc)

FOREACH(out_cxx ${UNITTEST_TEMPLATES})
	ADD_CUSTOM_COMMAND(OUTPUT ${out_cxx}
			COMMAND ${PYTHON_EXECUTABLE} ${${out_cxx}_CMD}
			WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
			COMMENT "Generating ${out_cxx}")
	LIST(APPEND TEMPLATE_GENERATED_UNITTEST ${out_cxx})
ENDFOREACH()

# collect the unittests
FILE(GLOB_RECURSE UNITTEST_SRC *_unittest.cc)

ADD_EXECUTABLE(shogun-unit-test ${UNITTEST_SRC} ${TEMPLATE_GENERATED_UNITTEST})
{'fraction_non_alphanumeric': 0.10785288270377734, 'fraction_numerical': 0.003727634194831014, 'mean_word_length': 8.865196078431373, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '3276830', 'n_tokens_mistral': 1577, 'n_tokens_neox': 1489, 'n_words': 208}