summaryrefslogtreecommitdiffstats
path: root/FindICU.cmake
blob: dfbf67d68f5d3ecea21da6c7db18d969c3efd79a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
FIND_PROGRAM(ICU_CONFIG NAMES icu-config)

IF(ICU_CONFIG)
  SET(ICU_FOUND 1)
ELSE(ICU_CONFIG)
  SET(ICU_FOUND 0)
ENDIF(ICU_CONFIG)

IF(ICU_FOUND)
  EXECUTE_PROCESS(
    COMMAND ${ICU_CONFIG} --cflags
    OUTPUT_VARIABLE ICU_CONFIG_CFLAGS
    OUTPUT_STRIP_TRAILING_WHITESPACE
    RESULT_VARIABLE ICU_CONFIG_RESULT
  )
  
  IF("${ICU_CONFIG_RESULT}" MATCHES "^0$")
    STRING(REGEX REPLACE " +" ";" ICU_CONFIG_CFLAGS "${ICU_CONFIG_CFLAGS}")

    # Look for -I options.
    SET(ICU_INCLUDE_DIRS)
    FOREACH(flag ${ICU_CONFIG_CFLAGS})
      IF("${flag}" MATCHES "^-I")
        STRING(REGEX REPLACE "^-I" "" DIR "${flag}")
        FILE(TO_CMAKE_PATH "${DIR}" DIR)
        SET(ICU_INCLUDE_DIRS ${ICU_INCLUDE_DIRS} "${DIR}")
      ENDIF("${flag}" MATCHES "^-I")
    ENDFOREACH(flag)
  ELSE("${ICU_CONFIG_RESULT}" MATCHES "^0$")
    MESSAGE("Error running ${ICU_CONFIG}: [${ICU_CONFIG_RESULT}]")
    SET(ICU_FOUND 0)
  ENDIF("${ICU_CONFIG_RESULT}" MATCHES "^0$")
ENDIF(ICU_FOUND)

IF(ICU_FOUND)
  EXECUTE_PROCESS(
    COMMAND ${ICU_CONFIG} --ldflags
    OUTPUT_VARIABLE ICU_CONFIG_LDFLAGS
    OUTPUT_STRIP_TRAILING_WHITESPACE
    RESULT_VARIABLE ICU_CONFIG_RESULT
  )

  IF("${ICU_CONFIG_RESULT}" MATCHES "^0$")
    STRING(REGEX REPLACE " +" ";" ICU_CONFIG_LDFLAGS "${ICU_CONFIG_LDFLAGS}")

    # Look for -L flags for directories and -l flags for library names.
    SET(ICU_LIBRARY_DIRS)
    SET(ICU_LIBRARY_NAMES)
    FOREACH(flag ${ICU_CONFIG_LDFLAGS})
      IF("${flag}" MATCHES "^-L")
        STRING(REGEX REPLACE "^-L" "" DIR "${flag}")
        FILE(TO_CMAKE_PATH "${DIR}" DIR)
        SET(ICU_LIBRARY_DIRS ${ICU_LIBRARY_DIRS} "${DIR}")
      ELSEIF("${flag}" MATCHES "^-l")
        STRING(REGEX REPLACE "^-l" "" NAME "${flag}")
        SET(ICU_LIBRARY_NAMES ${ICU_LIBRARY_NAMES} "${NAME}")
      ENDIF("${flag}" MATCHES "^-L")
    ENDFOREACH(flag)

    # Search for each library needed using the directories given.
    FOREACH(name ${ICU_LIBRARY_NAMES})
      # Look for this library.
      FIND_LIBRARY(ICU_${name}_LIBRARY
        NAMES ${name}
        PATHS ${ICU_LIBRARY_DIRS}
        NO_DEFAULT_PATH
      )
      FIND_LIBRARY(ICU_${name}_LIBRARY NAMES ${name})
      MARK_AS_ADVANCED(ICU_${name}_LIBRARY)

      # If any library is not found then the whole package is not found.
      IF(NOT ICU_${name}_LIBRARY)
        SET(ICU_FOUND 0)
      ENDIF(NOT ICU_${name}_LIBRARY)

      # Build an ordered list of all the libraries needed.
      SET(ICU_LIBRARIES ${ICU_LIBRARIES} "${ICU_${name}_LIBRARY}")
    ENDFOREACH(name)
  ELSE("${ICU_CONFIG_RESULT}" MATCHES "^0$")
    MESSAGE("Error running ${ICU_CONFIG}: [${ICU_CONFIG_RESULT}]")
    SET(ICU_FOUND 0)
  ENDIF("${ICU_CONFIG_RESULT}" MATCHES "^0$")
ENDIF(ICU_FOUND)

# Report the results.
IF(ICU_FOUND)
  MESSAGE(STATUS "Found ICU headers: ${ICU_INCLUDE_DIRS}")
  MESSAGE(STATUS "Found ICU libs:    ${ICU_LIBRARIES}")
ELSE(ICU_FOUND)
  SET(ICU_DIR_MESSAGE
    "ICU was not found.")
  IF(NOT ICU_FIND_QUIETLY)
    MESSAGE(STATUS "${ICU_DIR_MESSAGE}")
  ELSE(NOT ICU_FIND_QUIETLY)
    IF(ICU_FIND_REQUIRED)
      MESSAGE(FATAL_ERROR "${ICU_DIR_MESSAGE}")
    ENDIF(ICU_FIND_REQUIRED)
  ENDIF(NOT ICU_FIND_QUIETLY)
ENDIF(ICU_FOUND)