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