Blame cmake/compat_3.7.0/FindICU.cmake

Packit 1fb8d4
# Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
Packit 1fb8d4
# file Copyright.txt or https://cmake.org/licensing for details.
Packit 1fb8d4
Packit 1fb8d4
#.rst:
Packit 1fb8d4
# FindICU
Packit 1fb8d4
# -------
Packit 1fb8d4
#
Packit 1fb8d4
# Find the International Components for Unicode (ICU) libraries and
Packit 1fb8d4
# programs.
Packit 1fb8d4
#
Packit 1fb8d4
# This module supports multiple components.
Packit 1fb8d4
# Components can include any of: ``data``, ``i18n``, ``io``, ``le``,
Packit 1fb8d4
# ``lx``, ``test``, ``tu`` and ``uc``.
Packit 1fb8d4
#
Packit 1fb8d4
# Note that on Windows ``data`` is named ``dt`` and ``i18n`` is named
Packit 1fb8d4
# ``in``; any of the names may be used, and the appropriate
Packit 1fb8d4
# platform-specific library name will be automatically selected.
Packit 1fb8d4
#
Packit 1fb8d4
# This module reports information about the ICU installation in
Packit 1fb8d4
# several variables.  General variables::
Packit 1fb8d4
#
Packit 1fb8d4
#   ICU_VERSION - ICU release version
Packit 1fb8d4
#   ICU_FOUND - true if the main programs and libraries were found
Packit 1fb8d4
#   ICU_LIBRARIES - component libraries to be linked
Packit 1fb8d4
#   ICU_INCLUDE_DIRS - the directories containing the ICU headers
Packit 1fb8d4
#
Packit 1fb8d4
# Imported targets::
Packit 1fb8d4
#
Packit 1fb8d4
#   ICU::<C>
Packit 1fb8d4
#
Packit 1fb8d4
# Where ``<C>`` is the name of an ICU component, for example
Packit 1fb8d4
# ``ICU::i18n``.
Packit 1fb8d4
#
Packit 1fb8d4
# ICU programs are reported in::
Packit 1fb8d4
#
Packit 1fb8d4
#   ICU_GENCNVAL_EXECUTABLE - path to gencnval executable
Packit 1fb8d4
#   ICU_ICUINFO_EXECUTABLE - path to icuinfo executable
Packit 1fb8d4
#   ICU_GENBRK_EXECUTABLE - path to genbrk executable
Packit 1fb8d4
#   ICU_ICU-CONFIG_EXECUTABLE - path to icu-config executable
Packit 1fb8d4
#   ICU_GENRB_EXECUTABLE - path to genrb executable
Packit 1fb8d4
#   ICU_GENDICT_EXECUTABLE - path to gendict executable
Packit 1fb8d4
#   ICU_DERB_EXECUTABLE - path to derb executable
Packit 1fb8d4
#   ICU_PKGDATA_EXECUTABLE - path to pkgdata executable
Packit 1fb8d4
#   ICU_UCONV_EXECUTABLE - path to uconv executable
Packit 1fb8d4
#   ICU_GENCFU_EXECUTABLE - path to gencfu executable
Packit 1fb8d4
#   ICU_MAKECONV_EXECUTABLE - path to makeconv executable
Packit 1fb8d4
#   ICU_GENNORM2_EXECUTABLE - path to gennorm2 executable
Packit 1fb8d4
#   ICU_GENCCODE_EXECUTABLE - path to genccode executable
Packit 1fb8d4
#   ICU_GENSPREP_EXECUTABLE - path to gensprep executable
Packit 1fb8d4
#   ICU_ICUPKG_EXECUTABLE - path to icupkg executable
Packit 1fb8d4
#   ICU_GENCMN_EXECUTABLE - path to gencmn executable
Packit 1fb8d4
#
Packit 1fb8d4
# ICU component libraries are reported in::
Packit 1fb8d4
#
Packit 1fb8d4
#   ICU_<C>_FOUND - ON if component was found
Packit 1fb8d4
#   ICU_<C>_LIBRARIES - libraries for component
Packit 1fb8d4
#
Packit 1fb8d4
# Note that ``<C>`` is the uppercased name of the component.
Packit 1fb8d4
#
Packit 1fb8d4
# This module reads hints about search results from::
Packit 1fb8d4
#
Packit 1fb8d4
#   ICU_ROOT - the root of the ICU installation
Packit 1fb8d4
#
Packit 1fb8d4
# The environment variable ``ICU_ROOT`` may also be used; the
Packit 1fb8d4
# ICU_ROOT variable takes precedence.
Packit 1fb8d4
#
Packit 1fb8d4
# The following cache variables may also be set::
Packit 1fb8d4
#
Packit 1fb8d4
#   ICU_

