<commit_before>project(ITKDCMTK)

set(ITKDCMTK_THIRD_PARTY 1)

# This depends on the external project, nothing locally built
set(ITKDCMTK_NO_SRC 1)

include(CMakeParseArguments)

macro(define_by_product)
  cmake_parse_arguments(BY_PRODUCT "" "NAME" "TARGETS" ${ARGN})
  if(CMAKE_VERSION VERSION_LESS 3.2)
    if("${CMAKE_GENERATOR}" STREQUAL "Ninja")
      message(FATAL_ERROR "CMake >= 3.2 required with Ninja to compile DCMTK.")
    endif()
    set(${BY_PRODUCT_NAME}_build_byproducts)
  else()
    set(${BY_PRODUCT_NAME}_build_byproducts  BUILD_BYPRODUCTS ${BY_PRODUCT_TARGETS})
  endif()
endmacro()

if(DCMTK_USE_ICU)
  option(ITK_USE_SYSTEM_ICU "Use an installed version of icu" OFF)
  if(NOT ITK_USE_SYSTEM_ICU)
    set(ITKDCMTK_PREREQS ${ITKDCMTK_BINARY_DIR}/DCMTK_Prereqs)
    set(ITKDCMTK_ICU_LIBRARIES )
    if(WIN32)
      set(ITKDCMTK_ICU_LIBRARY_NAMES uc dt)
    else()
      set(ITKDCMTK_ICU_LIBRARY_NAMES uc data)
    endif()
    foreach(lib_name ${ITKDCMTK_ICU_LIBRARY_NAMES})
      set(lib ICU::${lib_name})
        list(APPEND ITKDCMTK_ICU_LIBRARIES ${lib})
        add_library(${lib} STATIC IMPORTED GLOBAL)
        if(CMAKE_CONFIGURATION_TYPES)
          foreach(c ${CMAKE_CONFIGURATION_TYPES})
            string(TOUPPER "${c}" C)
            set(debug_suffix)
            if("${C}" STREQUAL "DEBUG")
              set(lib_path ${ITKDCMTK_PREREQS}/${c}/lib/${lib_prefix}icu${lib_name}d${CMAKE_STATIC_LIBRARY_SUFFIX})
            else()  # For all non-debug, use release
              set(lib_path ${ITKDCMTK_PREREQS}/Release/lib/${lib_prefix}icu${lib_name}${CMAKE_STATIC_LIBRARY_SUFFIX})
            endif()
            set_property(TARGET ${lib} PROPERTY IMPORTED_LOCATION_${C} ${lib_path})
          endforeach()
        else()
          set(lib_path ${ITKDCMTK_PREREQS}/lib/${lib_prefix}icu${lib_name}${CMAKE_STATIC_LIBRARY_SUFFIX})
          set_property(TARGET ${lib} PROPERTY IMPORTED_LOCATION ${lib_path})
        endif()
        list(APPEND ICU_BYPRODUCTS "${lib_path}")
      endforeach()
    define_by_product(NAME icu TARGETS ${ICU_BYPRODUCTS})
    if(MSVC)
      # Create map of MD5
      set(ICU_1800_32 462079 39c597cf28f2df71baf92156d9276a4e)
      set(ICU_1800_64 462080 9f9bc9e165ce47182889a748c20028c3)
      set(ICU_1900_32 462049 86f191c160ff86e66437c23ae36c50f8)
      set(ICU_1900_64 462053 3db188b9ba24ca39a0c5d1411b591d4d)
      set(ICU_1911_32 462051 e4053721d7d11125d82df34e0a576c2a)
      set(ICU_1911_64 462048 1706884a6fb773caad3f3955747cf7db)
      ###
      # Use a compatible MSVC_VERSION version if specific version is not available.
      set(ICU_MSVC_VERSION ${MSVC_VERSION})
      if(${ICU_MSVC_VERSION} LESS 1900) # Before VS 2015, so VS 2013 and earlier
        set(version "58.2")
      else()  # VS2015 && VS2017
        set(version "59.1")
        # All MSVC versions between 1910 and 1919 (both included) are or will
        # be VS2017
        if(${ICU_MSVC_VERSION} GREATER 1909 AND ${ICU_MSVC_VERSION} LESS 1920)
          set(ICU_MSVC_VERSION 1911)
        endif()
      endif()
      string(REPLACE "." "_" version_underscore ${version})
      math(EXPR bitness "${CMAKE_SIZEOF_VOID_P} * 8")
      set(root_name "icu4c-${version_underscore}")
      set(binary_archive_name "${root_name}-install-msvc${ICU_MSVC_VERSION}-${bitness}")
      if(NOT DEFINED ICU_${ICU_MSVC_VERSION}_${bitness})
        message(FATAL_ERROR
        "Unsupported version of Visual Studio. Disable DCMTK_USE_ICU."
        )
      endif()
      list(GET ICU_${ICU_MSVC_VERSION}_${bitness} 0 item_id)
      set(ICU_URL "https://midas3.kitware.com/midas/download/bitstream/${item_id}")
      list(GET ICU_${ICU_MSVC_VERSION}${bitness} 1 ICU_MD5)
    else()
      set(ICU_URL "http://download.icu-project.org/files/icu4c/58.2/icu4c-58_2-src.tgz")
      set(ICU_MD5 fac212b32b7ec7ab007a12dff1f3aea1)
    endif()

    # If not Debug, use Release (for Release, MinSizeRel,...)
    set(ICU_ROOT_DIR ${ITKDCMTK_PREREQS}/$<$<CONFIG:Debug>:Debug>$<$<NOT:$<CONFIG:Debug>>:Release>)
    set(ICU_ARGS
      -DDCMTK_WITH_STDLIBC_ICONV:BOOL=OFF<commit_msg>COMP: update download location for pre-built ICU for Visual Studio<commit_after>project(ITKDCMTK)

set(ITKDCMTK_THIRD_PARTY 1)

# This depends on the external project, nothing locally built
set(ITKDCMTK_NO_SRC 1)

include(CMakeParseArguments)

macro(define_by_product)
  cmake_parse_arguments(BY_PRODUCT "" "NAME" "TARGETS" ${ARGN})
  if(CMAKE_VERSION VERSION_LESS 3.2)
    if("${CMAKE_GENERATOR}" STREQUAL "Ninja")
      message(FATAL_ERROR "CMake >= 3.2 required with Ninja to compile DCMTK.")
    endif()
    set(${BY_PRODUCT_NAME}_build_byproducts)
  else()
    set(${BY_PRODUCT_NAME}_build_byproducts  BUILD_BYPRODUCTS ${BY_PRODUCT_TARGETS})
  endif()
endmacro()

if(DCMTK_USE_ICU)
  option(ITK_USE_SYSTEM_ICU "Use an installed version of icu" OFF)
  if(NOT ITK_USE_SYSTEM_ICU)
    set(ITKDCMTK_PREREQS ${ITKDCMTK_BINARY_DIR}/DCMTK_Prereqs)
    set(ITKDCMTK_ICU_LIBRARIES )
    if(WIN32)
      set(ITKDCMTK_ICU_LIBRARY_NAMES uc dt)
    else()
      set(ITKDCMTK_ICU_LIBRARY_NAMES uc data)
    endif()
    foreach(lib_name ${ITKDCMTK_ICU_LIBRARY_NAMES})
      set(lib ICU::${lib_name})
        list(APPEND ITKDCMTK_ICU_LIBRARIES ${lib})
        add_library(${lib} STATIC IMPORTED GLOBAL)
        if(CMAKE_CONFIGURATION_TYPES)
          foreach(c ${CMAKE_CONFIGURATION_TYPES})
            string(TOUPPER "${c}" C)
            set(debug_suffix)
            if("${C}" STREQUAL "DEBUG")
              set(lib_path ${ITKDCMTK_PREREQS}/${c}/lib/${lib_prefix}icu${lib_name}d${CMAKE_STATIC_LIBRARY_SUFFIX})
            else()  # For all non-debug, use release
              set(lib_path ${ITKDCMTK_PREREQS}/Release/lib/${lib_prefix}icu${lib_name}${CMAKE_STATIC_LIBRARY_SUFFIX})
            endif()
            set_property(TARGET ${lib} PROPERTY IMPORTED_LOCATION_${C} ${lib_path})
          endforeach()
        else()
          set(lib_path ${ITKDCMTK_PREREQS}/lib/${lib_prefix}icu${lib_name}${CMAKE_STATIC_LIBRARY_SUFFIX})
          set_property(TARGET ${lib} PROPERTY IMPORTED_LOCATION ${lib_path})
        endif()
        list(APPEND ICU_BYPRODUCTS "${lib_path}")
      endforeach()
    define_by_product(NAME icu TARGETS ${ICU_BYPRODUCTS})
    if(MSVC)
      # Create map of SHA512/MD5 hashes
      set(ICU_1800_32 9b134c1fe8f5fcc3afe34f6a72d4c9fded776dfd33d7073861c2de32c40d4bda15ca9eb32613c262b13b479bf88bdd34658cee5505a1d9b7e3779104fd9440d3 39c597cf28f2df71baf92156d9276a4e)
      set(ICU_1800_64 023c9f1dc2469058aa4c0933d82cfdab37fc803dc86f8b936f2001f0b600ba02f8c42b695398d3ed88def6feec6b5e01561d86377a3fc582788bc35c4f9d912b 9f9bc9e165ce47182889a748c20028c3)
      set(ICU_1900_32 75cc1bb4ab6fce2df77cacb80e86be6e45d1a3bc0a7f96d5fd7193b0ddd67a2094d97626a2c59888b4374efdba7381ed3598333237b25b8bcce4777ba76731d7 86f191c160ff86e66437c23ae36c50f8)
      set(ICU_1900_64 2b200cb120c32ead26ce94aea1d531754f3c530fcb2cd26f9bf3b576c040009fdf2504376b843257a70223c8d8331359540e2ac6587004eaf9e5f7941bcf22b8 3db188b9ba24ca39a0c5d1411b591d4d)
      set(ICU_1911_32 b69569454639452c6636bc19d5e75ded119cf9a6f1f3fa8344662b481fdf7574d5ded54e7f36c69b3c752b4a1c3ea21597ae569376a888f030e6ee8d64268d0e e4053721d7d11125d82df34e0a576c2a)
      set(ICU_1911_64 462048 1706884a6fb773caad3f3955747cf7db)
      ###
      # Use a compatible MSVC_VERSION version if specific version is not available.
      set(ICU_MSVC_VERSION ${MSVC_VERSION})
      if(${ICU_MSVC_VERSION} LESS 1900) # Before VS 2015, so VS 2013 and earlier
        set(version "58.2")
      else()  # VS2015 && VS2017
        set(version "59.1")
        # All MSVC versions between 1910 and 1919 (both included) are or will
        # be VS2017
        if(${ICU_MSVC_VERSION} GREATER 1909 AND ${ICU_MSVC_VERSION} LESS 1920)
          set(ICU_MSVC_VERSION 1911)
        endif()
      endif()
      string(REPLACE "." "_" version_underscore ${version})
      math(EXPR bitness "${CMAKE_SIZEOF_VOID_P} * 8")
      set(root_name "icu4c-${version_underscore}")
      set(binary_archive_name "${root_name}-install-msvc${ICU_MSVC_VERSION}-${bitness}")
      if(NOT DEFINED ICU_${ICU_MSVC_VERSION}_${bitness})
        message(FATAL_ERROR
        "Unsupported version of Visual Studio. Disable DCMTK_USE_ICU."
        )
      endif()
      list(GET ICU_${ICU_MSVC_VERSION}_${bitness} 0 item_hash)
      set(ICU_URL "https://data.kitware.com/api/v1/file/hashsum/sha512/${item_hash}/download")
      list(GET ICU_${ICU_MSVC_VERSION}${bitness} 1 ICU_MD5)
    else()
      set(ICU_URL "http://download.icu-project.org/files/icu4c/58.2/icu4c-58_2-src.tgz")
      set(ICU_MD5 fac212b32b7ec7ab007a12dff1f3aea1)
    endif()

    # If not Debug, use Release (for Release, MinSizeRel,...)
    set(ICU_ROOT_DIR ${ITKDCMTK_PREREQS}/$<$<CONFIG:Debug>:Debug>$<$<NOT:$<CONFIG:Debug>>:Release>)
    set(ICU_ARGS
      -DDCMTK_WITH_STDLIBC_ICONV:BOOL=OFF
{'fraction_non_alphanumeric': 0.10390783826519087, 'fraction_numerical': 0.1069573074316693, 'mean_word_length': 4.124421296296297, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 15, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5922500', 'n_tokens_mistral': 4204, 'n_tokens_neox': 3492, 'n_words': 511}