<commit_before>#
#
#    All test files' names must begin with a "test_" prefix
#
#
project( Test )

# Configuration
set(TEST_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/test)    # test executables are going to be placed there
set(TEST_EXT .testbin)           # test executable extension
set(ALL_TEST test${TEST_EXT})    # name of an executable comprising of all tests
set(RUN_TEST runtest)            # dummy target for running tests
set(TEST_MAIN_LIB test_main_lib) # name of a dummy lib containing main function

#    Generate config files
add_definitions(-DCMAKE_BUILD)    # definition needed in order to include CMake's generated files
set(IN_EXT .in)            # generator input file extension
set(GEN_EXT .gen.cmake)    # generated output file extension
set(TEST_DEFINES_FILE ${CMAKE_CURRENT_SOURCE_DIR}/cmake_test_defines.hpp)
set(TEST_DATA_FILE ${CMAKE_CURRENT_SOURCE_DIR}/test_data/sample_data_list.txt)

set(IN_FILES             # generator input files
    ${TEST_DEFINES_FILE}
    ${TEST_DATA_FILE}
)

foreach(in_file ${IN_FILES})    
    configure_file(
        ${in_file}${IN_EXT}
        ${in_file}${GEN_EXT}
    )    
endforeach()       

include_directories(
        ${Caffe_SOURCE_DIR}
        ${CMAKE_CURRENT_SOURCE_DIR}
)

set(TEST_MAIN test_caffe_main.cpp)
list(REMOVE_ITEM TEST_CPP_SOURCES ${TEST_MAIN})

if(NOT CPU_ONLY)
    set(TEST_CPP_SOURCES ${TEST_CPP_SOURCES} ${TEST_CU_SOURCES})
endif()

add_library(${TEST_MAIN_LIB} EXCLUDE_FROM_ALL ${TEST_MAIN})
target_link_libraries(${TEST_MAIN_LIB} gtest caffe)

