GetICU.cmake 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #=============================================================================
  2. # Copyright 2017-2026, Manticore Software LTD (https://manticoresearch.com)
  3. #
  4. # Distributed under the OSI-approved BSD License (the "License");
  5. # see accompanying file Copyright.txt for details.
  6. #
  7. # This software is distributed WITHOUT ANY WARRANTY; without even the
  8. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9. # See the License for more information.
  10. #=============================================================================
  11. set ( ICU_GITHUB "https://github.com/unicode-org/icu/releases/download/release-65-1/icu4c-65_1-src.tgz" )
  12. set ( ICU_BUNDLE "${LIBS_BUNDLE}/icu4c-65_1-src.tgz" )
  13. set ( ICU_SRC_MD5 "d1ff436e26cabcb28e6cb383d32d1339" )
  14. cmake_minimum_required ( VERSION 3.17 FATAL_ERROR )
  15. include ( update_bundle )
  16. # helpers
  17. function ( install_icudata DEST )
  18. if (NOT TARGET icu::icudata)
  19. return ()
  20. endif ()
  21. get_target_property ( ICU_DATA icu::icudata INTERFACE_SOURCES )
  22. diag ( ICU_DATA )
  23. install ( FILES ${ICU_DATA} DESTINATION "${DEST}" COMPONENT icudata )
  24. endfunction ()
  25. # if it is allowed to use system library - try to use it
  26. if (NOT WITH_ICU_FORCE_STATIC)
  27. find_package ( ICU MODULE QUIET COMPONENTS uc )
  28. if (ICU_UC_FOUND)
  29. add_library ( icu::icu ALIAS ICU::uc )
  30. endif ()
  31. return_if_target_found ( icu::icu "as default (sys or other)" )
  32. endif ()
  33. if (WITH_ICU_FORCE_BUILD) # special case for static binary
  34. select_nearest_url ( ICU_PLACE icu ${ICU_BUNDLE} ${ICU_GITHUB} )
  35. fetch_and_check ( icu ${ICU_PLACE} ${ICU_SRC_MD5} ICU_SRC )
  36. configure_file ( "${MANTICORE_SOURCE_DIR}/libicu/CMakeLists.txt" "${ICU_SRC}/CMakeLists.txt" COPYONLY )
  37. message ( STATUS "Build icu from sources since we want special build for static release" )
  38. set ( ICU_BUILD "${MANTICORE_BINARY_DIR}/icu-build-static-force" )
  39. external_build ( icu ICU_SRC ICU_BUILD "STATIC_BUILD=ON" )
  40. find_package ( icu REQUIRED CONFIG PATHS "${ICU_BUILD}" )
  41. trace ( icu::icu )
  42. return_if_target_found ( icu::icu "was built and saved" )
  43. endif ()
  44. # determine destination folder where we expect pre-built icu
  45. find_package ( icu QUIET CONFIG )
  46. return_if_target_found ( icu::icu "ready (no need to build)" )
  47. # not found. Populate and prepare sources
  48. select_nearest_url ( ICU_PLACE icu ${ICU_BUNDLE} ${ICU_GITHUB} )
  49. fetch_and_check ( icu ${ICU_PLACE} ${ICU_SRC_MD5} ICU_SRC )
  50. execute_process ( COMMAND ${CMAKE_COMMAND} -E copy_if_different "${MANTICORE_SOURCE_DIR}/libicu/CMakeLists.txt" "${ICU_SRC}/CMakeLists.txt" )
  51. # build external project
  52. get_build ( ICU_BUILD icu )
  53. external_build ( icu ICU_SRC ICU_BUILD )
  54. # now it should find
  55. find_package ( icu REQUIRED CONFIG )
  56. return_if_target_found ( icu::icu "was built and saved" )