<commit_before>## ---------------------------------------------------------------------
## $Id$
##
## Copyright (C) 2013 by the deal.II authors
##
## This file is part of the deal.II library.
##
## The deal.II library is free software; you can use it, redistribute
## it, and/or modify it under the terms of the GNU Lesser General
## Public License as published by the Free Software Foundation; either
## version 2.1 of the License, or (at your option) any later version.
## The full text of the license can be found in the file LICENSE at
## the top level of the deal.II distribution.
##
## ---------------------------------------------------------------------

#
# This is a bloody hack to avoid a severe performance penalty when using
# 12k top level targets with GNU Make that really does not like that...
#
# The only choice we have is to set up every test subdirectory as an
# independent project. Unfortunately this adds quite a significant amount
# of complexity :-(
#

MESSAGE(STATUS "")
MESSAGE(STATUS "Setup testsuite with TEST_DIR ${TEST_DIR}")
ADD_SUBDIRECTORY(quick_tests)

#
# Custom targets to set and clean up the testsuite:
#

# Setup tests:
ADD_CUSTOM_TARGET(setup_tests)

# Regenerate tests (run "make rebuild_cache" in subprojects):
ADD_CUSTOM_TARGET(regen_tests)

# Clean all tests
ADD_CUSTOM_TARGET(clean_tests)

# Remove all tests:
ADD_CUSTOM_TARGET(prune_tests)

#
# Write a minimalistic CTestTestfile.cmake file to CMAKE_BINARY_DIR and
# CMAKE_CURRENT_BINARY_DIR:
#
FILE(WRITE ${CMAKE_BINARY_DIR}/CTestTestfile.cmake
  "SUBDIRS(tests)"
  )
FILE(WRITE ${CMAKE_CURRENT_BINARY_DIR}/CTestTestfile.cmake "")

#
# Pass all relevant "TEST_" and "_DIR" variables down to the subprojects:
#
SET(_options)
LIST(APPEND _options -DDEAL_II_SOURCE_DIR=${CMAKE_SOURCE_DIR})
LIST(APPEND _options -DDEAL_II_BINARY_DIR=${CMAKE_BINARY_DIR})
FOREACH(_var
    NUMDIFF_DIR
    TEST_DIFF
    TEST_OVERRIDE_LOCATION
    TEST_PICKUP_REGEX
    TEST_TIME_LIMIT
    )
  # always undefine:
  LIST(APPEND _options "-U${_var}")
  IF(DEFINED ${_var})
    LIST(APPEND _options "-D${_var}=${${_var}}")
  ENDIF()
ENDFOREACH()

