<commit_before>###############################################################################
# Find python
find_package(PythonInterp REQUIRED)

###############################################################################
# Build swig

option(ITK_USE_SYSTEM_SWIG "Use system swig. If OFF, swig is built as an external project." OFF)

# Minimal swig version
set(swig_version_min 3.0.0)

set(ITK_SWIG_VERSION 3.0.5)
set(swig_md5     dcb9638324461b9baba8e044fe59031d)
set(swigwin_md5  fd2e050f29e2a00b2348f5f7d3476490)

if(WIN32)
  set(swig_ep "${CMAKE_CURRENT_BINARY_DIR}/swigwin-${ITK_SWIG_VERSION}/swig.exe")
else()
    # follow the standard EP_PREFIX locations
    set ( swig_binary_dir ${CMAKE_CURRENT_BINARY_DIR}/swig-prefix/src/swig-build )
    set ( swig_source_dir ${CMAKE_CURRENT_BINARY_DIR}/swig-prefix/src/swig )
    set ( swig_install_dir ${CMAKE_CURRENT_BINARY_DIR}/swig )

  set(swig_ep "${swig_install_dir}/bin/swig")
endif()

if(ITK_USE_SYSTEM_SWIG)

  # the path set for the EP build prevents find_package to do its job
  if("${SWIG_EXECUTABLE}" STREQUAL "${swig_ep}")
    unset(SWIG_DIR CACHE)
    unset(SWIG_EXECUTABLE CACHE)
    unset(SWIG_VERSION CACHE)
  endif()

  # Look for system swig
  find_package(SWIG REQUIRED)

  # Check for the swig version
  if(${SWIG_VERSION} VERSION_LESS ${swig_version_min})
    message(WARNING "Swig version less than ${swig_version_min}: \"${SWIG_VERSION}\".")
  endif()

else()

  # Install swig ourselves
  set(SWIG_VERSION ${ITK_SWIG_VERSION})

  include(ExternalProject)
  if(WIN32)
    # If we are building ITK
    if(ITK_BINARY_DIR)
      itk_download_attempt_check(SWIG)
    endif()
    ExternalProject_Add(swig
      URL http://prdownloads.sourceforge.net/swig/swigwin-${SWIG_VERSION}.zip
      URL_MD5 ${swigwin_md5}
      SOURCE_DIR ${CMAKE_CURRENT_BINARY_DIR}/swigwin-${SWIG_VERSION}
      CONFIGURE_COMMAND ""
      BUILD_COMMAND ""
      INSTALL_COMMAND ""
      )
    set(SWIG_DIR ${CMAKE_CURRENT_BINARY_DIR}/swigwin-${SWIG_VERSION})
  else()
    # From PCRE configure
    # Some influential environment variables:
    #  CC          C compiler command
    #  CFLAGS      C compiler flags
    #  LDFLAGS     linker flags, e.g. -L<lib dir> if you have libraries in a
    #              nonstandard directory <lib dir>
    #  LIBS        libraries to pass to the linker, e.g. -l<library>
    #  CPPFLAGS    (Objective) C/C++ preprocessor flags, e.g. -I<include dir> if
    #              you have headers in a nonstandard directory <include dir>
    #  CXX         C++ compiler command
    #  CXXFLAGS    C++ compiler flags
    #  CPP         C preprocessor
    #  CXXCPP      C++ preprocessor

    # build swig as an external project

    # If we are building ITK
    if(ITK_BINARY_DIR)
      itk_download_attempt_check(PCRE)
    endif()
    set(pcre_env)
    if(NOT CMAKE_CROSSCOMPILING)
      set(pcre_env
        env
          "CC=${CMAKE_C_COMPILER} ${CMAKE_C_COMPILER_ARG1}"
          "CFLAGS=${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_RELEASE} -w"
          "LDFLAGS=$ENV{LDFLAGS}"
          "LIBS=$ENV{LIBS}"
          "CPPFLAGS=$ENV{CPPFLAGS}"
          "CXX=${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1}"
          "CXXFLAGS=${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_RELEASE} -w"
          "CPP=$ENV{CPP}"
          "CXXPP=$ENV{CXXPP}"
        )
    endif()
    ExternalProject_Add(PCRE
    URL http://downloads.sourceforge.net/project/pcre/pcre/8.36/pcre-8.36.tar.gz
    URL_MD5 ff7b4bb14e355f04885cf18ff4125c98
    CONFIGURE_COMMAND
      ${pcre_env}
      ../PCRE/configure
      --prefix=${CMAKE_CURRENT_BINARY_DIR}/PCRE
      --enable-shared=no
    )

    # swig uses bison find it by cmake and pass it down
    find_package ( BISON )
    set ( BISON_FLAGS "" CACHE STRING "Flags used by bison" )
    mark_as_advanced ( BISON_FLAGS )
<commit_msg>ENH: Update to PCRE 8.37<commit_after>###############################################################################
# Find python
find_package(PythonInterp REQUIRED)

###############################################################################
# Build swig