_EXECUTABLE - the path to executable

Packit 1fb8d4
#   ICU_INCLUDE_DIR - the directory containing the ICU headers
Packit 1fb8d4
#   ICU_<C>_LIBRARY - the library for component <C>
Packit 1fb8d4
#
Packit 1fb8d4
# .. note::
Packit 1fb8d4
#
Packit 1fb8d4
#   In most cases none of the above variables will require setting,
Packit 1fb8d4
#   unless multiple ICU versions are available and a specific version
Packit 1fb8d4
#   is required.
Packit 1fb8d4
#
Packit 1fb8d4
# Other variables one may set to control this module are::
Packit 1fb8d4
#
Packit 1fb8d4
#   ICU_DEBUG - Set to ON to enable debug output from FindICU.
Packit 1fb8d4
Packit 1fb8d4
# Written by Roger Leigh <rleigh@codelibre.net>
Packit 1fb8d4
Packit 1fb8d4
set(icu_programs
Packit 1fb8d4
  gencnval
Packit 1fb8d4
  icuinfo
Packit 1fb8d4
  genbrk
Packit 1fb8d4
  icu-config
Packit 1fb8d4
  genrb
Packit 1fb8d4
  gendict
Packit 1fb8d4
  derb
Packit 1fb8d4
  pkgdata
Packit 1fb8d4
  uconv
Packit 1fb8d4
  gencfu
Packit 1fb8d4
  makeconv
Packit 1fb8d4
  gennorm2
Packit 1fb8d4
  genccode
Packit 1fb8d4
  gensprep
Packit 1fb8d4
  icupkg
Packit 1fb8d4
  gencmn)
Packit 1fb8d4
Packit 1fb8d4
# The ICU checks are contained in a function due to the large number
Packit 1fb8d4
# of temporary variables needed.
Packit 1fb8d4
function(_ICU_FIND)
Packit 1fb8d4
  # Set up search paths, taking compiler into account.  Search ICU_ROOT,
Packit 1fb8d4
  # with ICU_ROOT in the environment as a fallback if unset.
Packit 1fb8d4
  if(ICU_ROOT)
Packit 1fb8d4
    list(APPEND icu_roots "${ICU_ROOT}")
Packit 1fb8d4
  else()
Packit 1fb8d4
    if(NOT "$ENV{ICU_ROOT}" STREQUAL "")
Packit 1fb8d4
      file(TO_CMAKE_PATH "$ENV{ICU_ROOT}" NATIVE_PATH)
Packit 1fb8d4
      list(APPEND icu_roots "${NATIVE_PATH}")
Packit 1fb8d4
      set(ICU_ROOT "${NATIVE_PATH}"
Packit 1fb8d4
          CACHE PATH "Location of the ICU installation" FORCE)
Packit 1fb8d4
    endif()
Packit 1fb8d4
  endif()
Packit 1fb8d4
Packit 1fb8d4
  if(CMAKE_SIZEOF_VOID_P EQUAL 8)
Packit 1fb8d4
    # 64-bit binary directory
Packit 1fb8d4
    set(_bin64 "bin64")
Packit 1fb8d4
    # 64-bit library directory
Packit 1fb8d4
    set(_lib64 "lib64")
Packit 1fb8d4
  endif()
Packit 1fb8d4
Packit 1fb8d4
  # Generic 64-bit and 32-bit directories
Packit 1fb8d4
  list(APPEND icu_binary_suffixes "${_bin64}" "bin")
Packit 1fb8d4
  list(APPEND icu_library_suffixes "${_lib64}" "lib")
Packit 1fb8d4
Packit 1fb8d4
  # Find all ICU programs