#
# Glob together a list of all subfolders to set up:
#
FILE(GLOB _categories RELATIVE ${TEST_DIR} ${TEST_DIR}/*)
SET(_categories all-headers build_tests mesh_converter ${_categories})
LIST(REMOVE_DUPLICATES _categories)

#
# Define a subproject for every enabled category:
#

MESSAGE(STATUS "Regenerating testsuite subprojects")

FOREACH(_category ${_categories})
  IF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${_category}/CMakeLists.txt)
    SET(_category_dir ${CMAKE_CURRENT_SOURCE_DIR}/${_category})
  ELSEIF(EXISTS ${TEST_DIR}/${_category}/CMakeLists.txt)
    SET(_category_dir ${TEST_DIR}/${_category})
  ELSE()
    SET(_category_dir)
  ENDIF()

  IF(NOT "${_category_dir}" STREQUAL "")

    ADD_CUSTOM_TARGET(setup_tests_${_category}
      COMMAND ${CMAKE_COMMAND} -E make_directory
        ${CMAKE_CURRENT_BINARY_DIR}/${_category}
      COMMAND cd ${CMAKE_CURRENT_BINARY_DIR}/${_category} &&
        ${CMAKE_COMMAND} -G${CMAKE_GENERATOR} ${_options} ${_category_dir}
        > /dev/null # Shoo!
      DEPENDS ${_category_dir}
      COMMENT "Processing tests/${_category}"
      )
    ADD_DEPENDENCIES(setup_tests setup_tests_${_category})

    # depend on a compiled library:
    ADD_DEPENDENCIES(setup_tests_${_category} build_library)

    ADD_CUSTOM_TARGET(regen_tests_${_category}
      COMMAND [ ! -d ${_category} ] || ${CMAKE_COMMAND}
        --build ${CMAKE_CURRENT_BINARY_DIR}/${_category} --target regenerate
        > /dev/null # Shoo!
      )
    ADD_DEPENDENCIES(regen_tests regen_tests_${_category})

    ADD_CUSTOM_TARGET(clean_tests_${_category}
      COMMAND [ ! -d ${_category} ] || ${CMAKE_COMMAND}
        --build ${CMAKE_CURRENT_BINARY_DIR}/${_category} --target clean
        > /dev/null # Shoo!
      )
    ADD_DEPENDENCIES(clean_tests clean_tests_${_category})

    ADD_CUSTOM_TARGET(prune_tests_${_category}
      COMMAND ${CMAKE_COMMAND} -E remove_directory
        ${CMAKE_CURRENT_BINARY_DIR}/${_category}
      )
    ADD_DEPENDENCIES(prune_tests prune_tests_${_category})

    FILE(APPEND ${CMAKE_CURRENT_BINARY_DIR}/CTestTestfile.cmake
      "SUBDIRS(${_category})\n"
      )

    #
    # Regenerate subprojects: The "regenerate" target of the subproject
    # depends on "rebuild_cache" so that the subprojects rerun cmake if
    # necessary.
    # (TODO: Unfortunately this is sequential - due to the fact that we
    # cannot call back into the main build system)
    #

    IF(EXISTS ${CMAKE_CURRENT_BINARY_DIR}/${_category}/CMakeCache.txt)
      EXECUTE_PROCESS(
        COMMAND ${CMAKE_COMMAND}
        --build ${CMAKE_CURRENT_BINARY_DIR}/${_category} --target regenerate
        OUTPUT_QUIET
        )
    ENDIF()

  ENDIF()
ENDFOREACH()

MESSAGE(STATUS "Regenerating testsuite subprojects - Done")<commit_msg>CMake: Bugfix: Do not use >/dev/null on native Windows targets<commit_after>## ---------------------------------------------------------------------
## $Id$
##
## Copyright (C) 2013 by the deal.II authors
##
## This file is part of the deal.II library.
##
## The deal.II library is free software; you can use it, redistribute
## it, and/or modify it under the terms of the GNU Lesser General
## Public License as published by the Free Software Foundation; either
## version 2.1 of the License, or (at your option) any later version.
## The full text of the license can be found in the file LICENSE at
## the top level of the deal.II distribution.
##
## ---------------------------------------------------------------------

#
# This is a bloody hack to avoid a severe performance penalty when using
# 12k top level targets with GNU Make that really does not like that...
#
# The only choice we have is to set up every test subdirectory as an
# independent project. Unfortunately this adds quite a significant amount
# of complexity :-(
#

MESSAGE(STATUS "")
MESSAGE(STATUS "Setup testsuite with TEST_DIR ${TEST_DIR}")
ADD_SUBDIRECTORY(quick_tests)

#
# Custom targets to set and clean up the testsuite:
#

# Setup tests:
ADD_CUSTOM_TARGET(setup_tests)

# Regenerate tests (run "make rebuild_cache" in subprojects):
ADD_CUSTOM_TARGET(regen_tests)

# Clean all tests
ADD_CUSTOM_TARGET(clean_tests)

# Remove all tests:
ADD_CUSTOM_TARGET(prune_tests)

#
# Write a minimalistic CTestTestfile.cmake file to CMAKE_BINARY_DIR and
# CMAKE_CURRENT_BINARY_DIR:
#
FILE(WRITE ${CMAKE_BINARY_DIR}/CTestTestfile.cmake
  "SUBDIRS(tests)"
  )
FILE(WRITE ${CMAKE_CURRENT_BINARY_DIR}/CTestTestfile.cmake "")

#
# Pass all relevant "TEST_" and "_DIR" variables down to the subprojects:
#
SET(_options)
LIST(APPEND _options -DDEAL_II_SOURCE_DIR=${CMAKE_SOURCE_DIR})
LIST(APPEND _options -DDEAL_II_BINARY_DIR=${CMAKE_BINARY_DIR})
FOREACH(_var
    NUMDIFF_DIR
    TEST_DIFF
    TEST_OVERRIDE_LOCATION
    TEST_PICKUP_REGEX
    TEST_TIME_LIMIT
    )
  # always undefine:
  LIST(APPEND _options "-U${_var}")
  IF(DEFINED ${_var})
    LIST(APPEND _options "-D${_var}=${${_var}}")
  ENDIF()
ENDFOREACH()

# Be as quiet as possible:
IF(CMAKE_SYSTEM_NAME MATCHES "Windows")
  SET(_shoo)
ELSE()
  SET(_shoo >/dev/null)
ENDIF()

#
# Glob together a list of all subfolders to set up:
#
FILE(GLOB _categories RELATIVE ${TEST_DIR} ${TEST_DIR}/*)
SET(_categories all-headers build_tests mesh_converter ${_categories})
LIST(REMOVE_DUPLICATES _categories)

#
# Define a subproject for every enabled category:
#

MESSAGE(STATUS "Regenerating testsuite subprojects")

FOREACH(_category ${_categories})
  IF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${_category}/CMakeLists.txt)
    SET(_category_dir ${CMAKE_CURRENT_SOURCE_DIR}/${_category})
  ELSEIF(EXISTS ${TEST_DIR}/${_category}/CMakeLists.txt)
    SET(_category_dir ${TEST_DIR}/${_category})
  ELSE()
    SET(_category_dir)
  ENDIF()

  IF(NOT "${_category_dir}" STREQUAL "")

    ADD_CUSTOM_TARGET(setup_tests_${_category}
      COMMAND ${CMAKE_COMMAND} -E make_directory
        ${CMAKE_CURRENT_BINARY_DIR}/${_category}
      COMMAND cd ${CMAKE_CURRENT_BINARY_DIR}/${_category} &&
        ${CMAKE_COMMAND} -G${CMAKE_GENERATOR} ${_options} ${_category_dir}
        ${_shoo}
      DEPENDS ${_category_dir}
      COMMENT "Processing tests/${_category}"
      )
    ADD_DEPENDENCIES(setup_tests setup_tests_${_category})

    # depend on a compiled library:
    ADD_DEPENDENCIES(setup_tests_${_category} build_library)

    ADD_CUSTOM_TARGET(regen_tests_${_category}
      COMMAND [ ! -d ${_category} ] || ${CMAKE_COMMAND}
        --build ${CMAKE_CURRENT_BINARY_DIR}/${_category} --target regenerate
        ${_shoo}
      )
    ADD_DEPENDENCIES(regen_tests regen_tests_${_category})

    ADD_CUSTOM_TARGET(clean_tests_${_category}
      COMMAND [ ! -d ${_category} ] || ${CMAKE_COMMAND}
        --build ${CMAKE_CURRENT_BINARY_DIR}/${_category} --target clean
        ${_shoo}
      )
    ADD_DEPENDENCIES(clean_tests clean_tests_${_category})

    ADD_CUSTOM_TARGET(prune_tests_${_category}
      COMMAND ${CMAKE_COMMAND} -E remove_directory
        ${CMAKE_CURRENT_BINARY_DIR}/${_category}
      )
    ADD_DEPENDENCIES(prune_tests prune_tests_${_category})

    FILE(APPEND ${CMAKE_CURRENT_BINARY_DIR}/CTestTestfile.cmake
      "SUBDIRS(${_category})\n"
      )

    #
    # Regenerate subprojects: The "regenerate" target of the subproject
    # depends on "rebuild_cache" so that the subprojects rerun cmake if
    # necessary.
    # (TODO: Unfortunately this is sequential - due to the fact that we
    # cannot call back into the main build system)
    #

    IF(EXISTS ${CMAKE_CURRENT_BINARY_DIR}/${_category}/CMakeCache.txt)
      EXECUTE_PROCESS(
        COMMAND ${CMAKE_COMMAND}
        --build ${CMAKE_CURRENT_BINARY_DIR}/${_category} --target regenerate
        OUTPUT_QUIET
        )
    ENDIF()

  ENDIF()
ENDFOREACH()

MESSAGE(STATUS "Regenerating testsuite subprojects - Done")
MESSAGE(STATUS "")
{'fraction_non_alphanumeric': 0.13333333333333333, 'fraction_numerical': 0.001618614061709661, 'mean_word_length': 3.7528846153846156, 'pattern_counts': {'":': 0, '<': 3, '<?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': '5753399', 'n_tokens_mistral': 3350, 'n_tokens_neox': 3223, 'n_words': 803}