option(ITK_USE_SYSTEM_SWIG "Use system swig. If OFF, swig is built as an external project." OFF)

# Minimal swig version
set(swig_version_min 3.0.0)

set(ITK_SWIG_VERSION 3.0.5)
set(swig_md5     dcb9638324461b9baba8e044fe59031d)
set(swigwin_md5  fd2e050f29e2a00b2348f5f7d3476490)

if(WIN32)
  set(swig_ep "${CMAKE_CURRENT_BINARY_DIR}/swigwin-${ITK_SWIG_VERSION}/swig.exe")
else()
    # follow the standard EP_PREFIX locations
    set ( swig_binary_dir ${CMAKE_CURRENT_BINARY_DIR}/swig-prefix/src/swig-build )
    set ( swig_source_dir ${CMAKE_CURRENT_BINARY_DIR}/swig-prefix/src/swig )
    set ( swig_install_dir ${CMAKE_CURRENT_BINARY_DIR}/swig )

  set(swig_ep "${swig_install_dir}/bin/swig")
endif()

if(ITK_USE_SYSTEM_SWIG)

  # the path set for the EP build prevents find_package to do its job
  if("${SWIG_EXECUTABLE}" STREQUAL "${swig_ep}")
    unset(SWIG_DIR CACHE)
    unset(SWIG_EXECUTABLE CACHE)
    unset(SWIG_VERSION CACHE)
  endif()

  # Look for system swig
  find_package(SWIG REQUIRED)

  # Check for the swig version
  if(${SWIG_VERSION} VERSION_LESS ${swig_version_min})
    message(WARNING "Swig version less than ${swig_version_min}: \"${SWIG_VERSION}\".")
  endif()

else()

  # Install swig ourselves
  set(SWIG_VERSION ${ITK_SWIG_VERSION})

  include(ExternalProject)
  if(WIN32)
    # If we are building ITK
    if(ITK_BINARY_DIR)
      itk_download_attempt_check(SWIG)
    endif()
    ExternalProject_Add(swig
      URL http://prdownloads.sourceforge.net/swig/swigwin-${SWIG_VERSION}.zip
      URL_MD5 ${swigwin_md5}
      SOURCE_DIR ${CMAKE_CURRENT_BINARY_DIR}/swigwin-${SWIG_VERSION}
      CONFIGURE_COMMAND ""
      BUILD_COMMAND ""
      INSTALL_COMMAND ""
      )
    set(SWIG_DIR ${CMAKE_CURRENT_BINARY_DIR}/swigwin-${SWIG_VERSION})
  else()
    # From PCRE configure
    # Some influential environment variables:
    #  CC          C compiler command
    #  CFLAGS      C compiler flags
    #  LDFLAGS     linker flags, e.g. -L<lib dir> if you have libraries in a
    #              nonstandard directory <lib dir>
    #  LIBS        libraries to pass to the linker, e.g. -l<library>
    #  CPPFLAGS    (Objective) C/C++ preprocessor flags, e.g. -I<include dir> if
    #              you have headers in a nonstandard directory <include dir>
    #  CXX         C++ compiler command
    #  CXXFLAGS    C++ compiler flags
    #  CPP         C preprocessor
    #  CXXCPP      C++ preprocessor

    # build swig as an external project

    # If we are building ITK
    if(ITK_BINARY_DIR)
      itk_download_attempt_check(PCRE)
    endif()
    set(pcre_env)
    if(NOT CMAKE_CROSSCOMPILING)
      set(pcre_env
        env
          "CC=${CMAKE_C_COMPILER} ${CMAKE_C_COMPILER_ARG1}"
          "CFLAGS=${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_RELEASE} -w"
          "LDFLAGS=$ENV{LDFLAGS}"
          "LIBS=$ENV{LIBS}"
          "CPPFLAGS=$ENV{CPPFLAGS}"
          "CXX=${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1}"
          "CXXFLAGS=${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_RELEASE} -w"
          "CPP=$ENV{CPP}"
          "CXXPP=$ENV{CXXPP}"
        )
    endif()
    ExternalProject_Add(PCRE
    URL http://downloads.sourceforge.net/project/pcre/pcre/8.37/pcre-8.37.tar.gz
    URL_MD5 6e0cc6d1bdac7a4308151f9b3571b86e
    CONFIGURE_COMMAND
      ${pcre_env}
      ../PCRE/configure
      --prefix=${CMAKE_CURRENT_BINARY_DIR}/PCRE
      --enable-shared=no
    )

    # swig uses bison find it by cmake and pass it down
    find_package ( BISON )
    set ( BISON_FLAGS "" CACHE STRING "Flags used by bison" )
    mark_as_advanced ( BISON_FLAGS )

{'fraction_non_alphanumeric': 0.1394010723159409, 'fraction_numerical': 0.022492480711390088, 'mean_word_length': 3.32090395480226, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3099967', 'n_tokens_mistral': 2913, 'n_tokens_neox': 2719, 'n_words': 540}