<commit_before>cmake_minimum_required(VERSION 2.6)

if (POLICY CMP0020)
  cmake_policy(SET CMP0020 NEW)
endif ()

project(DO_Cuda_Examples)

message(STATUS "  - DO_Cuda_Examples")

find_package(CUDA REQUIRED)
find_package(DO COMPONENTS Core Graphics REQUIRED)

include(${DO_USE_FILE})

include_directories(
  ${CUDA_TOOLKIT_INCLUDE}
  ${CMAKE_CURRENT_SOURCE_DIR}
)


macro (do_add_example example)
  cuda_add_executable(${example} ${example}.cu)
  source_group("CUDA Source Files" REGULAR_EXPRESSION ".*\\.cu")
  set_target_properties(${example} PROPERTIES
                        COMPILE_FLAGS "-DSRCDIR=${CMAKE_CURRENT_SOURCE_DIR}"
                        COMPILE_DEFINITIONS DO_STATIC)
  target_link_libraries(${example} ${DO_LIBRARIES})
  set_property(TARGET ${example} PROPERTY FOLDER "CUDA Examples/${example}")
endmacro ()


add_subdirectory(MultiArray)
add_subdirectory(Utilities)

do_add_example(cuda_test)
target_link_libraries(cuda_test DO_Cuda_Utilities DO_Cuda_MultiArray)<commit_msg>ENH: add convenient CMake script.<commit_after>cmake_minimum_required(VERSION 2.6)

if (POLICY CMP0020)
  cmake_policy(SET CMP0020 NEW)
endif ()

project(DO_Cuda_Examples)

message(STATUS "  - DO_Cuda_Examples")

find_package(CUDA REQUIRED)
find_package(DO COMPONENTS Core Graphics REQUIRED)

include(${DO_USE_FILE})

include_directories(
  ${CUDA_TOOLKIT_INCLUDE}
  ${CMAKE_CURRENT_SOURCE_DIR}
)


macro (do_add_example example)
  cuda_add_library(${example} ${example}.cu)
  source_group("CUDA Source Files" REGULAR_EXPRESSION ".*\\.cu$")
  set_target_properties(${example} PROPERTIES
                        COMPILE_FLAGS "-DSRCDIR=${CMAKE_CURRENT_SOURCE_DIR}"
                        COMPILE_DEFINITIONS DO_STATIC)
  target_link_libraries(${example} ${DO_LIBRARIES})
  set_property(TARGET ${example} PROPERTY FOLDER "CUDA Examples")
endmacro ()


function (cuda_add_example)
   # Get the test executable name.
   list(GET ARGN 0 EXAMPLE_NAME)
   message(STATUS "EXAMPLE NAME = ${EXAMPLE_NAME}")

   # Get the list of source files.
   list(REMOVE_ITEM ARGN ${EXAMPLE_NAME})
   message(STATUS "SOURCE FILES = ${ARGN}")

   # Split the list of source files in two sub-lists:
   # - list of CUDA source files.
   # - list of regular C++ source files.
   set (CUDA_SOURCE_FILES "")
   set (CPP_SOURCE_FILES "")
   foreach (SOURCE ${ARGN})
     if (${SOURCE} MATCHES "(.*).cu$")
       list(APPEND CUDA_SOURCE_FILES ${SOURCE})
     else ()
       list(APPEND CPP_SOURCE_FILES ${SOURCE})
     endif()
   endforeach ()
   message(STATUS "CUDA_SOURCE_FILES = ${CUDA_SOURCE_FILES}")
   message(STATUS "CPP_SOURCE_FILES = ${CPP_SOURCE_FILES}")

   # Add the C++ test executable.
   add_executable(${EXAMPLE_NAME} ${CPP_SOURCE_FILES})
   set_property(TARGET ${EXAMPLE_NAME} PROPERTY FOLDER "CUDA Examples")
   set_target_properties(
     ${EXAMPLE_NAME} PROPERTIES
     COMPILE_FLAGS "-DSRCDIR=${CMAKE_CURRENT_SOURCE_DIR}"
     COMPILE_DEFINITIONS DO_STATIC
   )

   # Create an auxilliary library for CUDA based code.
   # This is a workaround to do unit-test CUDA code with gtest.
   if (NOT "${CUDA_SOURCE_FILES}" STREQUAL "")
     source_group("CUDA Source Files" REGULAR_EXPRESSION ".*\\.cu$")
     cuda_add_library(${EXAMPLE_NAME}_CUDA_AUX ${CUDA_SOURCE_FILES})
	 target_link_libraries(${EXAMPLE_NAME}_CUDA_AUX DO_Cuda_Utilities ${DO_LIBRARIES})
     # Group the unit test in the "Tests" folder.
     set_property(
       TARGET ${EXAMPLE_NAME}_CUDA_AUX PROPERTY FOLDER "CUDA Examples")

     target_link_libraries(${EXAMPLE_NAME} ${EXAMPLE_NAME}_CUDA_AUX ${DO_LIBRARIES})
   endif ()
endfunction ()


add_subdirectory(MultiArray)
add_subdirectory(Utilities)

file(GLOB cuda_test_SRC_FILES FILES *.cu *.cpp *.hpp)
cuda_add_example(test ${cuda_test_SRC_FILES})
target_link_libraries(test DO_Cuda_Utilities DO_Cuda_MultiArray)
{'fraction_non_alphanumeric': 0.10604870384917518, 'fraction_numerical': 0.0054988216810683424, 'mean_word_length': 4.904173106646058, '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': '5741317', 'n_tokens_mistral': 1415, 'n_tokens_neox': 1315, 'n_words': 265}