[default] Build a no-op number formatter for old ICUs
This has been causing too many build problems and it is a major source of complains because of different ICU interfaces.
This commit is contained in:
@@ -1,10 +1,16 @@
|
||||
#include <mbgl/i18n/number_format.hpp>
|
||||
|
||||
#if !defined(MBGL_USE_BUILTIN_ICU)
|
||||
#include <unicode/numberformatter.h>
|
||||
#include <unicode/uvernum.h>
|
||||
#endif
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace mbgl {
|
||||
namespace platform {
|
||||
|
||||
#if !defined(MBGL_USE_BUILTIN_ICU)
|
||||
std::string formatNumber(double number,
|
||||
const std::string& localeId,
|
||||
const std::string& currency,
|
||||
@@ -22,28 +28,21 @@ std::string formatNumber(double number,
|
||||
.unit(icu::CurrencyUnit(ucurrency.getBuffer(), status))
|
||||
.locale(locale)
|
||||
.formatDouble(number, status)
|
||||
#if U_ICU_VERSION_MAJOR_NUM >= 62
|
||||
.toString(status);
|
||||
#else
|
||||
.toString();
|
||||
#endif
|
||||
} else {
|
||||
ustr = icu::number::NumberFormatter::with()
|
||||
#if U_ICU_VERSION_MAJOR_NUM >= 62
|
||||
.precision(icu::number::Precision::minMaxFraction(minFractionDigits, maxFractionDigits))
|
||||
#else
|
||||
.rounding(icu::number::Rounder::minMaxFraction(minFractionDigits, maxFractionDigits))
|
||||
#endif
|
||||
.locale(locale)
|
||||
.formatDouble(number, status)
|
||||
#if U_ICU_VERSION_MAJOR_NUM >= 62
|
||||
.toString(status);
|
||||
#else
|
||||
.toString();
|
||||
#endif
|
||||
}
|
||||
return ustr.toUTF8String(formatted);
|
||||
}
|
||||
#else
|
||||
std::string formatNumber(double number, const std::string&, const std::string&, uint8_t, uint8_t) {
|
||||
return std::to_string(number);
|
||||
}
|
||||
#endif
|
||||
|
||||
} // namespace platform
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
find_package(CURL REQUIRED)
|
||||
find_package(ICU REQUIRED i18n)
|
||||
find_package(ICU REQUIRED uc)
|
||||
find_package(ICU OPTIONAL_COMPONENTS i18n)
|
||||
find_package(ICU OPTIONAL_COMPONENTS uc)
|
||||
find_package(JPEG REQUIRED)
|
||||
find_package(OpenGL REQUIRED GLX)
|
||||
find_package(PNG REQUIRED)
|
||||
@@ -65,6 +65,20 @@ target_include_directories(
|
||||
include(${PROJECT_SOURCE_DIR}/vendor/nunicode.cmake)
|
||||
include(${PROJECT_SOURCE_DIR}/vendor/sqlite.cmake)
|
||||
|
||||
if(NOT ${ICU_FOUND} OR "${ICU_VERSION}" VERSION_LESS 62.0)
|
||||
message("-- ICU not found or too old, using builtin.")
|
||||
|
||||
set(MBGL_USE_BUILTIN_ICU TRUE)
|
||||
include(${PROJECT_SOURCE_DIR}/vendor/icu.cmake)
|
||||
|
||||
set_source_files_properties(
|
||||
${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/i18n/number_format.cpp
|
||||
PROPERTIES
|
||||
COMPILE_DEFINITIONS
|
||||
MBGL_USE_BUILTIN_ICU
|
||||
)
|
||||
endif()
|
||||
|
||||
target_link_libraries(
|
||||
mbgl-core
|
||||
PRIVATE
|
||||
@@ -72,8 +86,9 @@ target_link_libraries(
|
||||
${JPEG_LIBRARIES}
|
||||
${LIBUV_LIBRARIES}
|
||||
${X11_LIBRARIES}
|
||||
ICU::i18n
|
||||
ICU::uc
|
||||
$<$<NOT:$<BOOL:${MBGL_USE_BUILTIN_ICU}>>:ICU::i18n>
|
||||
$<$<NOT:$<BOOL:${MBGL_USE_BUILTIN_ICU}>>:ICU::uc>
|
||||
$<$<BOOL:${MBGL_USE_BUILTIN_ICU}>:mbgl-vendor-icu>
|
||||
OpenGL::GLX
|
||||
PNG::PNG
|
||||
mbgl-vendor-nunicode
|
||||
|
||||
Reference in New Issue
Block a user