57a459224a9ce3592bdd3a94e1817a4b969ce898
[WebKit.git] / Source / cmake / FindICU.cmake
1 # Finds the International Components for Unicode (ICU) Library
2 #
3 #  ICU_FOUND          - True if ICU found.
4 #  ICU_I18N_FOUND     - True if ICU's internationalization library found.
5 #  ICU_INCLUDE_DIRS   - Directory to include to get ICU headers
6 #                       Note: always include ICU headers as, e.g.,
7 #                       unicode/utypes.h
8 #  ICU_LIBRARIES      - Libraries to link against for the common ICU
9 #  ICU_I18N_LIBRARIES - Libraries to link against for ICU internationaliation
10 #                       (note: in addition to ICU_LIBRARIES)
11
12 find_package(PkgConfig)
13 pkg_check_modules(PC_ICU icu-uc)
14
15 # Look for the header file.
16 find_path(
17     ICU_INCLUDE_DIR
18     NAMES unicode/utypes.h
19     HINTS ${PC_ICU_INCLUDE_DIRS}
20           ${PC_ICU_INCLUDEDIR}
21           ${WEBKIT_LIBRARIES_INCLUDE_DIR}
22     DOC "Include directory for the ICU library")
23 mark_as_advanced(ICU_INCLUDE_DIR)
24
25 # Look for the library.
26 find_library(
27     ICU_LIBRARY
28     NAMES icuuc libicuuc cygicuuc cygicuuc32
29     HINTS ${PC_ICU_LIBRARY_DIRS}
30           ${PC_ICU_LIBDIR}
31           ${WEBKIT_LIBRARIES_LINK_DIR}
32     DOC "Libraries to link against for the common parts of ICU")
33 mark_as_advanced(ICU_LIBRARY)
34
35 # Copy the results to the output variables.
36 if (ICU_INCLUDE_DIR AND ICU_LIBRARY)
37     set(ICU_FOUND 1)
38     set(ICU_LIBRARIES ${ICU_LIBRARY})
39     set(ICU_INCLUDE_DIRS ${ICU_INCLUDE_DIR})
40
41     set(ICU_VERSION 0)
42     set(ICU_MAJOR_VERSION 0)
43     set(ICU_MINOR_VERSION 0)
44     file(READ "${ICU_INCLUDE_DIR}/unicode/uversion.h" _ICU_VERSION_CONENTS)
45     string(REGEX REPLACE ".*#define U_ICU_VERSION_MAJOR_NUM ([0-9]+).*" "\\1" ICU_MAJOR_VERSION "${_ICU_VERSION_CONENTS}")
46     string(REGEX REPLACE ".*#define U_ICU_VERSION_MINOR_NUM ([0-9]+).*" "\\1" ICU_MINOR_VERSION "${_ICU_VERSION_CONENTS}")
47
48     set(ICU_VERSION "${ICU_MAJOR_VERSION}.${ICU_MINOR_VERSION}")
49
50     # Look for the ICU internationalization libraries
51     pkg_check_modules(PC_ICU_I18N icu-i18n)
52     find_library(
53         ICU_I18N_LIBRARY
54         NAMES icui18n icuin libicui18n libicuin cygicuin cygicuin32
55         HINTS ${PC_ICU_I18N_LIBRARY_DIRS}
56               ${PC_ICU_I18N_LIBDIR}
57               ${WEBKIT_LIBRARIES_LINK_DIR}
58         DOC "Libraries to link against for ICU internationalization")
59     mark_as_advanced(ICU_I18N_LIBRARY)
60     if (ICU_I18N_LIBRARY)
61         set(ICU_I18N_FOUND 1)
62         set(ICU_I18N_LIBRARIES ${ICU_I18N_LIBRARY})
63     else ()
64         set(ICU_I18N_FOUND 0)
65         set(ICU_I18N_LIBRARIES)
66     endif ()
67
68     # Look for the ICU data libraries
69     find_library(
70         ICU_DATA_LIBRARY
71         NAMES icudata libicudata cygicudata cygicudata32
72         HINTS ${PC_ICU_I18N_LIBRARY_DIRS}
73               ${PC_ICU_I18N_LIBDIR}
74               ${WEBKIT_LIBRARIES_LINK_DIR}
75         DOC "Libraries to link against for ICU data")
76     mark_as_advanced(ICU_DATA_LIBRARY)
77     if (ICU_DATA_LIBRARY)
78         set(ICU_DATA_FOUND 1)
79         set(ICU_DATA_LIBRARIES ${ICU_DATA_LIBRARY})
80     else ()
81         set(ICU_DATA_FOUND 0)
82         set(ICU_DATA_LIBRARIES)
83     endif ()
84 else ()
85     set(ICU_FOUND 0)
86     set(ICU_I18N_FOUND 0)
87     set(ICU_DATA_FOUND 0)
88     set(ICU_LIBRARIES)
89     set(ICU_I18N_LIBRARIES)
90     set(ICU_DATA_LIBRARIES)
91     set(ICU_INCLUDE_DIRS)
92     set(ICU_VERSION)
93     set(ICU_MAJOR_VERSION)
94     set(ICU_MINOR_VERSION)
95 endif ()
96
97 if (ICU_FOUND)
98     if (NOT ICU_FIND_QUIETLY)
99         message(STATUS "Found ICU header files in ${ICU_INCLUDE_DIRS}")
100         message(STATUS "Found ICU libraries: ${ICU_LIBRARIES}")
101         message(STATUS "Found ICU internationaliation libraries: ${ICU_I18N_LIBRARIES}")
102         message(STATUS "Found ICU data libraries: ${ICU_DATA_LIBRARIES}")
103     endif ()
104 else ()
105     if (ICU_FIND_REQUIRED)
106         message(FATAL_ERROR "Could not find ICU")
107     else ()
108         message(STATUS "Optional package ICU was not found")
109     endif ()
110 endif ()