Skip to content

Commit c72b4b7

Browse files
authored
Merge pull request #6430 from ppenzin/cmake-embed-icu
Embed ICU via CMake
2 parents 8b38076 + 533bcd8 commit c72b4b7

File tree

13 files changed

+103
-66
lines changed

13 files changed

+103
-66
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ install_manifest.txt
7777
# ICU
7878
deps/Chakra.ICU/Chakra.ICU.props
7979
deps/Chakra.ICU/icu
80+
# CMake External Project
81+
deps/thirdparty
8082

8183
# VIM
8284
.*.swo

CMakeLists.txt

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ if(ICU_SETTINGS_RESET)
7777
unset(NO_ICU_SH CACHE)
7878
unset(LOCAL_ICU_SH CACHE)
7979
unset(SYSTEM_ICU_SH CACHE)
80+
unset(EMBED_ICU_SH CACHE)
8081
endif()
8182

8283
if(CC_TARGET_OS_ANDROID_SH)
@@ -135,7 +136,47 @@ else()
135136
set(INTL_ICU 0)
136137
endif()
137138

138-
if(ICU_INCLUDE_PATH)
139+
if(EMBED_ICU_SH)
140+
set(EMBED_ICU 1)
141+
unset(EMBED_ICU_SH CACHE)
142+
endif()
143+
144+
if(EMBED_ICU AND ICU_INCLUDE_PATH)
145+
message(FATAL_ERROR "Embedded ICU and ICU include path cannot be set at the same time")
146+
endif()
147+
148+
if(EMBED_ICU)
149+
# Keep consistent with what ICU download script used to print
150+
message("Note: ICU installation and use is subject to it's publisher's licensing terms")
151+
152+
set(ICU_PREFIX ${CMAKE_CURRENT_SOURCE_DIR}/deps/thirdparty/icu)
153+
set(ICU_DOWNLOAD_DIR ${ICU_PREFIX}/download)
154+
set(ICU_SOURCE_DIR ${ICU_PREFIX}/stage)
155+
set(EMBEDDED_ICU_TARGET icu4c)
156+
set(ICU_INCLUDE_PATH ${ICU_PREFIX}/include)
157+
set(ICU_LIBRARY_PATH ${ICU_PREFIX}/lib)
158+
add_definitions(-DHAS_REAL_ICU=1)
159+
add_definitions(-DHAS_ICU)
160+
add_definitions(-DINTL_ICU=1)
161+
set(ICU_LIBRARIES
162+
${ICU_LIBRARY_PATH}/libicuuc.a
163+
${ICU_LIBRARY_PATH}/libicui18n.a
164+
${ICU_LIBRARY_PATH}/libicudata.a
165+
)
166+
167+
include(ExternalProject)
168+
ExternalProject_Add(${EMBEDDED_ICU_TARGET}
169+
PREFIX ${ICU_PREFIX}
170+
DOWNLOAD_DIR ${ICU_DOWNLOAD_DIR}
171+
SOURCE_DIR ${ICU_SOURCE_DIR}
172+
URL https://github.com/unicode-org/icu/releases/download/release-63-2/icu4c-63_2-src.tgz
173+
URL_HASH SHA512=5fa9092efd8d6da6dfc8d498e4026167fda43423eaafc754d1789cf8fd4f6e76377878ebcaa32e14f314836136b764873511a93bfbcc5419b758841cc6df8f32
174+
CONFIGURE_COMMAND ${ICU_SOURCE_DIR}/source/configure --prefix=${ICU_PREFIX} --with-data-packaging=static --enable-static --disable-shared --with-library-bits=64 --disable-icuio --disable-layout --disable-tests --disable-samples
175+
BUILD_COMMAND make STATICCFLAGS="-fPIC" STATICCXXFLAGS="-fPIC" STATICCPPFLAGS="-DPIC"
176+
INSTALL_COMMAND make install
177+
BYPRODUCTS ${ICU_LIBRARIES}
178+
)
179+
elseif(ICU_INCLUDE_PATH)
139180
add_definitions(-DHAS_REAL_ICU=1)
140181
add_definitions(-DHAS_ICU)
141182
set(ICU_LIBRARY_PATH "${ICU_INCLUDE_PATH}/../lib/")

bin/ch/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ elseif(CC_TARGET_OS_OSX)
109109
endif()
110110
endif()
111111

