blob: 4ce705005a54c83c5c913839190e8222e626247c [file] [log] [blame]
David Beaumont14dc2152014-11-28 15:49:34 +00001 C++ version of the libphonenumber project
2 =========================================
Philip Liarda3802a32011-02-22 08:04:03 +00003
David Beaumont14dc2152014-11-28 15:49:34 +00004This library is a port of the Java version.
Philip Liarda3802a32011-02-22 08:04:03 +00005
6This project uses some third-party code:
Philippe Liardae165b12011-11-30 10:42:30 +00007 - src/phonenumbers/utf/ sources come from lib9 which is also used in Go.
Philip Liarda3802a32011-02-22 08:04:03 +00008
Philippe Liardb9a0d782011-12-07 14:52:33 +00009
David Beaumont14dc2152014-11-28 15:49:34 +000010Installing the library on GNU/Linux
11-----------------------------------
12In recent Debian-based distributions you may be able to simply install the
13libphonenumber library directly.
14
15Installing the binary packages:
16 - Use this if you just need to use or link against the library:
17 $ sudo apt-get install libphonenumber6 libphonenumber6-dev
18
19Installing the source package:
20 - Use this if you wish to develop or debug the library:
21 $ sudo apt-get source libphonenumber
22
23The latest packages can be found on the Debian packages site:
24 https://packages.debian.org/search?searchon=names&keywords=libphonenumber
25
26
27Manually installing the library on GNU/Linux
28--------------------------------------------
29You should only need these instructions if the above instructions do not work.
30
31The example command lines below assume that you have a Debian-based GNU/Linux
32distribution. Other distributions and packaging systems will differ.
33
34Quickstart:
35 - In recent Debian-based distributions, it should be sufficent to run:
36 $ sudo apt-get install \
37 cmake cmake-curses-gui libprotobuf-dev libgtest-dev libre2-dev \
38 libicu-dev libboost-dev libboost-thread-dev libboost-system-dev
39
40If any of these packages fails to install correctly, follow the instructions
41in the appropriate section below.
42
Philip Liarda3802a32011-02-22 08:04:03 +000043Requirements:
44 - CMake build system
45 http://www.cmake.org
46
David Beaumont14dc2152014-11-28 15:49:34 +000047 Installation:
Philip Liarda3802a32011-02-22 08:04:03 +000048 $ sudo apt-get install cmake
49
David Beaumont1b31d8e2012-07-19 13:31:07 +000050 Additionally it is recommended you install the ccmake configuration tool:
51 $ sudo apt-get install cmake-curses-gui
52
Philip Liardff0ef172011-03-04 08:43:24 +000053 - Protocol Buffers
54 http://code.google.com/p/protobuf/
David Beaumont14dc2152014-11-28 15:49:34 +000055 Version 2.4 or more recent is required (this is available by default for
56 recent Debian-based GNU/Linux distributions).
Philip Liardff0ef172011-03-04 08:43:24 +000057
David Beaumont14dc2152014-11-28 15:49:34 +000058 You can check which version is available:
Keghani Kouzoujian40f3fe02016-03-31 16:06:54 +020059 $ apt-cache show libprotobuf-dev
David Beaumont14dc2152014-11-28 15:49:34 +000060 Package: libprotobuf-dev
61 Source: protobuf
62 Version: 2.5.0-9ubuntu1 <-- This must be >= 2.4.0
63 ...
64
65 Installation:
Philip Liardff0ef172011-03-04 08:43:24 +000066 $ sudo apt-get install libprotobuf-dev
67
Shaopeng Jia4628c702011-03-24 09:10:31 +000068 Note: if your GNU/Linux distribution doesn't provide the needed package,
69 please download and install it manually:
70 $ tar xjf protobuf-2.4.tar.bz2
71 $ cd protobuf-2.4
72 $ ./configure && make && sudo make install
73
Philip Liardff0ef172011-03-04 08:43:24 +000074 - Google Test
75 http://code.google.com/p/googletest/
76
David Beaumont14dc2152014-11-28 15:49:34 +000077 Installation:
Philip Liardff0ef172011-03-04 08:43:24 +000078 $ sudo apt-get install libgtest-dev
79
Philip Liarda3802a32011-02-22 08:04:03 +000080 - RE2
81 http://code.google.com/p/re2/
82
David Beaumont14dc2152014-11-28 15:49:34 +000083 Installation:
Philip Liarda3802a32011-02-22 08:04:03 +000084 $ sudo apt-get install libre2-dev
85
David Beaumont14dc2152014-11-28 15:49:34 +000086 Note that some distributions (notably Ubuntu 10.4) may not include this,
87 so you might need to download and install it manually.
Philip Liarda3802a32011-02-22 08:04:03 +000088
David Beaumont14dc2152014-11-28 15:49:34 +000089 Find and download the Debian packages for your system. For example:
90 http://packages.ubuntu.com/utopic/libre2-1
91 http://packages.ubuntu.com/utopic/libre2-dev
Philip Liarda3802a32011-02-22 08:04:03 +000092
David Beaumont14dc2152014-11-28 15:49:34 +000093 You need to download both the libre2-dev and libre2-1 packages.
94 Once downloaded, install them with:
95 $ sudo dpkg -i libre2*.deb
96
97 If you want to install it from source, it's available via Mercurial at:
98 https://re2.googlecode.com/hg
99 however precise instructions on building and installing are outside the
100 scope of this document.
Philip Liarda3802a32011-02-22 08:04:03 +0000101
Philip Liard8e7e1b92011-03-03 14:35:27 +0000102 - ICU
David Beaumont14dc2152014-11-28 15:49:34 +0000103 Installation:
David Beaumont1b31d8e2012-07-19 13:31:07 +0000104 $ sudo apt-get install libicu-dev
105
106 Otherwise you need to download the source tarball for the latest version
107 from:
108 http://site.icu-project.org/download
109 And then extract it via:
David Beaumont14dc2152014-11-28 15:49:34 +0000110 $ tar xzf icu4c-*-src.tgz
David Beaumont1b31d8e2012-07-19 13:31:07 +0000111
112 Alternatively you can export the SVN repository to the current directory
113 via:
David Beaumont14dc2152014-11-28 15:49:34 +0000114 $ svn export http://source.icu-project.org/repos/icu/icu/tags/release-XX-y-z/
David Beaumont1b31d8e2012-07-19 13:31:07 +0000115
116 Having acquired the latest sources, make and install it via:
Philip Liard69921332011-06-06 08:15:16 +0000117 $ cd icu/source
118 $ ./configure && make && sudo make install
Philip Liard8e7e1b92011-03-03 14:35:27 +0000119
Philip Liard486cbd92011-06-07 14:41:10 +0000120 - Boost
Philippe Liard9f0d77e2013-04-30 12:08:05 +0000121 Version 1.40 or more recent is required if you need libphonenumber to be
122 thread-safe. If you access libphonenumber from a single thread, you can
123 avoid the Boost dependency by disabling the USE_BOOST CMake option (see
124 Troubleshooting section below for information about ccmake).
Philip Liard486cbd92011-06-07 14:41:10 +0000125
126 You can install it very easily on a Debian-based GNU/Linux distribution:
David Beaumont14dc2152014-11-28 15:49:34 +0000127 $ sudo apt-get install libboost-dev libboost-thread-dev libboost-system-dev
Philip Liard486cbd92011-06-07 14:41:10 +0000128
129 Note: Boost Thread is the only library needed at link time.
Philip Liarda3802a32011-02-22 08:04:03 +0000130
David Beaumont14dc2152014-11-28 15:49:34 +0000131
David Beaumonta34ddc92015-03-06 13:53:07 +0100132Building and testing the library
133--------------------------------
David Beaumont1b31d8e2012-07-19 13:31:07 +0000134 $ cd libphonenumber/cpp
Philip Liarda3802a32011-02-22 08:04:03 +0000135 $ mkdir build
136 $ cd build
Philippe Liard7b30af62011-09-21 17:43:54 +0000137 $ cmake ..
Philip Liarda3802a32011-02-22 08:04:03 +0000138 $ make
David Beaumonta34ddc92015-03-06 13:53:07 +0100139 $ ./libphonenumber_test
David Beaumont14dc2152014-11-28 15:49:34 +0000140
Keghani Kouzoujian40f3fe02016-03-31 16:06:54 +0200141
142Manually installing the library on Mac
143--------------------------------------
144
145You can easily install dependencies on Mac using a package manager. In these
146instructions we use Homebrew (http://brew.sh).
147
148Install Homebrew package manager and use it to install dependencies:
149 $ /usr/bin/ruby -e "$(curl -fsSL \
150 https://raw.githubusercontent.com/Homebrew/install/master/install)"
151 $ brew install boost cmake icu4c pkg-config protobuf wget
152
153See https://github.com/Homebrew/homebrew/issues/14099 - homebrew does not have
154gtest. We don't need to install gtest, we only copy sources. For example:
155 $ mkdir ~/googletest_clone
156 $ cd ~/googletest_clone
157 $ git clone https://github.com/google/googletest.git
158
159Get the libphonenumber source. For example:
160 $ mkdir ~/libphonenumber_clone
161 $ cd ~/libphonenumber_clone
162 $ git clone https://github.com/googlei18n/libphonenumber.git
163
164Build and test the library:
165 $ cd libphonenumber/cpp
166 $ mkdir build
167 $ cd build
168 Replace XXX with the appropriate version number:
169 $ cmake \
170 -DGTEST_SOURCE_DIR=~/googletest_clone/googletest/googletest/ \
171 -DGTEST_INCLUDE_DIR=~/googletest_clone/googletest/googletest/include/ \
172 -DICU_UC_INCLUDE_DIR=/usr/local/Cellar/icu4c/XXX/include/ \
173 -DICU_UC_LIB=/usr/local/Cellar/icu4c/XXX/lib/libicuuc.dylib \
174 -DICU_I18N_INCLUDE_DIR=/usr/local/Cellar/icu4c/XXX/include/ \
175 -DICU_I18N_LIB=/usr/local/Cellar/icu4c/XXX/lib/libicui18n.dylib \
176 -DUSE_STD_MAP=ON \
177 ..
178 $ make
179 $ ./libphonenumber_test
180
181Optional: Deleting & uninstalling everything again:
182 $ cd
183 $ rm -rf ~/libphonenumber_clone ~/googletest_clone
184
185 openssl is a dependency of wget and installed with it by Homebrew. If you had
186 openssl before installing wget don't uninstall here.
187 $ brew uninstall boost cmake icu4c openssl pkg-config protobuf wget
188
189 $ /usr/bin/ruby -e "$(curl -fsSL \
190 https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"
191
192 Homebrew will have changed permissions at installation. See output of previous
193 command for how to change them back, for example:
194 $ sudo chmod 0755 /usr/local
195 $ sudo chgrp wheel /usr/local
196
197
David Beaumont14dc2152014-11-28 15:49:34 +0000198Troubleshooting CMake via ccmake
199--------------------------------
David Beaumont1b31d8e2012-07-19 13:31:07 +0000200 Follow these instructions if the build steps above don't work for you.
201
202 - Incorrect protocol buffer library issues
203 If the build process complains that the version of protoc being used is too
204 old or that it cannot find the correct libprotobuf library, you may need to
205 change the library path of the project.
206
207 This issue should typically only occur in cases where you have two (or more)
208 versions of the protocol buffer libraries installed on your system. This
209 step assumes that you have already manually downloaded and installed the
210 protocol buffer libraries into /usr/local (as described above).
211
212 To make cmake use the manually installed version of the protocol buffer
213 libraries, install cmake-curses-gui and use ccmake as follows.
214
215 From within libphonenumber/cpp/build:
216 $ ccmake .
217
218 You should set the following values:
219 PROTOBUF_INCLUDE_DIR /usr/local/include
220 PROTOBUF_LIB /usr/local/lib/libprotobuf.so
221 PROTOC_BIN /usr/local/bin/protoc
222
223 Now press 'c' then 'g' to configure the new parameters and exit ccmake.
224 Finally regenerate the make files and rebuild via:
225 $ cmake ..
226 $ make
227
228 - Protoc binary not executing properly
229 If you still have issues with the protoc binary tool in /usr/local/bin not
230 running correctly (cannot find libprotobuf.so.x) then you may need to
231 configure the LD_LIBRARY_PATH. To do this, as a superuser, add the following
232 file:
233 /etc/ld.so.conf.d/libprotobuf.conf
234
235 with the contents:
236 # Use the manually installed version of the protocol buffer libraries.
237 /usr/local/lib
238
239 And then run:
240 $ sudo chmod 644 /etc/ld.so.conf.d/libprotobuf.conf
241 $ sudo ldconfig
242
243 - Incorrect ICU library issues
244 Similar to the protocol buffer library issue above, it is possible that your
245 build may fail if you have two conflicting versions of the ICU libraries
246 installed on your system. This step assumes that you have already manually
247 downloaded and installed a recent version of the ICU libraries into
248 /usr/local.
249
250 Install and run the ccmake tool (as described above) and set the following
251 values:
252 ICU_I18N_INCLUDE_DIR /usr/local/include
253 ICU_I18N_LIB /usr/local/lib/libicui18n.so
254 ICU_UC_INCLUDE_DIR /usr/local/include
255 ICU_UC_LIB /usr/local/lib/libicuuc.so
256
257 Now press 'c' then 'g' to configure the new parameters and exit ccmake.
258 Finally regenerate the make files and rebuild via:
259 $ cmake ..
260 $ make
Philippe Liardb9a0d782011-12-07 14:52:33 +0000261
Keghani Kouzoujian40f3fe02016-03-31 16:06:54 +0200262
Philippe Liardb9a0d782011-12-07 14:52:33 +0000263Building the library on Windows (Visual Studio)
264-----------------------------------------------
265The library was tested with Visual Studio 2010.
266
267You will need to manually fetch and install the following dependencies:
268 - CMake (tested with v2.8.6):
269 http://cmake.org/cmake/resources/software.html
270 * Download and install the Win32 installer.
271
272 - Boost (tested with v1.44) from BoostPro:
273 http://www.boostpro.com/download/
274 * Select all the variants and Boost DateTime and Boost Thread during the
275 installation process.
Philippe Liard9f0d77e2013-04-30 12:08:05 +0000276 See Linux instructions for information about thread-safety.
Philippe Liardb9a0d782011-12-07 14:52:33 +0000277
278 - GTest (tested with v1.6.0):
279 http://code.google.com/p/googletest/downloads/list
280 * Open msvc/gtest-md.sln with Visual Studio and build the whole solution.
281
282 - ICU (MSVC binaries, tested with v4.8.1):
283 http://site.icu-project.org/download/48#ICU4C-Download
284 * Simply extract the archive.
285
286 - Protocol Buffers:
287 http://code.google.com/p/protobuf/downloads/list
288 * Open vsprojects/protobuf.sln with Visual Studio and build the whole
289 solution.
290
291Then run cmake-gui and specify the path to the libphonenumber's cpp directory
292and its build directory which must be created (e.g. cpp/build).
293
294When clicking on "Configure", specify the appropriate Visual Studio version
295(tested with 2010).
296
297Then CMake will need your help to locate the dependencies. You will have to set
298the following variables (this example assumes that you extracted the
299dependencies to C:/).
300
301GTEST_INCLUDE_DIR C:/gtest-1.6.0/include
302GTEST_LIB C:/gtest-1.6.0/msvc/gtest-md/Release/gtest.lib
303
304ICU_I18N_INCLUDE_DIR C:/icu/include
305ICU_I18N_LIB C:/icu/lib/icuin.lib
306
307ICU_UC_INCLUDE_DIR C:/icu/include
308ICU_UC_LIB C:/icu/lib/icuuc.lib
309
310PROTOBUF_INCLUDE_DIR C:/protobuf-2.4.1/src
311PROTOBUF_LIB C:/protobuf-2.4.1/vsprojects/Release/libprotobuf.lib
312PROTOC_BIN C:/protobuf-2.4.1/vsprojects/Release/protoc.exe
313
314Then you can click on "Configure" again. CMake should have located all the
315dependencies.
316Then click on "Generate" to generate the appropriate Visual Studio project.
317Then open cpp/build/libphonenumber.sln with Visual Studio and build the INSTALL
318target.
319
320As a result the library's headers and binaries should have been installed to
321C:/Program Files/libphonenumber/.
322Note that this path can be set by overriding the CMAKE_INSTALL_PREFIX variable
323with cmake-gui.
324
Keghani Kouzoujian40f3fe02016-03-31 16:06:54 +0200325
Philippe Liardb9a0d782011-12-07 14:52:33 +0000326Supported build parameters
327--------------------------
Philip Liardb36c48f2011-05-09 15:04:24 +0000328 Build parameters can be specified invoking CMake with '-DKEY=VALUE' or using a
329 CMake user interface (ccmake or cmake-gui).
330
Philippe Liardb8a13bf2013-05-07 12:59:58 +0000331 USE_ALTERNATE_FORMATS = ON | OFF [ON] -- Use alternate formats for the phone
332 number matcher.
333 USE_BOOST = ON | OFF [ON] -- Use Boost. This is only needed in
Philippe Liardc2f27522013-06-17 11:53:01 +0000334 multi-threaded environments that
335 are not Linux and Mac.
336 Libphonenumber relies on Boost for
337 non-POSIX (e.g. Windows)
338 multi-threading.
Philippe Liardb8a13bf2013-05-07 12:59:58 +0000339 USE_ICU_REGEXP = ON | OFF [ON] -- Use ICU regexp engine.
340 USE_LITE_METADATA = ON | OFF [OFF] -- Generates smaller metadata that
341 doesn't include example numbers.
342 USE_RE2 = ON | OFF [OFF] -- Use RE2.
343 USE_STD_MAP = ON | OFF [OFF] -- Force the use of std::map.