Warning, /libraries/kdb/cmake/modules/FindICU.cmake is written in an unsupported language. File is not indexed.
0001 # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
0002 # file Copyright.txt or https://cmake.org/licensing for details.
0003
0004 #.rst:
0005 # FindICU
0006 # -------
0007 #
0008 # Find the International Components for Unicode (ICU) libraries and
0009 # programs.
0010 #
0011 # This module supports multiple components.
0012 # Components can include any of: ``data``, ``i18n``, ``io``, ``le``,
0013 # ``lx``, ``test``, ``tu`` and ``uc``.
0014 #
0015 # Note that on Windows ``data`` is named ``dt`` and ``i18n`` is named
0016 # ``in``; any of the names may be used, and the appropriate
0017 # platform-specific library name will be automatically selected.
0018 #
0019 # This module reports information about the ICU installation in
0020 # several variables. General variables::
0021 #
0022 # ICU_VERSION - ICU release version
0023 # ICU_FOUND - true if the main programs and libraries were found
0024 # ICU_LIBRARIES - component libraries to be linked
0025 # ICU_INCLUDE_DIRS - the directories containing the ICU headers
0026 #
0027 # Imported targets::
0028 #
0029 # ICU::<C>
0030 #
0031 # Where ``<C>`` is the name of an ICU component, for example
0032 # ``ICU::i18n``.
0033 #
0034 # ICU programs are reported in::
0035 #
0036 # ICU_GENCNVAL_EXECUTABLE - path to gencnval executable
0037 # ICU_ICUINFO_EXECUTABLE - path to icuinfo executable
0038 # ICU_GENBRK_EXECUTABLE - path to genbrk executable
0039 # ICU_ICU-CONFIG_EXECUTABLE - path to icu-config executable
0040 # ICU_GENRB_EXECUTABLE - path to genrb executable
0041 # ICU_GENDICT_EXECUTABLE - path to gendict executable
0042 # ICU_DERB_EXECUTABLE - path to derb executable
0043 # ICU_PKGDATA_EXECUTABLE - path to pkgdata executable
0044 # ICU_UCONV_EXECUTABLE - path to uconv executable
0045 # ICU_GENCFU_EXECUTABLE - path to gencfu executable
0046 # ICU_MAKECONV_EXECUTABLE - path to makeconv executable
0047 # ICU_GENNORM2_EXECUTABLE - path to gennorm2 executable
0048 # ICU_GENCCODE_EXECUTABLE - path to genccode executable
0049 # ICU_GENSPREP_EXECUTABLE - path to gensprep executable
0050 # ICU_ICUPKG_EXECUTABLE - path to icupkg executable
0051 # ICU_GENCMN_EXECUTABLE - path to gencmn executable
0052 #
0053 # ICU component libraries are reported in::
0054 #
0055 # ICU_<C>_FOUND - ON if component was found
0056 # ICU_<C>_LIBRARIES - libraries for component
0057 #
0058 # ICU datafiles are reported in::
0059 #
0060 # ICU_MAKEFILE_INC - Makefile.inc
0061 # ICU_PKGDATA_INC - pkgdata.inc
0062 #
0063 # Note that ``<C>`` is the uppercased name of the component.
0064 #
0065 # This module reads hints about search results from::
0066 #
0067 # ICU_ROOT - the root of the ICU installation
0068 #
0069 # The environment variable ``ICU_ROOT`` may also be used; the
0070 # ICU_ROOT variable takes precedence.
0071 #
0072 # The following cache variables may also be set::
0073 #
0074 # ICU_<P>_EXECUTABLE - the path to executable <P>
0075 # ICU_INCLUDE_DIR - the directory containing the ICU headers
0076 # ICU_<C>_LIBRARY - the library for component <C>
0077 #
0078 # .. note::
0079 #
0080 # In most cases none of the above variables will require setting,
0081 # unless multiple ICU versions are available and a specific version
0082 # is required.
0083 #
0084 # Other variables one may set to control this module are::
0085 #
0086 # ICU_DEBUG - Set to ON to enable debug output from FindICU.
0087
0088 # Written by Roger Leigh <rleigh@codelibre.net>
0089
0090 set(icu_programs
0091 gencnval
0092 icuinfo
0093 genbrk
0094 icu-config
0095 genrb
0096 gendict
0097 derb
0098 pkgdata
0099 uconv
0100 gencfu
0101 makeconv
0102 gennorm2
0103 genccode
0104 gensprep
0105 icupkg
0106 gencmn)
0107
0108 set(icu_data
0109 Makefile.inc
0110 pkgdata.inc)
0111
0112 # The ICU checks are contained in a function due to the large number
0113 # of temporary variables needed.
0114 function(_ICU_FIND)
0115 # Set up search paths, taking compiler into account. Search ICU_ROOT,
0116 # with ICU_ROOT in the environment as a fallback if unset.
0117 if(ICU_ROOT)
0118 list(APPEND icu_roots "${ICU_ROOT}")
0119 else()
0120 if(NOT "$ENV{ICU_ROOT}" STREQUAL "")
0121 file(TO_CMAKE_PATH "$ENV{ICU_ROOT}" NATIVE_PATH)
0122 list(APPEND icu_roots "${NATIVE_PATH}")
0123 set(ICU_ROOT "${NATIVE_PATH}"
0124 CACHE PATH "Location of the ICU installation" FORCE)
0125 endif()
0126 endif()
0127
0128 # Find include directory
0129 list(APPEND icu_include_suffixes "include")
0130 find_path(ICU_INCLUDE_DIR
0131 NAMES "unicode/utypes.h"
0132 HINTS ${icu_roots}
0133 PATH_SUFFIXES ${icu_include_suffixes}
0134 DOC "ICU include directory")
0135 set(ICU_INCLUDE_DIR "${ICU_INCLUDE_DIR}" PARENT_SCOPE)
0136
0137 # Get version
0138 if(ICU_INCLUDE_DIR AND EXISTS "${ICU_INCLUDE_DIR}/unicode/uvernum.h")
0139 file(STRINGS "${ICU_INCLUDE_DIR}/unicode/uvernum.h" icu_header_str
0140 REGEX "^#define[\t ]+U_ICU_VERSION[\t ]+\".*\".*")
0141
0142 string(REGEX REPLACE "^#define[\t ]+U_ICU_VERSION[\t ]+\"([^ \\n]*)\".*"
0143 "\\1" icu_version_string "${icu_header_str}")
0144 set(ICU_VERSION "${icu_version_string}")
0145 set(ICU_VERSION "${icu_version_string}" PARENT_SCOPE)
0146 unset(icu_header_str)
0147 unset(icu_version_string)
0148 endif()
0149
0150 if(CMAKE_SIZEOF_VOID_P EQUAL 8)
0151 # 64-bit binary directory
0152 set(_bin64 "bin64")
0153 # 64-bit library directory
0154 set(_lib64 "lib64")
0155 endif()
0156
0157
0158 # Find all ICU programs
0159 list(APPEND icu_binary_suffixes "${_bin64}" "bin")
0160 foreach(program ${icu_programs})
0161 string(TOUPPER "${program}" program_upcase)
0162 set(cache_var "ICU_${program_upcase}_EXECUTABLE")
0163 set(program_var "ICU_${program_upcase}_EXECUTABLE")
0164 find_program("${cache_var}" "${program}"
0165 HINTS ${icu_roots}
0166 PATH_SUFFIXES ${icu_binary_suffixes}
0167 DOC "ICU ${program} executable")
0168 mark_as_advanced(cache_var)
0169 set("${program_var}" "${${cache_var}}" PARENT_SCOPE)
0170 endforeach()
0171
0172 # Find all ICU libraries
0173 list(APPEND icu_library_suffixes "${_lib64}" "lib")
0174 set(ICU_REQUIRED_LIBS_FOUND ON)
0175 foreach(component ${ICU_FIND_COMPONENTS})
0176 string(TOUPPER "${component}" component_upcase)
0177 set(component_cache "ICU_${component_upcase}_LIBRARY")
0178 set(component_cache_release "${component_cache}_RELEASE")
0179 set(component_cache_debug "${component_cache}_DEBUG")
0180 set(component_found "${component_upcase}_FOUND")
0181 set(component_libnames "icu${component}")
0182 set(component_debug_libnames "icu${component}d")
0183
0184 # Special case deliberate library naming mismatches between Unix
0185 # and Windows builds
0186 unset(component_libnames)
0187 unset(component_debug_libnames)
0188 list(APPEND component_libnames "icu${component}")
0189 list(APPEND component_debug_libnames "icu${component}d")
0190 if(component STREQUAL "data")
0191 list(APPEND component_libnames "icudt")
0192 # Note there is no debug variant at present
0193 list(APPEND component_debug_libnames "icudtd")
0194 endif()
0195 if(component STREQUAL "dt")
0196 list(APPEND component_libnames "icudata")
0197 # Note there is no debug variant at present
0198 list(APPEND component_debug_libnames "icudatad")
0199 endif()
0200 if(component STREQUAL "i18n")
0201 list(APPEND component_libnames "icuin")
0202 list(APPEND component_debug_libnames "icuind")
0203 endif()
0204 if(component STREQUAL "in")
0205 list(APPEND component_libnames "icui18n")
0206 list(APPEND component_debug_libnames "icui18nd")
0207 endif()
0208
0209 find_library("${component_cache_release}" ${component_libnames}
0210 HINTS ${icu_roots}
0211 PATH_SUFFIXES ${icu_library_suffixes}
0212 DOC "ICU ${component} library (release)")
0213 find_library("${component_cache_debug}" ${component_debug_libnames}
0214 HINTS ${icu_roots}
0215 PATH_SUFFIXES ${icu_library_suffixes}
0216 DOC "ICU ${component} library (debug)")
0217 include(${CMAKE_CURRENT_LIST_DIR}/SelectLibraryConfigurations.cmake)
0218 select_library_configurations(ICU_${component_upcase})
0219 mark_as_advanced("${component_cache_release}" "${component_cache_debug}")
0220 if(${component_cache})
0221 set("${component_found}" ON)
0222 list(APPEND ICU_LIBRARY "${${component_cache}}")
0223 endif()
0224 mark_as_advanced("${component_found}")
0225 set("${component_cache}" "${${component_cache}}" PARENT_SCOPE)
0226 set("${component_found}" "${${component_found}}" PARENT_SCOPE)
0227 if(${component_found})
0228 if (ICU_FIND_REQUIRED_${component})
0229 list(APPEND ICU_LIBS_FOUND "${component} (required)")
0230 else()
0231 list(APPEND ICU_LIBS_FOUND "${component} (optional)")
0232 endif()
0233 else()
0234 if (ICU_FIND_REQUIRED_${component})
0235 set(ICU_REQUIRED_LIBS_FOUND OFF)
0236 list(APPEND ICU_LIBS_NOTFOUND "${component} (required)")
0237 else()
0238 list(APPEND ICU_LIBS_NOTFOUND "${component} (optional)")
0239 endif()
0240 endif()
0241 endforeach()
0242 set(_ICU_REQUIRED_LIBS_FOUND "${ICU_REQUIRED_LIBS_FOUND}" PARENT_SCOPE)
0243 set(ICU_LIBRARY "${ICU_LIBRARY}" PARENT_SCOPE)
0244
0245 # Find all ICU data files
0246 if(CMAKE_LIBRARY_ARCHITECTURE)
0247 list(APPEND icu_data_suffixes
0248 "${_lib64}/${CMAKE_LIBRARY_ARCHITECTURE}/icu/${ICU_VERSION}"
0249 "lib/${CMAKE_LIBRARY_ARCHITECTURE}/icu/${ICU_VERSION}"
0250 "${_lib64}/${CMAKE_LIBRARY_ARCHITECTURE}/icu"
0251 "lib/${CMAKE_LIBRARY_ARCHITECTURE}/icu")
0252 endif()
0253 list(APPEND icu_data_suffixes
0254 "${_lib64}/icu/${ICU_VERSION}"
0255 "lib/icu/${ICU_VERSION}"
0256 "${_lib64}/icu"
0257 "lib/icu")
0258 foreach(data ${icu_data})
0259 string(TOUPPER "${data}" data_upcase)
0260 string(REPLACE "." "_" data_upcase "${data_upcase}")
0261 set(cache_var "ICU_${data_upcase}")
0262 set(data_var "ICU_${data_upcase}")
0263 find_file("${cache_var}" "${data}"
0264 HINTS ${icu_roots}
0265 PATH_SUFFIXES ${icu_data_suffixes}
0266 DOC "ICU ${data} data file")
0267 mark_as_advanced(cache_var)
0268 set("${data_var}" "${${cache_var}}" PARENT_SCOPE)
0269 endforeach()
0270
0271 if(NOT ICU_FIND_QUIETLY)
0272 if(ICU_LIBS_FOUND)
0273 message(STATUS "Found the following ICU libraries:")
0274 foreach(found ${ICU_LIBS_FOUND})
0275 message(STATUS " ${found}")
0276 endforeach()
0277 endif()
0278 if(ICU_LIBS_NOTFOUND)
0279 message(STATUS "The following ICU libraries were not found:")
0280 foreach(notfound ${ICU_LIBS_NOTFOUND})
0281 message(STATUS " ${notfound}")
0282 endforeach()
0283 endif()
0284 endif()
0285
0286 if(ICU_DEBUG)
0287 message(STATUS "--------FindICU.cmake search debug--------")
0288 message(STATUS "ICU binary path search order: ${icu_roots}")
0289 message(STATUS "ICU include path search order: ${icu_roots}")
0290 message(STATUS "ICU library path search order: ${icu_roots}")
0291 message(STATUS "----------------")
0292 endif()
0293 endfunction()
0294
0295 _ICU_FIND()
0296
0297 include(FindPackageHandleStandardArgs)
0298 FIND_PACKAGE_HANDLE_STANDARD_ARGS(ICU
0299 FOUND_VAR ICU_FOUND
0300 REQUIRED_VARS ICU_INCLUDE_DIR
0301 ICU_LIBRARY
0302 _ICU_REQUIRED_LIBS_FOUND
0303 VERSION_VAR ICU_VERSION
0304 FAIL_MESSAGE "Failed to find all ICU components")
0305
0306 unset(_ICU_REQUIRED_LIBS_FOUND)
0307
0308 if(ICU_FOUND)
0309 set(ICU_INCLUDE_DIRS "${ICU_INCLUDE_DIR}")
0310 set(ICU_LIBRARIES "${ICU_LIBRARY}")
0311 foreach(_ICU_component ${ICU_FIND_COMPONENTS})
0312 string(TOUPPER "${_ICU_component}" _ICU_component_upcase)
0313 set(_ICU_component_cache "ICU_${_ICU_component_upcase}_LIBRARY")
0314 set(_ICU_component_cache_release "ICU_${_ICU_component_upcase}_LIBRARY_RELEASE")
0315 set(_ICU_component_cache_debug "ICU_${_ICU_component_upcase}_LIBRARY_DEBUG")
0316 set(_ICU_component_lib "ICU_${_ICU_component_upcase}_LIBRARIES")
0317 set(_ICU_component_found "${_ICU_component_upcase}_FOUND")
0318 set(_ICU_imported_target "ICU::${_ICU_component}")
0319 if(${_ICU_component_found})
0320 set("${_ICU_component_lib}" "${${_ICU_component_cache}}")
0321 if(NOT TARGET ${_ICU_imported_target})
0322 add_library(${_ICU_imported_target} UNKNOWN IMPORTED)
0323 if(ICU_INCLUDE_DIR)
0324 set_target_properties(${_ICU_imported_target} PROPERTIES
0325 INTERFACE_INCLUDE_DIRECTORIES "${ICU_INCLUDE_DIR}")
0326 endif()
0327 if(EXISTS "${${_ICU_component_cache}}")
0328 set_target_properties(${_ICU_imported_target} PROPERTIES
0329 IMPORTED_LINK_INTERFACE_LANGUAGES "CXX"
0330 IMPORTED_LOCATION "${${_ICU_component_cache}}")
0331 endif()
0332 if(EXISTS "${${_ICU_component_cache_release}}")
0333 set_property(TARGET ${_ICU_imported_target} APPEND PROPERTY
0334 IMPORTED_CONFIGURATIONS RELEASE)
0335 set_target_properties(${_ICU_imported_target} PROPERTIES
0336 IMPORTED_LINK_INTERFACE_LANGUAGES_RELEASE "CXX"
0337 IMPORTED_LOCATION_RELEASE "${${_ICU_component_cache_release}}")
0338 endif()
0339 if(EXISTS "${${_ICU_component_cache_debug}}")
0340 set_property(TARGET ${_ICU_imported_target} APPEND PROPERTY
0341 IMPORTED_CONFIGURATIONS DEBUG)
0342 set_target_properties(${_ICU_imported_target} PROPERTIES
0343 IMPORTED_LINK_INTERFACE_LANGUAGES_DEBUG "CXX"
0344 IMPORTED_LOCATION_DEBUG "${${_ICU_component_cache_debug}}")
0345 endif()
0346 endif()
0347 endif()
0348 unset(_ICU_component_upcase)
0349 unset(_ICU_component_cache)
0350 unset(_ICU_component_lib)
0351 unset(_ICU_component_found)
0352 unset(_ICU_imported_target)
0353 endforeach()
0354 endif()
0355
0356 if(ICU_DEBUG)
0357 message(STATUS "--------FindICU.cmake results debug--------")
0358 message(STATUS "ICU found: ${ICU_FOUND}")
0359 message(STATUS "ICU_VERSION number: ${ICU_VERSION}")
0360 message(STATUS "ICU_ROOT directory: ${ICU_ROOT}")
0361 message(STATUS "ICU_INCLUDE_DIR directory: ${ICU_INCLUDE_DIR}")
0362 message(STATUS "ICU_LIBRARIES: ${ICU_LIBRARIES}")
0363
0364 foreach(program IN LISTS icu_programs)
0365 string(TOUPPER "${program}" program_upcase)
0366 set(program_lib "ICU_${program_upcase}_EXECUTABLE")
0367 message(STATUS "${program} program: ${${program_lib}}")
0368 unset(program_upcase)
0369 unset(program_lib)
0370 endforeach()
0371
0372 foreach(data IN LISTS icu_data)
0373 string(TOUPPER "${data}" data_upcase)
0374 string(REPLACE "." "_" data_upcase "${data_upcase}")
0375 set(data_lib "ICU_${data_upcase}")
0376 message(STATUS "${data} data: ${${data_lib}}")
0377 unset(data_upcase)
0378 unset(data_lib)
0379 endforeach()
0380
0381 foreach(component IN LISTS ICU_FIND_COMPONENTS)
0382 string(TOUPPER "${component}" component_upcase)
0383 set(component_lib "ICU_${component_upcase}_LIBRARIES")
0384 set(component_found "${component_upcase}_FOUND")
0385 message(STATUS "${component} library found: ${${component_found}}")
0386 message(STATUS "${component} library: ${${component_lib}}")
0387 unset(component_upcase)
0388 unset(component_lib)
0389 unset(component_found)
0390 endforeach()
0391 message(STATUS "----------------")
0392 endif()
0393
0394 unset(icu_programs)