112-
113112
target_link_libraries (ch
114113
${lib_target}
115114
${CC_LTO_ENABLED}

bin/ch/WScriptJsrt.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
44
//-------------------------------------------------------------------------------------------------------
55
#include "stdafx.h"
6+
#include "PlatformAgnostic/ChakraICU.h"
67
#include <vector>
78

89
#if defined(_X86_) || defined(_M_IX86)

bin/ch/ch.vcxproj

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,11 @@
2323
%(AdditionalIncludeDirectories);
2424
$(MSBuildThisFileDirectory);
2525
$(ChakraCoreRootDirectory)Lib\Common;
26+
$(ChakraCoreRootDirectory)Lib\Runtime;
2627
$(ChakraCoreRootDirectory)Bin\ChakraCore;
2728
$(IntDir);
2829
%(AdditionalIncludeDirectories);
2930
</AdditionalIncludeDirectories>
30-
<!-- For ChakraICU.h -->
31-
<AdditionalIncludeDirectories Condition="'$(ChakraICU)'!='false'">
32-
$(ChakraCoreRootDirectory)lib\Runtime;
33-
%(AdditionalIncludeDirectories)
34-
</AdditionalIncludeDirectories>
3531
</ClCompile>
3632
<Link>
3733
<ModuleDefinitionFile>ch.def</ModuleDefinitionFile>

build.sh

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -406,42 +406,7 @@ while [[ $# -gt 0 ]]; do
406406
done
407407

408408
if [[ $USE_LOCAL_ICU == 1 ]]; then
409-
LOCAL_ICU_DIR="$CHAKRACORE_DIR/deps/Chakra.ICU/icu"
410-
if [[ ! -d $LOCAL_ICU_DIR ]]; then
411-
"$PYTHON2_BINARY" "$CHAKRACORE_DIR/tools/icu/configure.py" 63.2 $ALWAYS_YES
412-
fi
413-
414-
# if there is still no directory, then the user declined the license agreement
415-
if [[ ! -d $LOCAL_ICU_DIR ]]; then
416-
echo "You must accept the ICU license agreement in order to use this configuration"
417-
exit 1
418-
fi
419-
420-
LOCAL_ICU_DIST="$LOCAL_ICU_DIR/output"
421-
422-
if [ ! -d "$LOCAL_ICU_DIST" ]; then
423-
set -e
424-
425-
pushd "$LOCAL_ICU_DIR/source"
426-
427-
./configure --with-data-packaging=static\
428-
--prefix="$LOCAL_ICU_DIST"\
429-
--enable-static\
430-
--disable-shared\
431-
--with-library-bits=64\
432-
--disable-icuio\
433-
--disable-layout\
434-
--disable-tests\
435-
--disable-samples\
436-
CXXFLAGS="-fPIC"\
437-
CFLAGS="-fPIC"
438-
439-
ERROR_EXIT "rm -rf $LOCAL_ICU_DIST"
440-
make STATICCFLAGS="-fPIC" STATICCXXFLAGS="-fPIC" STATICCPPFLAGS="-DPIC" install
441-
ERROR_EXIT "rm -rf $LOCAL_ICU_DIST"
442-
popd
443-
fi
444-
CMAKE_ICU="-DICU_INCLUDE_PATH_SH=$LOCAL_ICU_DIST/include"
409+
CMAKE_ICU="-DEMBED_ICU_SH=ON"
445410
fi
446411

447412
if [[ "$MAKE" == "ninja" ]]; then

lib/CMakeLists.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,23 @@ if(NOT CC_XCODE_PROJECT)
120120
"${CMAKE_BINARY_DIR}/include"
121121
)
122122
endif(NOT CC_XCODE_PROJECT)
123+
124+
if (EMBED_ICU)
125+
# Declare ICU dependencies in bulk.
126+
# TODO Not the most idiomatic solution, need to understand if all of those
127+
# libraries needed to depend on it
128+
add_dependencies(Chakra.Backend ${EMBEDDED_ICU_TARGET})
129+
add_dependencies(Chakra.Jsrt ${EMBEDDED_ICU_TARGET})
130+
add_dependencies(Chakra.Jsrt.Core ${EMBEDDED_ICU_TARGET})
131+
add_dependencies(Chakra.Parser ${EMBEDDED_ICU_TARGET})
132+
add_dependencies(Chakra.Runtime.Base ${EMBEDDED_ICU_TARGET})
133+
add_dependencies(Chakra.Runtime.ByteCode ${EMBEDDED_ICU_TARGET})
134+
add_dependencies(Chakra.Runtime.Debug ${EMBEDDED_ICU_TARGET})
135+
add_dependencies(Chakra.Runtime.Library ${EMBEDDED_ICU_TARGET})
136+
add_dependencies(Chakra.Runtime.Math ${EMBEDDED_ICU_TARGET})
137+
add_dependencies(Chakra.Runtime.Language ${EMBEDDED_ICU_TARGET})
138+
add_dependencies(Chakra.Runtime.PlatformAgnostic ${EMBEDDED_ICU_TARGET})
139+
add_dependencies(Chakra.Runtime.Types ${EMBEDDED_ICU_TARGET})
140+
add_dependencies(Chakra.SCACore ${EMBEDDED_ICU_TARGET})
141+
add_dependencies(Chakra.WasmReader ${EMBEDDED_ICU_TARGET})
142+
endif()

lib/Common/CommonDefines.h

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -114,25 +114,6 @@
114114
#define ENABLE_UNICODE_API 1 // Enable use of Unicode-related APIs
115115
#endif
116116

117-
// Normalize ICU_VERSION for non-Kit ICU
118-
#if defined(HAS_ICU) && !defined(ICU_VERSION) && !defined(WINDOWS10_ICU)
119-
#include "unicode/uvernum.h"
120-
#define ICU_VERSION U_ICU_VERSION_MAJOR_NUM
121-
#endif
122-
123-
// Make non-Windows Kit ICU look and act like Windows Kit ICU for better compat
124-
#if defined(HAS_ICU) && !defined(WINDOWS10_ICU)
125-
#define U_SHOW_CPLUSPLUS_API 0
126-
// ICU 55 (Ubuntu 16.04 system default) has uloc_toUnicodeLocale* marked as draft, which is required for Intl
127-
#if ICU_VERSION > 56
128-
#define U_DEFAULT_SHOW_DRAFT 0
129-
#define U_HIDE_DRAFT_API 1
130-
#endif
131-
#define U_HIDE_DEPRECATED_API 1
132-
#define U_HIDE_OBSOLETE_API 1
133-
#define U_HIDE_INTERNAL_API 1
134-
#endif
135-
136117
// Language features
137118
#if !defined(CHAKRACORE_LITE) && (defined(_WIN32) || defined(INTL_ICU))
138119
#define ENABLE_INTL_OBJECT // Intl support

lib/Runtime/PlatformAgnostic/ChakraICU.h

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,24 @@
1515
#define NTDDI_VERSION NTDDI_WIN10_RS5
1616
#include <icu.h>
1717
#pragma pop_macro("NTDDI_VERSION")
18-
#else
18+
#else // ifdef WINDOWS10_ICU
19+
// Normalize ICU_VERSION for non-Kit ICU
20+
#ifndef ICU_VERSION
21+
#include "unicode/uvernum.h"
22+
#define ICU_VERSION U_ICU_VERSION_MAJOR_NUM
23+
#endif
24+
25+
// Make non-Windows Kit ICU look and act like Windows Kit ICU for better compat
26+
#define U_SHOW_CPLUSPLUS_API 0
27+
// ICU 55 (Ubuntu 16.04 system default) has uloc_toUnicodeLocale* marked as draft, which is required for Intl
28+
#if ICU_VERSION > 56
29+
#define U_DEFAULT_SHOW_DRAFT 0
30+
#define U_HIDE_DRAFT_API 1
31+
#endif
32+
#define U_HIDE_DEPRECATED_API 1
33+
#define U_HIDE_OBSOLETE_API 1
34+
#define U_HIDE_INTERNAL_API 1
35+
1936
#include "unicode/ucal.h"
2037
#include "unicode/uclean.h"
2138
#include "unicode/ucol.h"
@@ -27,7 +44,7 @@
2744
#include "unicode/ustring.h"
2845
#include "unicode/unorm2.h"
2946
#include "unicode/upluralrules.h"
30-
#endif
47+
#endif // ifdef WINDOWS10_ICU
3148

3249
// Different assertion code is used in ChakraFull that enforces that messages are char literals
3350
#ifdef _CHAKRACOREBUILD
@@ -87,4 +104,4 @@ namespace PlatformAgnostic
87104
}
88105
}
89106
}
90-
#endif
107+
#endif // ifdef HAS_ICU

