<commit_before># 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})
LINK_DIRECTORIES(${THIRD_PARTY_DIR}/libs/gmock)

# Generate automatic unittest from jinja2 templates
ADD_CUSTOM_COMMAND(OUTPUT clone_unittest.cc
	COMMAND ${PYTHON_EXECUTABLE} ${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
	DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/base/clone_unittest.cc.py
	${CMAKE_CURRENT_SOURCE_DIR}/base/clone_unittest.cc.jinja2
	WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
	COMMENT "Generating clone_unittest.cc")
LIST(APPEND TEMPLATE_GENERATED_UNITTEST clone_unittest.cc)

ADD_CUSTOM_COMMAND(OUTPUT DynamicObjectArray_unittest.cc
	COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/base/clone_unittest.cc.py
	${CMAKE_CURRENT_SOURCE_DIR}/base/DynamicObjectArray_unittest.cc.jinja2
	DynamicObjectArray_unittest.cc
	${LIBSHOGUN_SRC_DIR}/base/class_list.cpp
	DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/base/clone_unittest.cc.py
	${CMAKE_CURRENT_SOURCE_DIR}/base/DynamicObjectArray_unittest.cc.jinja2
	WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
	COMMENT "Generating DynamicObjectArray_unittest.cc")
LIST(APPEND TEMPLATE_GENERATED_UNITTEST DynamicObjectArray_unittest.cc)

ADD_CUSTOM_COMMAND(OUTPUT SerializationAscii_unittest.cc
	COMMAND ${PYTHON_EXECUTABLE} ${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
	DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/base/clone_unittest.cc.py
	${CMAKE_CURRENT_SOURCE_DIR}/io/SerializationAscii_unittest.cc.jinja2
	WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
	COMMENT "Generating SerializationAscii_unittest.cc")
LIST(APPEND TEMPLATE_GENERATED_UNITTEST SerializationAscii_unittest.cc)

ADD_CUSTOM_COMMAND(OUTPUT SerializationHDF5_unittest.cc
	COMMAND ${PYTHON_EXECUTABLE} ${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
	DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/base/clone_unittest.cc.py
	${CMAKE_CURRENT_SOURCE_DIR}/io/SerializationHDF5_unittest.cc.jinja2
	WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
	COMMENT "Generating SerializationHDF5_unittest.cc")
LIST(APPEND TEMPLATE_GENERATED_UNITTEST SerializationHDF5_unittest.cc)

ADD_CUSTOM_COMMAND(OUTPUT SerializationJSON_unittest.cc
	COMMAND ${PYTHON_EXECUTABLE} ${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
	DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/base/clone_unittest.cc.py
	${CMAKE_CURRENT_SOURCE_DIR}/io/SerializationJSON_unittest.cc.jinja2
	WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
	COMMENT "Generating SerializationJSON_unittest.cc")
LIST(APPEND TEMPLATE_GENERATED_UNITTEST SerializationJSON_unittest.cc)

ADD_CUSTOM_COMMAND(OUTPUT SerializationXML_unittest.cc
	COMMAND ${PYTHON_EXECUTABLE} ${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
	DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/base/clone_unittest.cc.py
	${CMAKE_CURRENT_SOURCE_DIR}/io/SerializationXML_unittest.cc.jinja2
	WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
	COMMENT "Generating SerializationXML_unittest.cc")
LIST(APPEND TEMPLATE_GENERATED_UNITTEST SerializationXML_unittest.cc)

add_executable (discover_gtest_tests
       ${CMAKE_CURRENT_SOURCE_DIR}/discover_gtest_tests.cpp)

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

ADD_EXECUTABLE(shogun-unit-test ${UNITTEST_SRC} ${TEMPLATE_GENERATED_UNITTEST})
target_link_libraries(shogun-unit-test shogun gmock gtest ${SANITIZER_LIBRARY})
IF (SANITIZER_FLAGS)
	set_target_properties(shogun-unit-test PROPERTIES COMPILE_FLAGS ${SANITIZER_FLAGS})
ENDIF()

ADD_CUSTOM_TARGET(unit-tests
	COMMAND ${CMAKE_CURRENT_BINARY_DIR}/shogun-unit-test
	DEPENDS shogun-unit-test)

shogun_discover_tests(shogun-unit-test)

# Add unittests to the dependencies of modular interfaces to make sure nothing
# will infer with them being build single-threaded.
IF(SWIG_SINGLE_THREADED)
	FOREACH(SG_MODULAR_INTERFACE_TARGET ${SG_MODULAR_INTERFACE_TARGETS})
		ADD_DEPENDENCIES(${SG_MODULAR_INTERFACE_TARGET} shogun-unit-test)<commit_msg>fix gTest segfaults with GCC >= 6.0.0.<commit_after># 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})
LINK_DIRECTORIES(${THIRD_PARTY_DIR}/libs/gmock)

# Generate automatic unittest from jinja2 templates
ADD_CUSTOM_COMMAND(OUTPUT clone_unittest.cc
	COMMAND ${PYTHON_EXECUTABLE} ${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
	DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/base/clone_unittest.cc.py
	${CMAKE_CURRENT_SOURCE_DIR}/base/clone_unittest.cc.jinja2
	WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
	COMMENT "Generating clone_unittest.cc")
LIST(APPEND TEMPLATE_GENERATED_UNITTEST clone_unittest.cc)

ADD_CUSTOM_COMMAND(OUTPUT DynamicObjectArray_unittest.cc
	COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/base/clone_unittest.cc.py
	${CMAKE_CURRENT_SOURCE_DIR}/base/DynamicObjectArray_unittest.cc.jinja2
	DynamicObjectArray_unittest.cc
	${LIBSHOGUN_SRC_DIR}/base/class_list.cpp
	DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/base/clone_unittest.cc.py
	${CMAKE_CURRENT_SOURCE_DIR}/base/DynamicObjectArray_unittest.cc.jinja2
	WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
	COMMENT "Generating DynamicObjectArray_unittest.cc")
LIST(APPEND TEMPLATE_GENERATED_UNITTEST DynamicObjectArray_unittest.cc)

ADD_CUSTOM_COMMAND(OUTPUT SerializationAscii_unittest.cc
	COMMAND ${PYTHON_EXECUTABLE} ${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
	DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/base/clone_unittest.cc.py
	${CMAKE_CURRENT_SOURCE_DIR}/io/SerializationAscii_unittest.cc.jinja2
	WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
	COMMENT "Generating SerializationAscii_unittest.cc")
LIST(APPEND TEMPLATE_GENERATED_UNITTEST SerializationAscii_unittest.cc)

ADD_CUSTOM_COMMAND(OUTPUT SerializationHDF5_unittest.cc
	COMMAND ${PYTHON_EXECUTABLE} ${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
	DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/base/clone_unittest.cc.py
	${CMAKE_CURRENT_SOURCE_DIR}/io/SerializationHDF5_unittest.cc.jinja2
	WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
	COMMENT "Generating SerializationHDF5_unittest.cc")
LIST(APPEND TEMPLATE_GENERATED_UNITTEST SerializationHDF5_unittest.cc)

ADD_CUSTOM_COMMAND(OUTPUT SerializationJSON_unittest.cc
	COMMAND ${PYTHON_EXECUTABLE} ${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
	DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/base/clone_unittest.cc.py
	${CMAKE_CURRENT_SOURCE_DIR}/io/SerializationJSON_unittest.cc.jinja2
	WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
	COMMENT "Generating SerializationJSON_unittest.cc")
LIST(APPEND TEMPLATE_GENERATED_UNITTEST SerializationJSON_unittest.cc)

ADD_CUSTOM_COMMAND(OUTPUT SerializationXML_unittest.cc
	COMMAND ${PYTHON_EXECUTABLE} ${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
	DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/base/clone_unittest.cc.py
	${CMAKE_CURRENT_SOURCE_DIR}/io/SerializationXML_unittest.cc.jinja2
	WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
	COMMENT "Generating SerializationXML_unittest.cc")
LIST(APPEND TEMPLATE_GENERATED_UNITTEST SerializationXML_unittest.cc)

add_executable (discover_gtest_tests
       ${CMAKE_CURRENT_SOURCE_DIR}/discover_gtest_tests.cpp)

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

ADD_EXECUTABLE(shogun-unit-test ${UNITTEST_SRC} ${TEMPLATE_GENERATED_UNITTEST})
target_link_libraries(shogun-unit-test shogun gmock gtest ${SANITIZER_LIBRARY})
IF (SANITIZER_FLAGS)
	set_target_properties(shogun-unit-test PROPERTIES COMPILE_FLAGS ${SANITIZER_FLAGS})
ENDIF()

# In some cases gTest segfaults with GCC >= 6.0.0.  This is a dirty fix.
# TODO: Update to gTest-release with proper support for GCC >= 6.0.0.
# See:  https://github.com/google/googletest/issues/705
IF(CMAKE_COMPILER_IS_GNUCXX)
	# in order to support cmake 2.8.7 and older
	IF(NOT CMAKE_CXX_COMPILER_VERSION)
		include(CheckCompiler)
	ENDIF(NOT CMAKE_CXX_COMPILER_VERSION)
	IF(NOT "${CMAKE_CXX_COMPILER_VERSION}" VERSION_LESS "6.0.0")
		target_compile_options(shogun-unit-test
			PUBLIC -fno-delete-null-pointer-checks)
	ENDIF(NOT "${CMAKE_CXX_COMPILER_VERSION}" VERSION_LESS "6.0.0")
ENDIF(CMAKE_COMPILER_IS_GNUCXX)

ADD_CUSTOM_TARGET(unit-tests
	COMMAND ${CMAKE_CURRENT_BINARY_DIR}/shogun-unit-test
	DEPENDS shogun-unit-test)

shogun_discover_tests(shogun-unit-test)

# Add unittests to the dependencies of modular interfaces to make sure nothing
# will infer with them being build single-threaded.
IF(SWIG_SINGLE_THREADED)
	FOREACH(SG_MODULAR_INTERFACE_TARGET ${SG_MODULAR_INTERFACE_TARGETS})
		ADD_DEPENDENCIES(${SG_MODULAR_INTERFACE_TARGET} shogun-unit-test)
{'fraction_non_alphanumeric': 0.08874522480164561, 'fraction_numerical': 0.00577921441865021, 'mean_word_length': 9.439672801635991, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, 'https://': 1, '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': '6312777', 'n_tokens_mistral': 3963, 'n_tokens_neox': 3824, 'n_words': 439}