FindICU.cmake 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. ################################################################################
  2. # HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems®.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. ################################################################################
  16. # - Try to find the ICU unicode library
  17. # Once done this will define
  18. #
  19. # ICU_FOUND - system has the ICU library
  20. # ICU_INCLUDE_DIR - the ICU include directory
  21. # ICU_LIBRARIES - The libraries needed to use ICU
  22. # ICU_VERSION - Version of unicode library
  23. IF (NOT ICU_FOUND)
  24. IF (NOT "${EXTERNALS_DIRECTORY}" STREQUAL "")
  25. IF (UNIX)
  26. IF (${ARCH64BIT} EQUAL 1)
  27. SET (libdir "lib/linux64_gcc4.1.1")
  28. ELSE()
  29. SET (libdir "lib/linux32_gcc4.1.1")
  30. ENDIF()
  31. ELSEIF(WIN32)
  32. IF (${ARCH64BIT} EQUAL 1)
  33. SET (libdir "lib64")
  34. ELSE()
  35. SET (libdir "lib")
  36. ENDIF()
  37. ELSE()
  38. SET (libdir "unknown")
  39. ENDIF()
  40. IF (NOT ("${libdir}" STREQUAL "unknown"))
  41. FIND_PATH (ICU_INCLUDE_DIR NAMES unicode/uchar.h PATHS "${EXTERNALS_DIRECTORY}/icu/include" NO_DEFAULT_PATH)
  42. FIND_LIBRARY (ICU_LIBRARIES NAMES icuuc PATHS "${EXTERNALS_DIRECTORY}/icu/${libdir}" NO_DEFAULT_PATH)
  43. ENDIF()
  44. ENDIF()
  45. if (USE_NATIVE_LIBRARIES)
  46. # if we didn't find in externals, look in system include path
  47. FIND_PATH (ICU_INCLUDE_DIR PATHS /usr/local/opt/icu4c/include NAMES unicode/uchar.h)
  48. FIND_LIBRARY (ICU_LIBRARIES PATHS /usr/local/opt/icu4c/lib NAMES icuuc)
  49. endif()
  50. if(EXISTS ${ICU_INCLUDE_DIR}/unicode/uchar.h)
  51. file(STRINGS ${ICU_INCLUDE_DIR}/unicode/uchar.h __ICU_VERSION REGEX
  52. "^#define U_UNICODE_VERSION*")
  53. string(REPLACE "#define U_UNICODE_VERSION" "" __ICU_VERSION
  54. ${__ICU_VERSION})
  55. string(REPLACE "\"" "" __ICU_VERSION ${__ICU_VERSION})
  56. string(STRIP "${__ICU_VERSION}" __ICU_VERSION)
  57. set(ICU_VERSION "${__ICU_VERSION}" CACHE STRING "unicode library version")
  58. endif()
  59. include(FindPackageHandleStandardArgs)
  60. find_package_handle_standard_args(ICU DEFAULT_MSG
  61. ICU_LIBRARIES
  62. ICU_INCLUDE_DIR
  63. )
  64. message(STATUS " version: ${ICU_VERSION}")
  65. IF (ICU_FOUND)
  66. IF (UNIX)
  67. STRING(REPLACE "icuuc" "icui18n" ICU_EXTRA1 "${ICU_LIBRARIES}")
  68. STRING(REPLACE "icuuc" "icudata" ICU_EXTRA2 "${ICU_LIBRARIES}")
  69. ELSE()
  70. STRING(REPLACE "icuuc" "icuin" ICU_EXTRA1 "${ICU_LIBRARIES}")
  71. ENDIF()
  72. # The order is important for lib2 processing:
  73. # depender, such as icuil8n, should be placed before the dependee
  74. set (ICU_LIBRARIES ${ICU_EXTRA1} ${ICU_LIBRARIES} ${ICU_EXTRA2} )
  75. ENDIF()
  76. MARK_AS_ADVANCED(ICU_INCLUDE_DIR ICU_LIBRARIES ICU_VERSION)
  77. ENDIF()