lib/Runtime/PlatformAgnostic/Platform/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ if(NOT STATIC_LIBRARY)
4141
add_library (Chakra.Runtime.PlatformAgnostic.Singular STATIC
4242
${PL_SOURCE_FILES}
4343
)
44+
if (EMBED_ICU)
45+
add_dependencies(Chakra.Runtime.PlatformAgnostic.Singular ${EMBEDDED_ICU_TARGET})
46+
endif()
4447
target_include_directories (
4548
Chakra.Runtime.PlatformAgnostic.Singular PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}
4649
)

pal/src/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,10 @@ add_library(Chakra.Pal
173173
${ARCH_SOURCES}
174174
)
175175

176+
if(EMBED_ICU)
177+
add_dependencies(Chakra.Pal ${EMBEDDED_ICU_TARGET})
178+
endif()
179+
176180
if (NOT STATIC_LIBRARY)
177181
add_library(Chakra.Pal.Singular
178182
STATIC
@@ -196,4 +200,8 @@ if (NOT STATIC_LIBRARY)
196200
${PTHREAD}
197201
dl
198202
)
203+
204+
if(EMBED_ICU)
205+
add_dependencies(Chakra.Pal.Singular ${EMBEDDED_ICU_TARGET})
206+
endif()
199207
endif()

pal/src/configure.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -913,7 +913,7 @@ else() # Anything else is Linux
913913
set(HAS_FTRUNCATE_LENGTH_ISSUE 0)
914914
endif(CMAKE_SYSTEM_NAME STREQUAL Darwin)
915915

916-
if(NOT NO_ICU)
916+
if(NOT NO_ICU OR EMBED_ICU)
917917
if(NOT HAVE_LIBICU_UCHAR_H)
918918
unset(HAVE_LIBICU_UCHAR_H CACHE)
919919
message(FATAL_ERROR "Cannot find ICU. Try installing libicu-dev or the appropriate packages for your platform. You may also disable icu/unicode with '--no-icu' argument")

tools/icu/configure.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
# Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
55
#-------------------------------------------------------------------------------------------------------
66

7+
#
8+
# TODO build.sh stopped using this script, is it needed?
9+
#
10+
711
from __future__ import print_function
812
import hashlib
913
import os

0 commit comments

Comments
 (0)