Packit 1fb8d4
  foreach(program ${icu_programs})
Packit 1fb8d4
    string(TOUPPER "${program}" program_upcase)
Packit 1fb8d4
    set(cache_var "ICU_${program_upcase}_EXECUTABLE")
Packit 1fb8d4
    set(program_var "ICU_${program_upcase}_EXECUTABLE")
Packit 1fb8d4
    find_program("${cache_var}" "${program}"
Packit 1fb8d4
      HINTS ${icu_roots}
Packit 1fb8d4
      PATH_SUFFIXES ${icu_binary_suffixes}
Packit 1fb8d4
      DOC "ICU ${program} executable")
Packit 1fb8d4
    mark_as_advanced(cache_var)
Packit 1fb8d4
    set("${program_var}" "${${cache_var}}" PARENT_SCOPE)
Packit 1fb8d4
  endforeach()
Packit 1fb8d4
Packit 1fb8d4
  # Find include directory
Packit 1fb8d4
  find_path(ICU_INCLUDE_DIR
Packit 1fb8d4
            NAMES "unicode/utypes.h"
Packit 1fb8d4
            HINTS ${icu_roots}
Packit 1fb8d4
            PATH_SUFFIXES ${icu_include_suffixes}
Packit 1fb8d4
            DOC "ICU include directory")
Packit 1fb8d4
  set(ICU_INCLUDE_DIR "${ICU_INCLUDE_DIR}" PARENT_SCOPE)
Packit 1fb8d4
Packit 1fb8d4
  # Get version
Packit 1fb8d4
  if(ICU_INCLUDE_DIR AND EXISTS "${ICU_INCLUDE_DIR}/unicode/uvernum.h")
Packit 1fb8d4
    file(STRINGS "${ICU_INCLUDE_DIR}/unicode/uvernum.h" icu_header_str
Packit 1fb8d4
      REGEX "^#define[\t ]+U_ICU_VERSION[\t ]+\".*\".*")
Packit 1fb8d4
Packit 1fb8d4
    string(REGEX REPLACE "^#define[\t ]+U_ICU_VERSION[\t ]+\"([^ \\n]*)\".*"
Packit 1fb8d4
      "\\1" icu_version_string "${icu_header_str}")
Packit 1fb8d4
    set(ICU_VERSION "${icu_version_string}" PARENT_SCOPE)
Packit 1fb8d4
    unset(icu_header_str)
Packit 1fb8d4
    unset(icu_version_string)
Packit 1fb8d4
  endif()
Packit 1fb8d4
Packit 1fb8d4
  # Find all ICU libraries
Packit 1fb8d4
  set(ICU_REQUIRED_LIBS_FOUND ON)
Packit 1fb8d4
  foreach(component ${ICU_FIND_COMPONENTS})
Packit 1fb8d4
    string(TOUPPER "${component}" component_upcase)
Packit 1fb8d4
    set(component_cache "ICU_${component_upcase}_LIBRARY")
Packit 1fb8d4
    set(component_cache_release "${component_cache}_RELEASE")
Packit 1fb8d4
    set(component_cache_debug "${component_cache}_DEBUG")
Packit 1fb8d4
    set(component_found "${component_upcase}_FOUND")
Packit 1fb8d4
    set(component_libnames "icu${component}")
Packit 1fb8d4
    set(component_debug_libnames "icu${component}d")
Packit 1fb8d4
Packit 1fb8d4
    # Special case deliberate library naming mismatches between Unix
Packit 1fb8d4
    # and Windows builds
Packit 1fb8d4
    unset(component_libnames)
Packit 1fb8d4
    unset(component_debug_libnames)
Packit 1fb8d4
    list(APPEND component_libnames "icu${component}")
Packit 1fb8d4
    list(APPEND component_debug_libnames "icu${component}d")
Packit 1fb8d4
    if(component STREQUAL "data")
Packit 1fb8d4
      list(APPEND component_libnames "icudt")
Packit 1fb8d4
      # Note there is no debug variant at present
Packit 1fb8d4
      list(APPEND component_debug_libnames "icudtd")
Packit 1fb8d4
    endif()
Packit 1fb8d4
    if(component STREQUAL "dt")
