|
| 1 | +# Find libicu's libraries |
| 2 | + |
| 3 | +function(_icu_find) |
| 4 | + set(icu_programs |
| 5 | + gencnval icuinfo genbrk icu-config genrb gendict derb pkgdata uconv gencfu |
| 6 | + makeconf gennorm2 genccode gensprep icupkg gencmn) |
| 7 | + set(icu_data |
| 8 | + Makefile.inc pkgdata.inc) |
| 9 | + |
| 10 | + # Set up search paths, taking compiler into account. Search ICU_ROOT, with |
| 11 | + # ICU_ROOT in the environment as a fallback if unset. |
| 12 | + if(ICU_ROOT) |
| 13 | + list(APPEND icu_roots ${ICU_ROOT}) |
| 14 | + else() |
| 15 | + if(NOT "$ENV{ICU_ROOT}" STREQUAL "") |
| 16 | + file(TO_CMAKE_PATH "$ENV{ICU_ROOT}" NATIVE_PATH) |
| 17 | + set(ICU_ROOT "${NATIVE_PATH}" CACHE PATH |
| 18 | + "Location of the ICU installation" FORCE) |
| 19 | + list(APPEND icu_roots ${NATIVE_PATH}) |
| 20 | + endif() |
| 21 | + endif() |
| 22 | + |
| 23 | + # Find the include directory. |
| 24 | + list(APPEND icu_include_suffixes "include") |
| 25 | + find_path(ICU_INCLUDE_DIR |
| 26 | + NAMES "unicode/utypes.h" |
| 27 | + HINTS ${icu_roots} |
| 28 | + PATh_SUFFIXES ${icu_include_suffixes} |
| 29 | + DOC "ICU include directory") |
| 30 | + set(ICU_INCLUDE_DIR "${ICU_INCLUDE_DIR}" PARENT_SCOPE) |
| 31 | + |
| 32 | + # Get the version. |
| 33 | + if(ICU_INCLUDE_DIR AND EXISTS "${ICU_INCLUDE_DIR}/unicode/uvernum.h") |
| 34 | + file(STRINGS "${ICU_INCLUDE_DIR}/unicode/uvernum.h" icu_header_str |
| 35 | + REGEX "^#define[\t ]+U_ICU_VERSION[\t ]+\".*\".*") |
| 36 | + |
| 37 | + string(REGEX REPLACE "^#define[\t ]+U_ICU_VERSION[\t ]+\"([^ \\n]*)\".*" |
| 38 | + "\\1" icu_version_string "${icu_header_str}") |
| 39 | + set(ICU_VERSION "${icu_version_string}" PARENT_SCOPE) |
| 40 | + |
| 41 | + unset(icu_header_str) |
| 42 | + unset(icu_version_string) |
| 43 | + endif() |
| 44 | + |
| 45 | + if(CMAKE_SIZEOF_VOID_P EQUAL 8) |
| 46 | + set(_bin64 "bin64") |
| 47 | + set(_lib64 "lib64") |
| 48 | + endif() |
| 49 | + |
| 50 | + # Find all ICU programs. |
| 51 | + list(APPEND icu_binary_suffixes "${_bin64}" "bin" "sbin") |
| 52 | + foreach(program ${icu_programs}) |
| 53 | + string(TOUPPER ${program} program_upcase) |
| 54 | + set(cache_var "ICU_${program_upcase}_EXECUTABLE") |
| 55 | + find_program(${cache_var} ${program} |
| 56 | + HINTS ${icu_roots} |
| 57 | + PATH_SUFFIXES ${icu_binary_suffixes} |
| 58 | + DOC "ICU ${program} executable") |
| 59 | + mark_as_advanced(cache_var) |
| 60 | + set(${cache_var} "${${cache_var}}" PARENT_SCOPE) |
| 61 | + endforeach() |
| 62 | + |
| 63 | + set(static_prefix ) |
| 64 | + if(MSVC) |
| 65 | + set(static_prefix "s") |
| 66 | + endif() |
| 67 | + |
| 68 | + # Find all ICU libraries. |
| 69 | + list(APPEND icu_library_suffixes "${_lib64}" "lib") |
| 70 | + set(ICU_REQUIRED_LIBS_FOUND YES) |
| 71 | + foreach(component ${ICU_FIND_COMPONENTS}) |
| 72 | + string(TOUPPER ${component} component_upcase) |
| 73 | + |
| 74 | + set(component_cache "ICU_${component_upcase}_LIBRARY") |
| 75 | + set(component_cache_release "${component_cache}_RELEASE") |
| 76 | + set(component_cache_debug "${component_cache}_DEBUG") |
| 77 | + set(component_found "${component_cache}_FOUND") |
| 78 | + |
| 79 | + list(APPEND component_libnames "icu${component}") |
| 80 | + list(APPEND component_debug_libnames "icu${component}d") |
| 81 | + if(component STREQUAL data) |
| 82 | + list(APPEND component_libnames icudt) |
| 83 | + list(APPEND component_debug_libnames icudtd) |
| 84 | + elseif(component STREQUAL dt) |
| 85 | + list(APPEND component_libnames icudata) |
| 86 | + list(APPEND component_debug_libnames icudatad) |
| 87 | + elseif(component STREQUAL i18n) |
| 88 | + list(APPEND component_libnames icuin) |
| 89 | + list(APPEND component_debug_libnames icuind) |
| 90 | + elseif(component STREQUAL in) |
| 91 | + list(APPEND component_libnames icui18n) |
| 92 | + list(APPEND component_debug_libnames icui18nd) |
| 93 | + endif() |
| 94 | + |
| 95 | + if(static_prefix) |
| 96 | + unset(static_component_libnames) |
| 97 | + foreach(component_libname ${component_libnames}) |
| 98 | + list(APPEND static_component_libnames |
| 99 | + ${static_prefix}${component_libname}) |
| 100 | + endforeach() |
| 101 | + list(APPEND component_libnames ${static_component_libnames}) |
| 102 | + |
| 103 | + unset(static_component_debug_libnames) |
| 104 | + foreach(component_libname ${component_debug_libnames}) |
| 105 | + list(APPEND static_component_debug_libnames |
| 106 | + ${static_prefix}${component_libname}) |
| 107 | + endforeach() |
| 108 | + list(APPEND component_debug_libnames ${static_component_debug_libnames}) |
| 109 | + endif() |
| 110 | + |
| 111 | + find_library(${component_cache_release} ${component_libnames} |
| 112 | + HINTS ${icu_roots} |
| 113 | + PATH_SUFFIXES ${icu_library_suffixes} |
| 114 | + DOC "ICU ${component} library (release)") |
| 115 | + find_library(${component_cache_debug} ${component_debug_libnames} |
| 116 | + HINTS ${icu_roots} |
| 117 | + PATH_SUFFIXES ${icu_library_suffixes} |
| 118 | + DOC "ICU ${component} library (debug)") |
| 119 | + |
| 120 | + include(SelectLibraryConfigurations) |
| 121 | + select_library_configurations(ICU_${component_upcase}) |
| 122 | + mark_as_advanced(${component_cache_release} ${component_cache_debug}) |
| 123 | + |
| 124 | + if(${component_cache}) |
| 125 | + set(${component_found} YES) |
| 126 | + list(APPEND ICU_LIBRARY ${${component_cache}}) |
| 127 | + endif() |
| 128 | + mark_as_advanced(${component_found}) |
| 129 | + |
| 130 | + set(${component_cache} "${${component_cache}}" PARENT_SCOPE) |
| 131 | + set(${component_found} "${${component_found}}" PARENT_SCOPE) |
| 132 | + if(${component_found}) |
| 133 | + if(ICU_FIND_REQUIRED_${component}) |
| 134 | + list(APPEND ICU_LIBS_FOUND "${component} (required)") |
| 135 | + else() |
| 136 | + list(APPEND ICU_LIBS_FOUND "${component} (optional)") |
| 137 | + endif() |
| 138 | + else() |
| 139 | + if(ICU_FIND_REQUIRED_${component}) |
| 140 | + list(APPEND ICU_LIBS_NOTFOUND "${component} (required)") |
| 141 | + else() |
| 142 | + list(APPEND ICU_LIBS_NOTFOUND "${component} (optional)") |
| 143 | + endif() |
| 144 | + endif() |
| 145 | + |
| 146 | + set(_ICU_REQUIRED_LIBS_FOUND "${ICU_REQUIRED_LIBS_FOUND}" PARENT_SCOPE) |
| 147 | + set(ICU_LIBRARY "${ICU_LIBRARY}" PARENT_SCOPE) |
| 148 | + endforeach() |
| 149 | + |
| 150 | + if(CMAKE_LIBRARY_ARCHITECTURE) |
| 151 | + list(APPEND icu_data_suffixes |
| 152 | + "${_lib64}/${CMAKE_LIBRARY_ARCHITECTURE}/icu/${ICU_VERSION}" |
| 153 | + "lib/${CMAKE_LIBRARY_ARCHITECTURE}/icu/${ICU_VERSION}" |
| 154 | + "${_lib64}/${CMAKE_LIBRARY_ARCHITECTURE}/icu" |
| 155 | + "lib/${CMAKE_LIBRARY_ARCHITECTURE}/icu") |
| 156 | + endif() |
| 157 | + list(APPEND icu_data_suffixes |
| 158 | + "${_lib64}/icu/${ICU_VERSION}" |
| 159 | + "lib/icu/${ICU_VERSION}" |
| 160 | + "${_lib64}/icu" |
| 161 | + "lib/icu") |
| 162 | + foreach(data ${icu_data}) |
| 163 | + string(TOUPPER ${data} data_upcase) |
| 164 | + STRING(REPLACE "." "_" data_upcase ${data_upcase}) |
| 165 | + |
| 166 | + set(cache_var ICU_${data_upcase}) |
| 167 | + find_file(${cache_Var} ${data} |
| 168 | + HINTS ${icu_roots} |
| 169 | + PATH_SUFFIXES ${icu_data_suffixes} |
| 170 | + DOC "ICU ${data} data file") |
| 171 | + mark_as_advanced(cache_var) |
| 172 | + set(${cache_var} "${${cache_var}}" PARENT_SCOPE) |
| 173 | + endforeach() |
| 174 | +endfunction() |
| 175 | + |
| 176 | +_icu_find() |
| 177 | +include(FindPackageHandleStandardArgs) |
| 178 | +find_package_handle_standard_args(ICU |
| 179 | + FOUND_VAR |
| 180 | + ICU_FOUND |
| 181 | + REQUIRED_VARS |
| 182 | + ICU_INCLUDE_DIR |
| 183 | + ICU_LIBRARY |
| 184 | + _ICU_REQUIRED_LIBS_FOUND |
| 185 | + VERSION_VAR |
| 186 | + ICU_VERSION |
| 187 | + FAIL_MESSAGE |
| 188 | + "Failed to find all ICU components") |
| 189 | +unset(_ICU_REQUIRED_LIBS_FOUND) |
| 190 | + |
| 191 | +if(ICU_FOUND) |
| 192 | + set(ICU_INCLUDE_DIRS "${ICU_INCLUDE_DIR}") |
| 193 | + set(ICU_LIBRARIES "${ICU_LIBRARY}") |
| 194 | + foreach(_ICU_component ${ICU_FIND_COMPONENTS}) |
| 195 | + string(TOUPPER ${_ICU_component} _ICU_component_upcase) |
| 196 | + |
| 197 | + set(_ICU_component_cache "ICU_${_ICU_component_upcase}_LIBRARY") |
| 198 | + set(_ICU_component_cache_release "ICU_${_ICU_component_upcase}_LIBRARY_RELEASE") |
| 199 | + set(_ICU_component_cache_debug "ICU_${_ICU_component_upcase}_LIBRARY_DEBUG") |
| 200 | + set(_ICU_component_lib "ICU_${_ICU_component_upcase}_LIBRARIES") |
| 201 | + set(_ICU_component_found "${_ICU_component_upcase}_FOUND") |
| 202 | + set(_ICU_imported_target "ICU::${_ICU_component}") |
| 203 | + |
| 204 | + if(${_ICU_component_found}) |
| 205 | + set(${_ICU_component_lib} "${${_ICU_component_cache}}") |
| 206 | + if(NOT TARGET ${_ICU_imported_target}) |
| 207 | + add_library(${_ICU_imported_target} UNKNOWN IMPORTED) |
| 208 | + if(ICU_INCLUDE_DIR) |
| 209 | + set_target_properties(${_ICU_imported_target} PROPERTIES |
| 210 | + INTERFACE_INCLUDE_DIRECTORIES |
| 211 | + ${ICU_INCLUDE_DIR}) |
| 212 | + endif() |
| 213 | + if(EXISTS ${${_ICU_component_cache}}) |
| 214 | + set_target_properties(${_ICU_imported_target} PROPERTIES |
| 215 | + IMPORTED_LINK_INTERFACE_LANGUAGES |
| 216 | + CXX |
| 217 | + IMPORTED_LOCATION |
| 218 | + ${${_ICU_component_cache}}) |
| 219 | + endif() |
| 220 | + if(EXISTS ${${_ICU_component_cache_release}}) |
| 221 | + set_property(TARGET ${_ICU_imported_target} APPEND PROPERTY |
| 222 | + IMPORTED_CONFIGURATIONS |
| 223 | + RELEASE) |
| 224 | + set_target_properties(${_ICU_imported_target} PROPERTIES |
| 225 | + IMPORTED_LINK_INTERFACE_LANGUAGES_RELEASE |
| 226 | + CXX |
| 227 | + IMPORTED_LOCATION_RELEASE |
| 228 | + ${${_ICU_component_cache_release}}) |
| 229 | + endif() |
| 230 | + if(EXISTS ${${_ICU_component_cache_debug}}) |
| 231 | + set_property(TARGET ${_ICU_imported_target} APPEND PROPERTY |
| 232 | + IMPORTED_CONFIGURATIONS |
| 233 | + DEBUG) |
| 234 | + set_target_properties(${_ICU_imported_target} PROPERTIES |
| 235 | + IMPORTED_LINK_INTERFACE_LANGUAGES_DEBUG |
| 236 | + CXX |
| 237 | + IMPORTED_LOCATION_DEBUG |
| 238 | + ${${_ICU_component_cache_debug}}) |
| 239 | + endif() |
| 240 | + endif() |
| 241 | + endif() |
| 242 | + |
| 243 | + unset(_ICU_imported_target) |
| 244 | + unset(_ICU_component_found) |
| 245 | + unset(_ICU_component_lib) |
| 246 | + unset(_ICU_component_cache_debug) |
| 247 | + unset(_ICU_component_cache_release) |
| 248 | + unset(_ICU_component_cache) |
| 249 | + endforeach() |
| 250 | +endif() |
| 251 | + |
0 commit comments