#    Build each test separately
foreach(source ${TEST_CPP_SOURCES})
    get_filename_component(name ${source} NAME_WE)
    set(TEST_NAME ${name}${TEST_EXT})
    
    add_library(${TEST_NAME}.lib OBJECT ${source})
    set(TEST_OBJ_LIB $<TARGET_OBJECTS:${TEST_NAME}.lib>)
    add_executable(${TEST_NAME} EXCLUDE_FROM_ALL ${TEST_OBJ_LIB}) 
    
    target_link_libraries(${TEST_NAME} ${TEST_MAIN_LIB})
    #    output dir
    set_target_properties(${TEST_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/test)
    
    # Targets and object libs
    set(TEST_TARGETS ${TEST_TARGETS} ${TEST_NAME})
    set(TEST_OBJ_LIBS ${TEST_OBJ_LIBS} ${TEST_OBJ_LIB})
endforeach()

#    Build a compound test excluded from the ALL target
add_executable(${ALL_TEST} EXCLUDE_FROM_ALL ${TEST_OBJ_LIBS} )
target_link_libraries(${ALL_TEST} ${TEST_MAIN_LIB})
add_dependencies(${ALL_TEST} ${TEST_TARGETS})
#    output dir
set_target_properties(${ALL_TEST} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${TEST_OUTPUT_DIRECTORY})
#    Test command
set(TEST_ARGS --gtest_shuffle)
if(CPU_ONLY)
    set(TEST_ARGS ${TEST_ARGS} --gtest_filter="-*GPU*")
endif()

add_custom_target(${RUN_TEST} COMMAND ${ALL_TEST} ${TEST_ARGS})<commit_msg>cpp and cu files processed separately in test build<commit_after>#
#
#    All test files' names must begin with a "test_" prefix
#
#
project( Test )

# Configuration
set(TEST_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/test)    # test executables are going to be placed there
set(TEST_EXT .testbin)           # test executable extension
set(ALL_TEST test${TEST_EXT})    # name of an executable comprising of all tests
set(RUN_TEST runtest)            # dummy target for running tests
set(TEST_MAIN test_caffe_main.cpp)     # main test file (with main function)

#    Generate config files
add_definitions(-DCMAKE_BUILD)    # definition needed in order to include CMake's generated files
set(IN_EXT .in)            # generator input file extension
set(GEN_EXT .gen.cmake)    # generated output file extension
set(TEST_DEFINES_FILE ${CMAKE_CURRENT_SOURCE_DIR}/cmake_test_defines.hpp)
set(TEST_DATA_FILE ${CMAKE_CURRENT_SOURCE_DIR}/test_data/sample_data_list.txt)

set(IN_FILES             # generator input files
    ${TEST_DEFINES_FILE}
    ${TEST_DATA_FILE}
)

foreach(in_file ${IN_FILES})    
    configure_file(
        ${in_file}${IN_EXT}
        ${in_file}${GEN_EXT}
    )    
endforeach()       

include_directories(
        ${Caffe_SOURCE_DIR}
        ${CMAKE_CURRENT_SOURCE_DIR}
)

# Remove main from test sources and prepare an Object lib with main
file(GLOB TEST_MAIN ${TEST_MAIN}) 
list(REMOVE_ITEM TEST_CPP_SOURCES ${TEST_MAIN})
add_library(main_obj EXCLUDE_FROM_ALL OBJECT ${TEST_MAIN})

#if(NOT CPU_ONLY)
#    set(TEST_CPP_SOURCES ${TEST_CPP_SOURCES} ${TEST_CU_SOURCES})
#endif()

#    Build each test separately from *.cpp files
foreach(source ${TEST_CPP_SOURCES})
    #
    get_filename_component(name ${source} NAME_WE)
    set(TEST_NAME ${name}${TEST_EXT})
    
    #
    add_library(${TEST_NAME}.obj OBJECT ${source})
    set(TEST_OBJ_LIB $<TARGET_OBJECTS:${TEST_NAME}.obj>)
    
    add_executable(${TEST_NAME} EXCLUDE_FROM_ALL ${TEST_OBJ_LIB} $<TARGET_OBJECTS:main_obj>)     
    target_link_libraries(${TEST_NAME} gtest caffe)
    
    #    output dir
    set_target_properties(${TEST_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/test)
    
    # Targets and object libs
    set(TEST_TARGETS ${TEST_TARGETS} ${TEST_NAME})
    set(TEST_OBJ_LIBS ${TEST_OBJ_LIBS} ${TEST_OBJ_LIB})
endforeach()

#    Build each test separately from *.cu files
if(NOT CPU_ONLY)
    foreach(source ${TEST_CU_SOURCES})
        #
        get_filename_component(name ${source} NAME_WE)
        set(TEST_NAME ${name}${TEST_EXT})
        
        #
        add_library(${TEST_NAME}.lib ${source})
        
        add_executable(${TEST_NAME} EXCLUDE_FROM_ALL $<TARGET_OBJECTS:main_obj>)     
        target_link_libraries(${TEST_NAME} ${TEST_NAME}.lib gtest caffe)
        
        #    output dir
        set_target_properties(${TEST_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/test)
        
        # Targets and object libs
        set(TEST_TARGETS ${TEST_TARGETS} ${TEST_NAME})
        set(TEST_CU_LIBS ${TEST_CU_LIBS} ${TEST_NAME}.lib)
    endforeach()
endif()

#    Build a compound test excluded from the ALL target
add_executable(${ALL_TEST} EXCLUDE_FROM_ALL ${TEST_OBJ_LIBS} $<TARGET_OBJECTS:main_obj>)
if(NOT CPU_ONLY)
    target_link_libraries(${ALL_TEST} ${TEST_CU_LIBS})
endif()
target_link_libraries(${ALL_TEST} gtest caffe)
add_dependencies(${ALL_TEST} ${TEST_TARGETS})

#    output dir
set_target_properties(${ALL_TEST} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${TEST_OUTPUT_DIRECTORY})
#    Test command
set(TEST_ARGS --gtest_shuffle)
if(CPU_ONLY)
    set(TEST_ARGS ${TEST_ARGS} --gtest_filter="-*GPU*")
endif()

add_custom_target(${RUN_TEST} COMMAND ${ALL_TEST} ${TEST_ARGS})
{'fraction_non_alphanumeric': 0.10538568989601117, 'fraction_numerical': 0.0, 'mean_word_length': 4.498293515358362, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, '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': '5190979', 'n_tokens_mistral': 2258, 'n_tokens_neox': 2158, 'n_words': 451}