Packit 1fb8d4
      list(APPEND component_libnames "icudata")
Packit 1fb8d4
      # Note there is no debug variant at present
Packit 1fb8d4
      list(APPEND component_debug_libnames "icudatad")
Packit 1fb8d4
    endif()
Packit 1fb8d4
    if(component STREQUAL "i18n")
Packit 1fb8d4
      list(APPEND component_libnames "icuin")
Packit 1fb8d4
      list(APPEND component_debug_libnames "icuind")
Packit 1fb8d4
    endif()
Packit 1fb8d4
    if(component STREQUAL "in")
Packit 1fb8d4
      list(APPEND component_libnames "icui18n")
Packit 1fb8d4
      list(APPEND component_debug_libnames "icui18nd")
Packit 1fb8d4
    endif()
Packit 1fb8d4
Packit 1fb8d4
    find_library("${component_cache_release}" ${component_libnames}
Packit 1fb8d4
      HINTS ${icu_roots}
Packit 1fb8d4
      PATH_SUFFIXES ${icu_library_suffixes}
Packit 1fb8d4
      DOC "ICU ${component} library (release)")
Packit 1fb8d4
    find_library("${component_cache_debug}" ${component_debug_libnames}
Packit 1fb8d4
      HINTS ${icu_roots}
Packit 1fb8d4
      PATH_SUFFIXES ${icu_library_suffixes}
Packit 1fb8d4
      DOC "ICU ${component} library (debug)")
Packit 1fb8d4
    include(SelectLibraryConfigurations)
Packit 1fb8d4
    select_library_configurations(ICU_${component_upcase})
Packit 1fb8d4
    mark_as_advanced("${component_cache_release}" "${component_cache_debug}")
Packit 1fb8d4
    if(${component_cache})
Packit 1fb8d4
      set("${component_found}" ON)
Packit 1fb8d4
      list(APPEND ICU_LIBRARY "${${component_cache}}")
Packit 1fb8d4
    endif()
Packit 1fb8d4
    mark_as_advanced("${component_found}")
Packit 1fb8d4
    set("${component_cache}" "${${component_cache}}" PARENT_SCOPE)
Packit 1fb8d4
    set("${component_found}" "${${component_found}}" PARENT_SCOPE)
Packit 1fb8d4
    if(${component_found})
Packit 1fb8d4
      if (ICU_FIND_REQUIRED_${component})
Packit 1fb8d4
        list(APPEND ICU_LIBS_FOUND "${component} (required)")
Packit 1fb8d4
      else()
Packit 1fb8d4
        list(APPEND ICU_LIBS_FOUND "${component} (optional)")
Packit 1fb8d4
      endif()
Packit 1fb8d4
    else()
Packit 1fb8d4
      if (ICU_FIND_REQUIRED_${component})
Packit 1fb8d4
        set(ICU_REQUIRED_LIBS_FOUND OFF)
Packit 1fb8d4
        list(APPEND ICU_LIBS_NOTFOUND "${component} (required)")
Packit 1fb8d4
      else()
Packit 1fb8d4
        list(APPEND ICU_LIBS_NOTFOUND "${component} (optional)")
Packit 1fb8d4
      endif()
Packit 1fb8d4
    endif()
Packit 1fb8d4
  endforeach()
Packit 1fb8d4
  set(_ICU_REQUIRED_LIBS_FOUND "${ICU_REQUIRED_LIBS_FOUND}" PARENT_SCOPE)
Packit 1fb8d4
  set(ICU_LIBRARY "${ICU_LIBRARY}" PARENT_SCOPE)
Packit 1fb8d4
Packit 1fb8d4
  if(NOT ICU_FIND_QUIETLY)
Packit 1fb8d4
    if(ICU_LIBS_FOUND)
Packit 1fb8d4
      message(STATUS "Found the following ICU libraries:")
Packit 1fb8d4
      foreach(found ${ICU_LIBS_FOUND})
Packit 1fb8d4
        message(STATUS "  ${found}")
Packit 1fb8d4
      endforeach()
Packit 1fb8d4
    endif()
Packit 1fb8d4
    if(ICU_LIBS_NOTFOUND)
