Skip to content

Commit

Permalink
[libphonenumber] Enable geocoding and fix its build. Contributes to J…
Browse files Browse the repository at this point in the history
…B#50394
  • Loading branch information
Timur Kristóf committed Dec 18, 2020
1 parent 6f32574 commit 84ab0a9
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 2 deletions.
51 changes: 51 additions & 0 deletions rpm/0001-Fix-geocoding-build-when-static-libraries-are-off.patch
@@ -0,0 +1,51 @@
From 2e0cb4dee43eaf5f4dc256b2c62ff0f9ad39a280 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timur=20Krist=C3=B3f?= <timur.kristof@gmail.com>
Date: Wed, 16 Dec 2020 19:45:36 +0100
Subject: [PATCH] Fix geocoding build when static libraries are off.

---
cpp/CMakeLists.txt | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt
index 696d888d..32005fe6 100644
--- a/cpp/CMakeLists.txt
+++ b/cpp/CMakeLists.txt
@@ -480,7 +480,9 @@ if (${BUILD_GEOCODER} STREQUAL "ON")
list (APPEND GEOCODER_DEPS ${COMMON_DEPS})
# Note that the subset of base/ on which the geocoder relies is implemented
# on top of Boost header-only libraries (e.g. scoped_ptr.hpp).
- target_link_libraries (geocoding ${LIBRARY_DEPS})
+ if (${BUILD_STATIC_LIB} STREQUAL "ON")
+ target_link_libraries (geocoding ${LIBRARY_DEPS})
+ endif ()
target_link_libraries (geocoding-shared ${LIBRARY_DEPS})
endif ()

@@ -647,7 +649,9 @@ if (BUILD_SHARED_LIB)
endif ()

if (${BUILD_GEOCODER} STREQUAL "ON")
- install (TARGETS geocoding LIBRARY DESTINATION ${LIBDIR} ARCHIVE DESTINATION ${LIBDIR})
+ if (${BUILD_STATIC_LIB} STREQUAL "ON")
+ install (TARGETS geocoding LIBRARY DESTINATION ${LIBDIR} ARCHIVE DESTINATION ${LIBDIR})
+ endif ()
install (TARGETS geocoding-shared LIBRARY DESTINATION ${LIBDIR} ARCHIVE
DESTINATION ${LIBDIR})
endif ()
@@ -659,7 +663,11 @@ if (${BUILD_GEOCODER} STREQUAL "ON")
geocoding_test_program
"test/phonenumbers/geocoding/geocoding_test_program.cc"
)
- target_link_libraries (geocoding_test_program geocoding phonenumber)
+ if (${BUILD_STATIC_LIB} STREQUAL "ON")
+ target_link_libraries (geocoding_test_program geocoding phonenumber)
+ else ()
+ target_link_libraries (geocoding_test_program geocoding-shared phonenumber-shared)
+ endif ()
endif ()

# Build an RPM
--
2.29.2

20 changes: 18 additions & 2 deletions rpm/libphonenumber.spec
Expand Up @@ -10,6 +10,9 @@ Source0: %{name}-%{version}.tar.gz
# https://github.com/google/libphonenumber/pull/2482
Patch1: 0001-Add-ability-for-the-C-library-to-link-against-protob.patch

# https://github.com/google/libphonenumber/pull/2556
Patch2: 0001-Fix-geocoding-build-when-static-libraries-are-off.patch

BuildRequires: gcc-c++
BuildRequires: cmake
BuildRequires: protobuf-compiler
Expand All @@ -25,10 +28,18 @@ formatting, storing and validating international phone numbers. The
Java version is optimized for running on smartphones, and is used by
the Android framework since 4.0 (Ice Cream Sandwich).

%package geocoding
Summary: Geocoding library of %{name}
Requires: %{name} = %{version}

%package doc
Summary: Documentation of %{name}
BuildArch: noarch

%description geocoding
Contains geocoding information of %{name}, which can be used to
decide which phone number belongs to which region.

%description doc
Contains documentation files of %{name}.

Expand All @@ -46,7 +57,7 @@ Contains files needed to development with %{name}.
%build

# Explanation of cmake options:
# BUILD_GEOCODER=OFF - we currently don't need the offline geocoder library
# BUILD_GEOCODER=ON - enable the geocoder library
# REGENERATE_METADATA=OFF - don't regenerate metadata with the java based tool
# USE_ALTERNATE_FORMATS=OFF - we don't want to use alternate formatting
# USE_PROTOBUF_LITE=ON - link to protobuf-lite to save some disk space
Expand All @@ -55,7 +66,7 @@ Contains files needed to development with %{name}.
# USE_RE2=OFF - don't use google's re2 library (ICU is already in our default install, RE2 isn't)
# BUILD_STATIC_LIB=OFF - we don't need static libraries

%cmake -DBUILD_GEOCODER=OFF \
%cmake -DBUILD_GEOCODER=ON \
-DREGENERATE_METADATA=OFF \
-DUSE_ALTERNATE_FORMATS=OFF \
-DUSE_PROTOBUF_LITE=ON \
Expand All @@ -82,6 +93,10 @@ Contains files needed to development with %{name}.
%license LICENSE.Chromium
%{_libdir}/libphonenumber.so.*

%files geocoding
%defattr(-, root, root, -)
%{_libdir}/libgeocoding.so.*

%files doc
%defattr(-, root, root, -)
%doc AUTHORS
Expand All @@ -94,3 +109,4 @@ Contains files needed to development with %{name}.
%defattr(-, root, root, -)
%{_includedir}/phonenumbers
%{_libdir}/libphonenumber.so
%{_libdir}/libgeocoding.so

0 comments on commit 84ab0a9

Please sign in to comment.