[Support] Add option to use Windows vendored ICU (#186371)
Windows 10 provided [ICU C API](https://learn.microsoft.com/en-us/windows/win32/intl/international-components-for-unicode--icu-) since 1703, this PR adds support for it.
This commit is contained in:
@@ -614,6 +614,11 @@ option(LLVM_ENABLE_THREADS "Use threads if available." ON)
|
|||||||
|
|
||||||
set(LLVM_ENABLE_ICU "OFF" CACHE STRING "Use ICU for text encoding conversion support if available. Can be ON, OFF, or FORCE_ON")
|
set(LLVM_ENABLE_ICU "OFF" CACHE STRING "Use ICU for text encoding conversion support if available. Can be ON, OFF, or FORCE_ON")
|
||||||
|
|
||||||
|
# After Windows 10 1903, icu.lib is available.
|
||||||
|
if(WIN32 AND CMAKE_SYSTEM_VERSION VERSION_GREATER_EQUAL "10.0.18362")
|
||||||
|
cmake_dependent_option(LLVM_ENABLE_WINDOWS_ICU "Use Windows vendored ICU if possible" OFF LLVM_ENABLE_ICU OFF)
|
||||||
|
endif()
|
||||||
|
|
||||||
set(LLVM_ENABLE_ICONV "OFF" CACHE STRING "Use iconv for text encoding conversion support if available. Can be ON, OFF, or FORCE_ON")
|
set(LLVM_ENABLE_ICONV "OFF" CACHE STRING "Use iconv for text encoding conversion support if available. Can be ON, OFF, or FORCE_ON")
|
||||||
|
|
||||||
set(LLVM_ENABLE_ZLIB "ON" CACHE STRING "Use zlib for compression/decompression if available. Can be ON, OFF, or FORCE_ON")
|
set(LLVM_ENABLE_ZLIB "ON" CACHE STRING "Use zlib for compression/decompression if available. Can be ON, OFF, or FORCE_ON")
|
||||||
|
|||||||
@@ -313,6 +313,12 @@ endif()
|
|||||||
if(LLVM_ENABLE_ICU AND NOT(LLVM_ENABLE_ICONV STREQUAL FORCE_ON))
|
if(LLVM_ENABLE_ICU AND NOT(LLVM_ENABLE_ICONV STREQUAL FORCE_ON))
|
||||||
set(LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
|
set(LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
|
||||||
set(CMAKE_FIND_LIBRARY_SUFFIXES "${CMAKE_SHARED_LIBRARY_SUFFIX}")
|
set(CMAKE_FIND_LIBRARY_SUFFIXES "${CMAKE_SHARED_LIBRARY_SUFFIX}")
|
||||||
|
set(HAVE_WINDOWS_ICU OFF)
|
||||||
|
if(LLVM_ENABLE_WINDOWS_ICU AND WIN32 AND CMAKE_SYSTEM_VERSION VERSION_GREATER_EQUAL "10.0.18362")
|
||||||
|
message(STATUS "Use Windows vendored ICU")
|
||||||
|
set(HAVE_WINDOWS_ICU ON)
|
||||||
|
endif()
|
||||||
|
if(NOT HAVE_WINDOWS_ICU)
|
||||||
if (LLVM_ENABLE_ICU STREQUAL FORCE_ON)
|
if (LLVM_ENABLE_ICU STREQUAL FORCE_ON)
|
||||||
find_package(ICU REQUIRED COMPONENTS uc i18n)
|
find_package(ICU REQUIRED COMPONENTS uc i18n)
|
||||||
if (NOT ICU_FOUND)
|
if (NOT ICU_FOUND)
|
||||||
@@ -322,6 +328,9 @@ if(LLVM_ENABLE_ICU AND NOT(LLVM_ENABLE_ICONV STREQUAL FORCE_ON))
|
|||||||
find_package(ICU COMPONENTS uc i18n)
|
find_package(ICU COMPONENTS uc i18n)
|
||||||
endif()
|
endif()
|
||||||
set(HAVE_ICU ${ICU_FOUND})
|
set(HAVE_ICU ${ICU_FOUND})
|
||||||
|
else()
|
||||||
|
set(HAVE_ICU ON)
|
||||||
|
endif()
|
||||||
set(CMAKE_FIND_LIBRARY_SUFFIXES ${LIBRARY_SUFFIXES})
|
set(CMAKE_FIND_LIBRARY_SUFFIXES ${LIBRARY_SUFFIXES})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|||||||
@@ -242,6 +242,9 @@
|
|||||||
/* Define if ICU library is available */
|
/* Define if ICU library is available */
|
||||||
#cmakedefine01 HAVE_ICU
|
#cmakedefine01 HAVE_ICU
|
||||||
|
|
||||||
|
/* Define if Windows vendored ICU is available */
|
||||||
|
#cmakedefine01 HAVE_WINDOWS_ICU
|
||||||
|
|
||||||
/* Define if iconv library is available */
|
/* Define if iconv library is available */
|
||||||
#cmakedefine01 HAVE_ICONV
|
#cmakedefine01 HAVE_ICONV
|
||||||
|
|
||||||
|
|||||||
@@ -42,6 +42,9 @@ if( WIN32 )
|
|||||||
# advapi32 required for CryptAcquireContextW in lib/Support/Windows/Path.inc.
|
# advapi32 required for CryptAcquireContextW in lib/Support/Windows/Path.inc.
|
||||||
# ntdll required for RtlGetLastNtStatus in lib/Support/ErrorHandling.cpp.
|
# ntdll required for RtlGetLastNtStatus in lib/Support/ErrorHandling.cpp.
|
||||||
set(system_libs ${system_libs} psapi shell32 ole32 uuid advapi32 ws2_32 ntdll)
|
set(system_libs ${system_libs} psapi shell32 ole32 uuid advapi32 ws2_32 ntdll)
|
||||||
|
if( HAVE_WINDOWS_ICU )
|
||||||
|
list(APPEND system_libs icu)
|
||||||
|
endif()
|
||||||
elseif( CMAKE_HOST_UNIX )
|
elseif( CMAKE_HOST_UNIX )
|
||||||
if( HAVE_LIBRT )
|
if( HAVE_LIBRT )
|
||||||
set(system_libs ${system_libs} rt)
|
set(system_libs ${system_libs} rt)
|
||||||
@@ -333,7 +336,7 @@ add_llvm_component_library(LLVMSupport
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Link ICU library if it is an external library.
|
# Link ICU library if it is an external library.
|
||||||
if(ICU_FOUND)
|
if(ICU_FOUND AND NOT HAVE_WINDOWS_ICU)
|
||||||
target_link_libraries(LLVMSupport
|
target_link_libraries(LLVMSupport
|
||||||
PRIVATE
|
PRIVATE
|
||||||
${ICU_LIBRARIES}
|
${ICU_LIBRARIES}
|
||||||
|
|||||||
@@ -20,7 +20,11 @@
|
|||||||
#include <system_error>
|
#include <system_error>
|
||||||
|
|
||||||
#if HAVE_ICU
|
#if HAVE_ICU
|
||||||
|
#if HAVE_WINDOWS_ICU
|
||||||
|
#include <icu.h>
|
||||||
|
#else
|
||||||
#include <unicode/ucnv.h>
|
#include <unicode/ucnv.h>
|
||||||
|
#endif
|
||||||
#elif HAVE_ICONV
|
#elif HAVE_ICONV
|
||||||
#include <iconv.h>
|
#include <iconv.h>
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user