Packit 1fb8d4
      message(STATUS "The following ICU libraries were not found:")
Packit 1fb8d4
      foreach(notfound ${ICU_LIBS_NOTFOUND})
Packit 1fb8d4
        message(STATUS "  ${notfound}")
Packit 1fb8d4
      endforeach()
Packit 1fb8d4
    endif()
Packit 1fb8d4
  endif()
Packit 1fb8d4
Packit 1fb8d4
  if(ICU_DEBUG)
Packit 1fb8d4
    message(STATUS "--------FindICU.cmake search debug--------")
Packit 1fb8d4
    message(STATUS "ICU binary path search order: ${icu_roots}")
Packit 1fb8d4
    message(STATUS "ICU include path search order: ${icu_roots}")
Packit 1fb8d4
    message(STATUS "ICU library path search order: ${icu_roots}")
Packit 1fb8d4
    message(STATUS "----------------")
Packit 1fb8d4
  endif()
Packit 1fb8d4
endfunction()
Packit 1fb8d4
Packit 1fb8d4
_ICU_FIND()
Packit 1fb8d4
Packit 1fb8d4
include(FindPackageHandleStandardArgs)
Packit 1fb8d4
FIND_PACKAGE_HANDLE_STANDARD_ARGS(ICU
Packit 1fb8d4
                                  FOUND_VAR ICU_FOUND
Packit 1fb8d4
                                  REQUIRED_VARS ICU_INCLUDE_DIR
Packit 1fb8d4
                                                ICU_LIBRARY
Packit 1fb8d4
                                                _ICU_REQUIRED_LIBS_FOUND
Packit 1fb8d4
                                  VERSION_VAR ICU_VERSION
Packit 1fb8d4
                                  FAIL_MESSAGE "Failed to find all ICU components")
Packit 1fb8d4
Packit 1fb8d4
unset(_ICU_REQUIRED_LIBS_FOUND)
Packit 1fb8d4
Packit 1fb8d4
if(ICU_FOUND)
Packit 1fb8d4
  set(ICU_INCLUDE_DIRS "${ICU_INCLUDE_DIR}")
Packit 1fb8d4
  set(ICU_LIBRARIES "${ICU_LIBRARY}")
Packit 1fb8d4
  foreach(_ICU_component ${ICU_FIND_COMPONENTS})
Packit 1fb8d4
    string(TOUPPER "${_ICU_component}" _ICU_component_upcase)
Packit 1fb8d4
    set(_ICU_component_cache "ICU_${_ICU_component_upcase}_LIBRARY")
Packit 1fb8d4
    set(_ICU_component_cache_release "ICU_${_ICU_component_upcase}_LIBRARY_RELEASE")
Packit 1fb8d4
    set(_ICU_component_cache_debug "ICU_${_ICU_component_upcase}_LIBRARY_DEBUG")
Packit 1fb8d4
    set(_ICU_component_lib "ICU_${_ICU_component_upcase}_LIBRARIES")
Packit 1fb8d4
    set(_ICU_component_found "${_ICU_component_upcase}_FOUND")
Packit 1fb8d4
    set(_ICU_imported_target "ICU::${_ICU_component}")
Packit 1fb8d4
    if(${_ICU_component_found})
Packit 1fb8d4
      set("${_ICU_component_lib}" "${${_ICU_component_cache}}")
Packit 1fb8d4
      if(NOT TARGET ${_ICU_imported_target})
Packit 1fb8d4
        add_library(${_ICU_imported_target} UNKNOWN IMPORTED)
Packit 1fb8d4
        if(ICU_INCLUDE_DIR)
Packit 1fb8d4
          set_target_properties(${_ICU_imported_target} PROPERTIES
Packit 1fb8d4
            INTERFACE_INCLUDE_DIRECTORIES "${ICU_INCLUDE_DIR}")
Packit 1fb8d4
        endif()
Packit 1fb8d4
        if(EXISTS "${${_ICU_component_cache}}")
Packit 1fb8d4
          set_target_properties(${_ICU_imported_target} PROPERTIES
Packit 1fb8d4
            IMPORTED_LINK_INTERFACE_LANGUAGES "CXX"
Packit 1fb8d4
            IMPORTED_LOCATION "${${_ICU_component_cache}}")
