88# Script to build and install libbitcoin-system.
99#
1010# Script options:
11- # --with-icu Compile with International Components for Unicode.
12- # Since the addition of BIP-39 and later BIP-38
13- # support, libbitcoin conditionally incorporates ICU
14- # to provide BIP-38 and BIP-39 passphrase
15- # normalization features. Currently
16- # libbitcoin-explorer is the only other library that
17- # accesses this feature, so if you do not intend to
18- # use passphrase normalization this dependency can
19- # be avoided.
20- # --build-icu Builds ICU libraries.
2111# --build-boost Builds Boost libraries.
2212# --build-dir=<path> Location of downloaded and intermediate files.
2313# --preset=<label> CMakePreset label.
@@ -252,6 +242,8 @@ parse_command_line_options()
252242 (--disable-shared) DISABLE_SHARED=" yes" ;;
253243 (--disable-static) DISABLE_STATIC=" yes" ;;
254244
245+ # Common project options.
246+
255247 # Custom build options.
256248 (--build-boost) BUILD_BOOST=" yes" ;;
257249 (--build-secp256k1) BUILD_SECP256K1=" yes" ;;
@@ -407,7 +399,6 @@ handle_custom_options()
407399 export CMAKE_LIBRARY_PATH=" ${PREFIX} /lib:${CMAKE_LIBRARY_PATH} "
408400 fi
409401 fi
410-
411402}
412403
413404remove_build_options ()
@@ -767,6 +758,23 @@ build_from_github_cmake()
767758 cmake_project_directory " $REPO " " $PRESET " " $JOBS " " $TEST " " ${CONFIGURATION[@]} "
768759}
769760
761+ # Because boost ICU static lib detection assumes in incorrect ICU path.
762+ circumvent_boost_icu_detection ()
763+ {
764+ # Boost expects a directory structure for ICU which is incorrect.
765+ # Boost ICU discovery fails when using prefix, can't fix with -sICU_LINK,
766+ # so we rewrite the two 'has_icu_test.cpp' files to always return success.
767+
768+ local SUCCESS=" int main() { return 0; }"
769+ local REGEX_TEST=" libs/regex/build/has_icu_test.cpp"
770+ local LOCALE_TEST=" libs/locale/build/has_icu_test.cpp"
771+
772+ printf " %s" " $SUCCESS " > $REGEX_TEST
773+ printf " %s" " $SUCCESS " > $LOCALE_TEST
774+
775+ # display_message "Hack: ICU detection modified, will always indicate found."
776+ }
777+
770778# Because boost doesn't support autoconfig and doesn't like empty settings.
771779initialize_boost_configuration ()
772780{
@@ -789,6 +797,32 @@ initialize_boost_configuration()
789797 fi
790798}
791799
800+ # Because boost doesn't use pkg-config.
801+ # The hacks below are still required as of boost 1.72.0.
802+ initialize_boost_icu_configuration ()
803+ {
804+ BOOST_ICU_ICONV=" on"
805+ BOOST_ICU_POSIX=" on"
806+
807+ if [[ $WITH_ICU ]]; then
808+ # Restrict other locale options when compiling boost with icu.
809+ BOOST_ICU_ICONV=" off"
810+ BOOST_ICU_POSIX=" off"
811+
812+ # Work around boost ICU static lib discovery bug.
813+ circumvent_boost_icu_detection
814+
815+ # Extract ICU prefix directory from package config variable.
816+ ICU_PREFIX=$( pkg-config icu-i18n --variable=prefix)
817+
818+ # Extract ICU libs from package config variables and augment with -ldl.
819+ ICU_LIBS=" $( pkg-config icu-i18n --libs) -ldl"
820+
821+ # This is a hack for boost m4 scripts that fail with ICU dependency.
822+ export BOOST_ICU_LIBS=(" ${ICU_LIBS[@]} " )
823+ fi
824+ }
825+
792826# Because boost doesn't use autoconfig.
793827build_from_tarball_boost ()
794828{
@@ -811,6 +845,7 @@ build_from_tarball_boost()
811845 push_directory " $TARGET "
812846
813847 initialize_boost_configuration
848+ initialize_boost_icu_configuration
814849
815850 guessed_toolset=` ./tools/build/src/engine/build.sh --guess-toolset`
816851 CXXFLAGS=" -w" ./tools/build/src/engine/build.sh ${guessed_toolset} --cxxflags=" -w"
@@ -829,8 +864,12 @@ build_from_tarball_boost()
829864 display_message " boost cxxflags : $BOOST_CXXFLAGS "
830865 display_message " boost linkflags : $BOOST_LINKFLAGS "
831866 display_message " link : $BOOST_LINK "
867+ display_message " boost.locale.iconv : $BOOST_ICU_ICONV "
868+ display_message " boost.locale.posix : $BOOST_ICU_POSIX "
832869 display_message " -sNO_BZIP2 : 1"
833870 display_message " -sNO_ZSTD : 1"
871+ display_message " -sICU_PATH : $ICU_PREFIX "
872+ # display_message "-sICU_LINK : " "${ICU_LIBS[*]}"
834873 display_message " -j : $JOBS "
835874 display_message " -d0 : [supress informational messages]"
836875 display_message " -q : [stop at the first error]"
@@ -842,7 +881,14 @@ build_from_tarball_boost()
842881
843882 ./bootstrap.sh \
844883 " --with-bjam=./b2" \
845- " --prefix=$PREFIX "
884+ " --prefix=$PREFIX " \
885+ " --with-icu=$ICU_PREFIX "
886+
887+ # boost_regex:
888+ # As of boost 1.72.0 the ICU_LINK symbol is no longer supported and
889+ # produces a hard stop if WITH_ICU is also defined. Removal is sufficient.
890+ # github.com/libbitcoin/libbitcoin-system/issues/1192
891+ # "-sICU_LINK=${ICU_LIBS[*]}"
846892
847893 ./b2 install \
848894 " cxxstd=20" \
@@ -853,8 +899,11 @@ build_from_tarball_boost()
853899 " $BOOST_LINKFLAGS " \
854900 " link=$BOOST_LINK " \
855901 " warnings=off" \
902+ " boost.locale.iconv=$BOOST_ICU_ICONV " \
903+ " boost.locale.posix=$BOOST_ICU_POSIX " \
856904 " -sNO_BZIP2=1" \
857905 " -sNO_ZSTD=1" \
906+ " -sICU_PATH=$ICU_PREFIX " \
858907 " -j $JOBS " \
859908 " -d0" \
860909 " -q" \
0 commit comments