1 # CMake provides a FindICU module since version 3.7.
2 # But it doesn't use pkgconfig, doesn't set expected variables,
3 # And it returns incomplete dependencies if only some modules are searched.
6 #[=======================================================================[.rst:
10 Finds components of the ICU library.
12 Accepted components are: uc, i18n, le, lx, io, data
17 This will define the following variables:
20 True if components of ICU library are found.
22 The version of the ICU library which was found.
24 True if the system has the <c> component of ICU library.
25 ``ICU_<c>_INCLUDE_DIRS``
26 Include directories needed to use the <c> component of ICU library.
28 Libraries needed to link to the <c> component of ICU library.
30 #]=======================================================================]
32 find_package(PkgConfig QUIET)
34 set(ICU_KNOWN_COMPONENTS "uc" "i18n" "le" "lx" "io" "data")
36 foreach(MOD_NAME IN LISTS ICU_FIND_COMPONENTS)
37 if(NOT MOD_NAME IN_LIST ICU_KNOWN_COMPONENTS)
38 message(FATAL_ERROR "Unknown ICU component: ${MOD_NAME}")
40 pkg_check_modules(PC_ICU_${MOD_NAME} QUIET icu-${MOD_NAME})
42 # Check the libraries returned by pkg-config really exist.
44 foreach(LIBRARY IN LISTS PC_ICU_${MOD_NAME}_LIBRARIES)
45 unset(PC_LIBRARY CACHE)
46 find_library(PC_LIBRARY NAMES ${LIBRARY})
48 unset(PC_ICU_${MOD_NAME}_FOUND)
50 list(APPEND PC_LIBRARIES ${PC_LIBRARY})
52 unset(PC_LIBRARY CACHE)
54 if(${PC_ICU_${MOD_NAME}_FOUND})
55 set(ICU_COMPONENT_FOUND TRUE)
56 set(ICU_${MOD_NAME}_FOUND TRUE)
57 set(ICU_${MOD_NAME}_LIBRARIES ${PC_LIBRARIES})
58 set(ICU_${MOD_NAME}_INCLUDE_DIRS ${PC_ICU_${MOD_NAME}_INCLUDE_DIRS})
59 set(ICU_VERSION ${PC_ICU_${MOD_NAME}_VERSION})
63 include(FindPackageHandleStandardArgs)
64 find_package_handle_standard_args(ICU
66 REQUIRED_VARS ICU_COMPONENT_FOUND
67 VERSION_VAR ICU_VERSION