Packit 1fb8d4
        endif()
Packit 1fb8d4
        if(EXISTS "${${_ICU_component_cache_release}}")
Packit 1fb8d4
          set_property(TARGET ${_ICU_imported_target} APPEND PROPERTY
Packit 1fb8d4
            IMPORTED_CONFIGURATIONS RELEASE)
Packit 1fb8d4
          set_target_properties(${_ICU_imported_target} PROPERTIES
Packit 1fb8d4
            IMPORTED_LINK_INTERFACE_LANGUAGES_RELEASE "CXX"
Packit 1fb8d4
            IMPORTED_LOCATION_RELEASE "${${_ICU_component_cache_release}}")
Packit 1fb8d4
        endif()
Packit 1fb8d4
        if(EXISTS "${${_ICU_component_cache_debug}}")
Packit 1fb8d4
          set_property(TARGET ${_ICU_imported_target} APPEND PROPERTY
Packit 1fb8d4
            IMPORTED_CONFIGURATIONS DEBUG)
Packit 1fb8d4
          set_target_properties(${_ICU_imported_target} PROPERTIES
Packit 1fb8d4
            IMPORTED_LINK_INTERFACE_LANGUAGES_DEBUG "CXX"
Packit 1fb8d4
            IMPORTED_LOCATION_DEBUG "${${_ICU_component_cache_debug}}")
Packit 1fb8d4
        endif()
Packit 1fb8d4
      endif()
Packit 1fb8d4
    endif()
Packit 1fb8d4
    unset(_ICU_component_upcase)
Packit 1fb8d4
    unset(_ICU_component_cache)
Packit 1fb8d4
    unset(_ICU_component_lib)
Packit 1fb8d4
    unset(_ICU_component_found)
Packit 1fb8d4
    unset(_ICU_imported_target)
Packit 1fb8d4
  endforeach()
Packit 1fb8d4
endif()
Packit 1fb8d4
Packit 1fb8d4
if(ICU_DEBUG)
Packit 1fb8d4
  message(STATUS "--------FindICU.cmake results debug--------")
Packit 1fb8d4
  message(STATUS "ICU found: ${ICU_FOUND}")
Packit 1fb8d4
  message(STATUS "ICU_VERSION number: ${ICU_VERSION}")
Packit 1fb8d4
  message(STATUS "ICU_ROOT directory: ${ICU_ROOT}")
Packit 1fb8d4
  message(STATUS "ICU_INCLUDE_DIR directory: ${ICU_INCLUDE_DIR}")
Packit 1fb8d4
  message(STATUS "ICU_LIBRARIES: ${ICU_LIBRARIES}")
Packit 1fb8d4
Packit 1fb8d4
  foreach(program IN LISTS icu_programs)
Packit 1fb8d4
    string(TOUPPER "${program}" program_upcase)
Packit 1fb8d4
    set(program_lib "ICU_${program_upcase}_EXECUTABLE")
Packit 1fb8d4
    message(STATUS "${program} program: ${${program_lib}}")
Packit 1fb8d4
    unset(program_upcase)
Packit 1fb8d4
    unset(program_lib)
Packit 1fb8d4
  endforeach()
Packit 1fb8d4
Packit 1fb8d4
  foreach(component IN LISTS ICU_FIND_COMPONENTS)
Packit 1fb8d4
    string(TOUPPER "${component}" component_upcase)
Packit 1fb8d4
    set(component_lib "ICU_${component_upcase}_LIBRARIES")
Packit 1fb8d4
    set(component_found "${component_upcase}_FOUND")
Packit 1fb8d4
    message(STATUS "${component} library found: ${${component_found}}")
Packit 1fb8d4
    message(STATUS "${component} library: ${${component_lib}}")
Packit 1fb8d4
    unset(component_upcase)
Packit 1fb8d4
    unset(component_lib)
Packit 1fb8d4
    unset(component_found)
Packit 1fb8d4
  endforeach()
Packit 1fb8d4
  message(STATUS "----------------")
Packit 1fb8d4
endif()
Packit 1fb8d4
Packit 1fb8d4
unset(icu_programs)