Fix FindICU.cmake
[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     DOC "Include directory for the ICU library")
22 mark_as_advanced(ICU_INCLUDE_DIR)
23
24 # Look for the library.
25 find_library(
26     ICU_LIBRARY
27     NAMES icuuc cygicuuc cygicuuc32
28     HINTS ${PC_ICU_LIBRARY_DIRS}
29           ${PC_ICU_LIBDIR}
30     DOC "Libraries to link against for the common parts of ICU")
31 mark_as_advanced(ICU_LIBRARY)
32
33 # Copy the results to the output variables.
34 if (ICU_INCLUDE_DIR AND ICU_LIBRARY)
35     set(ICU_FOUND 1)
36     set(ICU_LIBRARIES ${ICU_LIBRARY})
37     set(ICU_INCLUDE_DIRS ${ICU_INCLUDE_DIR})
38
39     set(ICU_VERSION 0)
40     set(ICU_MAJOR_VERSION 0)
41     set(ICU_MINOR_VERSION 0)
42     file(READ "${ICU_INCLUDE_DIR}/unicode/uversion.h" _ICU_VERSION_CONENTS)
43     string(REGEX REPLACE ".*#define U_ICU_VERSION_MAJOR_NUM ([0-9]+).*" "\\1" ICU_MAJOR_VERSION "${_ICU_VERSION_CONENTS}")
44     string(REGEX REPLACE ".*#define U_ICU_VERSION_MINOR_NUM ([0-9]+).*" "\\1" ICU_MINOR_VERSION "${_ICU_VERSION_CONENTS}")
45
46     set(ICU_VERSION "${ICU_MAJOR_VERSION}.${ICU_MINOR_VERSION}")
47
48     # Look for the ICU internationalization libraries
49     find_library(
50         ICU_I18N_LIBRARY
51         NAMES icuin icui18n cygicuin cygicuin32
52         DOC "Libraries to link against for ICU internationalization")
53     mark_as_advanced(ICU_I18N_LIBRARY)
54     if (ICU_I18N_LIBRARY)
55         set(ICU_I18N_FOUND 1)
56         set(ICU_I18N_LIBRARIES ${ICU_I18N_LIBRARY})
57     else ()
58         set(ICU_I18N_FOUND 0)
59         set(ICU_I18N_LIBRARIES)
60     endif ()
61 else ()
62     set(ICU_FOUND 0)
63     set(ICU_I18N_FOUND 0)
64     set(ICU_LIBRARIES)
65     set(ICU_I18N_LIBRARIES)
66     set(ICU_INCLUDE_DIRS)
67     set(ICU_VERSION)
68     set(ICU_MAJOR_VERSION)
69     set(ICU_MINOR_VERSION)
70 endif ()
71
72 if (ICU_FOUND)
73     if (NOT ICU_FIND_QUIETLY)
74         message(STATUS "Found ICU header files in ${ICU_INCLUDE_DIRS}")
75         message(STATUS "Found ICU libraries: ${ICU_LIBRARIES}")
76     endif ()
77 else ()
78     if (ICU_FIND_REQUIRED)
79         message(FATAL_ERROR "Could not find ICU")
80     else ()
81         message(STATUS "Optional package ICU was not found")
82     endif ()
83 endif ()