Skip to content

Commit

Permalink
Add support for ICU library bundled with Windows
Browse files Browse the repository at this point in the history
The UPA_USE_WINDOWS_ICU cmake option variable is added for this purpose
  • Loading branch information
rmisev committed Jul 7, 2024
1 parent c9b7de4 commit ad4ef7e
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 9 deletions.
10 changes: 9 additions & 1 deletion .github/workflows/test-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ jobs:
cxx_standard: 14
cmake_options: ""

- name: VS 2022 C++17 (Windows ICU)
os: windows-2022
generator: "Visual Studio 17 2022"
cxx_standard: 17
cmake_options: "-DUPA_USE_WINDOWS_ICU=ON"

- name: VS 2022 C++23
os: windows-2022
generator: "Visual Studio 17 2022"
Expand All @@ -47,7 +53,9 @@ jobs:
run: init.bat
shell: cmd
- name: cmake
run: cmake -S . -B build -G "${{ matrix.generator }}" -A x64 -DCMAKE_CXX_STANDARD=${{ matrix.cxx_standard }} -DICU_ROOT=C:\LIB\ICU ${{ matrix.cmake_options }}
run: cmake -S . -B build -G "${{ matrix.generator }}" -A x64 -DCMAKE_CXX_STANDARD=${{ matrix.cxx_standard }} ${{ matrix.cmake_options }}
env:
ICU_ROOT: C:\LIB\ICU
- name: build
run: cmake --build build --config Release
- name: test
Expand Down
15 changes: 11 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ option(UPA_BUILD_TOOLS "Build tools." OFF)
option(UPA_INSTALL "Generate the install target." ON)
# library options
option(UPA_AMALGAMATED "Use amalgamated URL library source." OFF)
option(UPA_USE_WINDOWS_ICU "Use ICU library bundled with Windows 10 version 1903 or later." OFF)
# tests build options
option(UPA_TEST_COVERAGE "Build tests with code coverage reporting" OFF)
option(UPA_TEST_COVERAGE_CLANG "Build tests with Clang source-based code coverage" OFF)
Expand Down Expand Up @@ -115,8 +116,10 @@ include_directories(deps)
# Are Upa URL and ICU libraries needed?
if (UPA_BUILD_TESTS OR UPA_BUILD_BENCH OR UPA_BUILD_FUZZER OR UPA_BUILD_EXAMPLES OR
UPA_BUILD_EXTRACTED OR UPA_INSTALL OR NOT UPA_BUILD_TOOLS)
# This library depends on ICU
find_package(ICU REQUIRED COMPONENTS i18n uc)
if (NOT UPA_USE_WINDOWS_ICU)
# This library depends on ICU
find_package(ICU REQUIRED COMPONENTS i18n uc)
endif()

if (UPA_AMALGAMATED)
add_library(${upa_lib_target} STATIC
Expand All @@ -138,8 +141,12 @@ if (UPA_BUILD_TESTS OR UPA_BUILD_BENCH OR UPA_BUILD_FUZZER OR UPA_BUILD_EXAMPLES
add_library(upa::${upa_lib_export} ALIAS ${upa_lib_target})
set_target_properties(${upa_lib_target} PROPERTIES
EXPORT_NAME ${upa_lib_export})
target_include_directories(${upa_lib_target} PRIVATE ${ICU_INCLUDE_DIR})
target_link_libraries(${upa_lib_target} INTERFACE ICU::i18n ICU::uc)
if (UPA_USE_WINDOWS_ICU)
target_compile_definitions(${upa_lib_target} PRIVATE UPA_USE_WINDOWS_ICU=1)
else()
target_include_directories(${upa_lib_target} PRIVATE ${ICU_INCLUDE_DIR})
target_link_libraries(${upa_lib_target} INTERFACE ICU::i18n ICU::uc)
endif()
endif()

# Test targets
Expand Down
20 changes: 16 additions & 4 deletions src/url_idna.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,28 @@
// Copyright 2013 The Chromium Authors. All rights reserved.
//

// Define UPA_USE_WINDOWS_ICU = 1 to use the ICU library bundled with
// Windows 10 version 1903 or later. For more information, see:
// https://learn.microsoft.com/en-us/windows/win32/intl/international-components-for-unicode--icu-
#ifndef UPA_USE_WINDOWS_ICU
# define UPA_USE_WINDOWS_ICU 0 // NOLINT(*-macro-*)
#endif // UPA_USE_WINDOWS_ICU

#include "upa/config.h"
#include "upa/url_idna.h"
#include "upa/util.h"

#if UPA_USE_WINDOWS_ICU
# include <icu.h>
# pragma comment( lib, "icu" )
#else
// ICU: only C API is used (U_SHOW_CPLUSPLUS_API 0)
// https://unicode-org.github.io/icu/userguide/icu4c/build.html#icu-as-a-system-level-library
#define U_SHOW_CPLUSPLUS_API 0 // NOLINT(*-macro-*)
#include "unicode/uchar.h" // u_getUnicodeVersion
#include "unicode/uclean.h"
#include "unicode/uidna.h"
# define U_SHOW_CPLUSPLUS_API 0 // NOLINT(*-macro-*)
# include "unicode/uchar.h" // u_getUnicodeVersion
# include "unicode/uclean.h"
# include "unicode/uidna.h"
#endif

#include <algorithm>
#include <cassert>
Expand Down

0 comments on commit ad4ef7e

Please sign in to comment.