Source

libphonenumber-csharp / cpp / CMakeLists.txt

phil...@gmail.co… 2e2d74a 
jia....@ee073f10… 1bf548f 












jia....@ee073f10… 5846899 

jia....@ee073f10… 1bf548f 


phil...@gmail.co… 51cb4a2 
phil...@gmail.co… 84729f3 
jia....@ee073f10… 1bf548f 
jia....@ee073f10… 138c330 

jia....@ee073f10… 1bf548f 
jia....@ee073f10… 138c330 
jia....@ee073f10… 1bf548f 
jia....@ee073f10… 138c330 

jia....@ee073f10… 1bf548f 
jia....@ee073f10… 138c330 




jia....@ee073f10… 9072173 
jia....@ee073f10… 1bf548f 
jia....@ee073f10… 138c330 






jia....@ee073f10… 1bf548f 
jia....@ee073f10… 138c330 



jia....@ee073f10… 1bf548f 
jia....@ee073f10… 138c330 

jia....@ee073f10… 567a4da 

phil...@gmail.co… 0764099 
jia....@ee073f10… 567a4da 
jia....@ee073f10… 138c330 
jia....@ee073f10… 1bf548f 
jia....@ee073f10… 138c330 



jia....@ee073f10… 1bf548f 
jia....@ee073f10… 138c330 



jia....@ee073f10… 1bf548f 
lara...@google.c… 9272323 
phil...@gmail.co… 6099edf 
lara...@google.c… 9272323 
phil...@gmail.co… 6099edf 
phil...@gmail.co… 07044b7 
lara...@google.c… 9272323 
jia....@ee073f10… 138c330 
phil...@gmail.co… c55f0c4 



jia....@ee073f10… db43256 
phil...@gmail.co… c55f0c4 
jia....@ee073f10… db43256 


jia....@ee073f10… 138c330 
jia....@ee073f10… 1bf548f 
lara...@google.c… 9272323 


jia....@ee073f10… 1bf548f 
jia....@ee073f10… 138c330 

jia....@ee073f10… 567a4da 
jia....@ee073f10… 1bf548f 
lara...@google.c… 9272323 
jia....@ee073f10… 567a4da 

lara...@google.c… 9272323 


phil...@gmail.co… 6099edf 
lara...@google.c… 9272323 
jia....@ee073f10… 567a4da 
lara...@google.c… 9272323 


jia....@ee073f10… 1bf548f 
jia....@ee073f10… 138c330 

jia....@ee073f10… 1bf548f 
jia....@ee073f10… 8c15ee4 


jia....@ee073f10… d29d18c 




phil...@gmail.co… 07044b7 




jia....@ee073f10… d29d18c 


jia....@ee073f10… 138c330 
jia....@ee073f10… bb84162 

jia....@ee073f10… 1bf548f 
jia....@ee073f10… bb84162 

jia....@ee073f10… 1bf548f 


phil...@gmail.co… 2041cbe 



jia....@ee073f10… 1bf548f 


phil...@gmail.co… 2041cbe 
jia....@ee073f10… bb84162 
jia....@ee073f10… 1bf548f 











phil...@gmail.co… ded7f23 



















lara...@google.c… 977d692 


phil...@gmail.co… 233cdc8 
phil...@gmail.co… 2041cbe 
phil...@gmail.co… 3ce36e4 

phil...@gmail.co… ded7f23 
phil...@gmail.co… 528eb95 
phil...@gmail.co… 2041cbe 





dav...@google.co… 28c2d8d 
phil...@gmail.co… 13df3cd 
phil...@gmail.co… 2041cbe 
phil...@gmail.co… 233cdc8 
phil...@gmail.co… 2041cbe 


lara...@google.c… 977d692 

phil...@gmail.co… 6099edf 
lara...@google.c… 9272323 
phil...@gmail.co… cca39cc 

phil...@gmail.co… 6099edf 

phil...@gmail.co… cca39cc 
phil...@gmail.co… 2041cbe 
phil...@gmail.co… 6099edf 



phil...@gmail.co… 2041cbe 
phil...@gmail.co… 6099edf 
dbea...@google.c… cb73715 
phil...@gmail.co… 6099edf 

lara...@google.c… 9272323 

lara...@google.c… 977d692 



jia....@ee073f10… 8c15ee4 

lara...@google.c… 977d692 

jia....@ee073f10… 8c15ee4 

dbea...@google.c… cb73715 

phil...@gmail.co… 2041cbe 
lara...@google.c… 977d692 
dbea...@google.c… cb73715 
jia....@ee073f10… 8c15ee4 




phil...@gmail.co… 2041cbe 

jia....@ee073f10… 8c15ee4 










lara...@google.c… 977d692 






dbea...@google.c… cb73715 
lara...@google.c… 977d692 
phil...@gmail.co… 2041cbe 
lara...@google.c… 977d692 






dbea...@google.c… cb73715 
lara...@google.c… 977d692 
phil...@gmail.co… 2041cbe 
lara...@google.c… 977d692 



jia....@ee073f10… 8c15ee4 
lara...@google.c… 977d692 


dbea...@google.c… cb73715 
jia....@ee073f10… 8c15ee4 
phil...@gmail.co… 2041cbe 
phil...@gmail.co… 56a9d50 
dbea...@google.c… cb73715 










phil...@gmail.co… 56a9d50 


lara...@google.c… 977d692 
jia....@ee073f10… 1bf548f 
jia....@ee073f10… 138c330 
jia....@ee073f10… d8e859d 
jia....@ee073f10… 1bf548f 
lara...@google.c… 977d692 
dbea...@google.c… cb73715 


jia....@ee073f10… 1bf548f 
jia....@ee073f10… d8e859d 
jia....@ee073f10… 64c367a 














dbea...@google.c… cb73715 


jia....@ee073f10… 64c367a 
jia....@ee073f10… d4ebfa8 




jia....@ee073f10… 64c367a 
jia....@ee073f10… d8e859d 
jia....@ee073f10… db43256 
lara...@google.c… 9272323 



jia....@ee073f10… 1bf548f 
jia....@ee073f10… d29d18c 
lara...@google.c… 977d692 
jia....@ee073f10… d29d18c 

lara...@google.c… 0f8cfa0 
jia....@ee073f10… 64c367a 



lara...@google.c… 977d692 





phil...@gmail.co… ded7f23 









phil...@gmail.co… e111038 
phil...@gmail.co… ded7f23 





jia....@ee073f10… 1bf548f 
phil...@gmail.co… 233cdc8 
phil...@gmail.co… 3ce36e4 
phil...@gmail.co… e111038 
phil...@gmail.co… ded7f23 
phil...@gmail.co… 528eb95 
phil...@gmail.co… 1ffa578 




dav...@google.co… 28c2d8d 
phil...@gmail.co… 1ffa578 
phil...@gmail.co… 6099edf 
phil...@gmail.co… 233cdc8 
phil...@gmail.co… 1ffa578 
jia....@ee073f10… 1bf548f 
phil...@gmail.co… 6099edf 




jia....@ee073f10… 1bf548f 
lara...@google.c… 977d692 
phil...@gmail.co… 1ffa578 
jia....@ee073f10… 1bf548f 
phil...@gmail.co… 56a9d50 






phil...@gmail.co… ded7f23 





phil...@gmail.co… 48e51cb 

phil...@gmail.co… cbeb57c 
phil...@gmail.co… 233cdc8 
phil...@gmail.co… f9fc0dc 
phil...@gmail.co… 2041cbe 

phil...@gmail.co… 233cdc8 
phil...@gmail.co… 2041cbe 
phil...@gmail.co… 233cdc8 

dav...@google.co… 28c2d8d 
phil...@gmail.co… 233cdc8 
phil...@gmail.co… cbeb57c 

phil...@gmail.co… 48e51cb 
phil...@gmail.co… 233cdc8 


phil...@gmail.co… 6099edf 










jia....@ee073f10… 55d5827 
phil...@gmail.co… 48e51cb 
jia....@ee073f10… 55d5827 


phil...@gmail.co… 48e51cb 
jia....@ee073f10… 55d5827 
phil...@gmail.co… 6099edf 
jia....@ee073f10… d4ebfa8 
phil...@gmail.co… 48e51cb 





  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
# Copyright (C) 2011 The Libphonenumber Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Author: Philippe Liard

cmake_minimum_required (VERSION 2.8)

project (libphonenumber)
set (libphonenumber_VERSION_MAJOR 4)
set (libphonenumber_VERSION_MINOR 3)

# Helper functions dealing with finding libraries and programs this library
# depends on.

function (print_error DESCRIPTION FILE)
  message (FATAL_ERROR
    "Can't find ${DESCRIPTION}: can't locate ${FILE}. Please read the README.")
endfunction ()

# Find a library. If it has not been found, stop CMake with a fatal error
# message.
function (find_required_library NAME HEADER LIBRARY DESCRIPTION)
  # Check the header.
  find_path (${NAME}_INCLUDE_DIR ${HEADER})
  set (INCLUDE_DIR ${${NAME}_INCLUDE_DIR})

  if (${INCLUDE_DIR} STREQUAL "${INCLUDE_DIR}-NOTFOUND")
    print_error (${DESCRIPTION} ${HEADER})
  endif ()
  include_directories (${INCLUDE_DIR})
  # Check the binary.
  find_library (${NAME}_LIB ${LIBRARY})
  set (LIB ${NAME}_LIB)

  if (${LIB} STREQUAL "${LIB}-NOTFOUND")
    print_error (${DESCRIPTION} ${LIBRARY})
  endif ()
endfunction (find_required_library)

# Check the library version (if pkg-config available).
find_package (PkgConfig)
function (check_library_version VARNAME LIBRARY_WITH_VERSION)
  if (PKG_CONFIG_FOUND)
    pkg_check_modules (${VARNAME} ${LIBRARY_WITH_VERSION})
  endif ()
endfunction ()

# Find a program. If it has not been found, stop CMake with a fatal error
# message.
function (find_required_program NAME FILENAME DESCRIPTION)
  find_program (${NAME}_BIN NAMES ${FILENAME})

  if (${NAME}_BIN STREQUAL "${${NAME}_BIN}-NOTFOUND")
    print_error (${DESCRIPTION} ${FILENAME})
  endif ()
endfunction (find_required_program)

# Options that can be passed to CMake using 'cmake -DKEY=VALUE'.
option ("USE_ICU_REGEXP" "Use ICU regexp engine" "ON")
option ("USE_LITE_METADATA" "Use lite metadata" "OFF")
option ("USE_RE2" "Use RE2" "OFF")
option ("USE_STD_MAP" "Force the use of std::map" "OFF")

# Find all the required libraries and programs.
if (WIN32)
  set (Boost_USE_STATIC_LIBS ON)
endif ()
find_package (Boost 1.40.0 COMPONENTS date_time thread)
if (NOT Boost_FOUND)
  print_error ("Boost Datetime/Thread" "Boost")
endif ()
include_directories (${Boost_INCLUDE_DIRS})

find_required_library (GTEST gtest/gtest.h gtest "Google Test framework")

if (${USE_RE2} STREQUAL "ON")
  find_required_library (RE2 re2/re2.h re2 "Google RE2")
endif ()

find_required_library (PROTOBUF google/protobuf/message_lite.h protobuf
                       "Google Protocol Buffers")
check_library_version (PC_PROTOBUF protobuf>=2.4)

find_required_library (ICU_UC unicode/uchar.h icuuc "ICU")
check_library_version (PC_ICU_UC icu-uc>=4.4)

set (ICU_INCLUDE_DIR ${ICU_UC_INCLUDE_DIR})
set (ICU_LIB ${ICU_UC_LIB})
# If ICU regexp engine is used, use icui18n as well.
if (${USE_ICU_REGEXP} STREQUAL "ON")
  find_required_library (ICU_I18N unicode/regex.h icui18n "ICU")
  check_library_version (PC_ICU_I18N icu-i18n>=4.4)
  list (APPEND ICU_INCLUDE_DIR ${ICU_I18N_INCLUDE_DIR})
  list (APPEND ICU_LIB ${ICU_I18N_LIB})
endif ()

find_required_program (PROTOC protoc
                       "Google Protocol Buffers compiler (protoc)")

find_required_program (JAVA java
                       "Java Runtime Environment")

if (APPLE)
  FIND_LIBRARY (COREFOUNDATION_LIB CoreFoundation)
  FIND_LIBRARY (FOUNDATION_LIB Foundation)
endif ()

if (${USE_STD_MAP} STREQUAL "OFF")
  INCLUDE (CheckIncludeFileCXX)
  CHECK_INCLUDE_FILE_CXX ("tr1/unordered_map" HAVE_CXX_TR1_UNORDERED_MAP)
  if (HAVE_CXX_TR1_UNORDERED_MAP)
    add_definitions ("-DUSE_TR1_UNORDERED_MAP")
  endif ()
endif ()

# Add protoc (Protocol Buffers compiler) target.
set (RESOURCES_DIR "${CMAKE_SOURCE_DIR}/../resources")

set (
  PROTOBUF_SOURCES "${RESOURCES_DIR}/phonemetadata.proto"
                   "${RESOURCES_DIR}/phonenumber.proto"
)

set (
  PROTOBUF_OUTPUT "${CMAKE_SOURCE_DIR}/src/phonenumbers/phonemetadata.pb.cc"
                  "${CMAKE_SOURCE_DIR}/src/phonenumbers/phonemetadata.pb.h"
                  "${CMAKE_SOURCE_DIR}/src/phonenumbers/phonenumber.pb.cc"
                  "${CMAKE_SOURCE_DIR}/src/phonenumbers/phonenumber.pb.h"
)

add_custom_command (
  COMMAND ${PROTOC_BIN} --cpp_out=${CMAKE_SOURCE_DIR}/src/phonenumbers/
    --proto_path=${RESOURCES_DIR} ${PROTOBUF_SOURCES}

  OUTPUT ${PROTOBUF_OUTPUT}
  DEPENDS ${PROTOBUF_SOURCES}
)

add_custom_target (
  generate-sources

  DEPENDS ${PROTOBUF_OUTPUT}
  COMMENT "Generating Protocol Buffers code"
)

# Geocoding data cpp file generation
set (TOOLS_DIR "${CMAKE_CURRENT_BINARY_DIR}/tools")
add_subdirectory("${CMAKE_SOURCE_DIR}/../tools/cpp" "${TOOLS_DIR}")

set (GEOCODING_DIR "${RESOURCES_DIR}/geocoding")
file (GLOB_RECURSE GEOCODING_SOURCES "${GEOCODING_DIR}/*.txt")

set (GEOCODING_DATA_OUTPUT
  "${CMAKE_SOURCE_DIR}/src/phonenumbers/geocoding/geocoding_data.cc"
)

add_custom_command (
  COMMAND generate_geocoding_data "${GEOCODING_DIR}" "${GEOCODING_DATA_OUTPUT}"

  OUTPUT ${GEOCODING_DATA_OUTPUT}
  DEPENDS ${GEOCODING_SOURCES}
          generate_geocoding_data
  COMMENT "Generating geocoding data code"
)

set (
  SOURCES
  "src/base/string_piece.cc"
  "src/phonenumbers/asyoutypeformatter.cc"
  "src/phonenumbers/default_logger.cc"
  "src/phonenumbers/geocoding/area_code_map.cc"
  "src/phonenumbers/geocoding/default_map_storage.cc"
  "src/phonenumbers/geocoding/geocoding_data.cc"
  "src/phonenumbers/geocoding/mapping_file_provider.cc"
  "src/phonenumbers/logger.cc"
  "src/phonenumbers/phonemetadata.pb.cc" # Generated by Protocol Buffers.
  "src/phonenumbers/phonenumber.cc"
  "src/phonenumbers/phonenumber.pb.cc"   # Generated by Protocol Buffers.
  "src/phonenumbers/phonenumberutil.cc"
  "src/phonenumbers/regexp_cache.cc"
  "src/phonenumbers/shortnumberutil.cc"
  "src/phonenumbers/string_byte_sink.cc"
  "src/phonenumbers/stringutil.cc"
  "src/phonenumbers/unicodestring.cc"
  "src/phonenumbers/utf/rune.c"
  "src/phonenumbers/utf/unicodetext.cc"
  "src/phonenumbers/utf/unilib.cc"
)

# Add regexp engine-dependent sources. ICU is used by default.
if (${USE_RE2} STREQUAL "ON")
  # Add a flag to select the right regexp factory implementation used by
  # regexp_factory.h and regexp_adapter_test.cc.
  # When both ICU regexp and RE2 are defined, the regexp engine adapter defaults
  # to RE2 unless the ICU implementation is instantiated explictly obviously.
  add_definitions (-DUSE_RE2)
  list (APPEND SOURCES "src/phonenumbers/regexp_adapter_re2.cc")
endif ()

if (${USE_ICU_REGEXP} STREQUAL "ON")
  add_definitions (-DUSE_ICU_REGEXP)
  list (APPEND SOURCES "src/phonenumbers/regexp_adapter_icu.cc")
  # The phone number matcher needs ICU.
  list (APPEND SOURCES "src/phonenumbers/alternate_format.cc")
  list (APPEND SOURCES "src/phonenumbers/phonenumbermatch.cc")
  list (APPEND SOURCES "src/phonenumbers/phonenumbermatcher.cc")
endif ()

# Library sources excluding the metadata files, since special metadata is used
# for unit-testing.
set (TESTING_LIBRARY_SOURCES ${SOURCES})

# Add metadata code generation targets.

# This function is invoked to create metadata, test metadata and lite metadata
# code generation targets.
function (add_metadata_gen_target TARGET_NAME
                                  XML_FILE
                                  METADATA_TYPE
                                  METADATA_HEADER)
  set (METADATA_SOURCE_DIR "${CMAKE_SOURCE_DIR}/src/phonenumbers")
  set (GEN_OUTPUT "${METADATA_SOURCE_DIR}/${METADATA_TYPE}.cc"
                  "${METADATA_SOURCE_DIR}/${METADATA_HEADER}.h")
  set (JAR_PATH "${CMAKE_SOURCE_DIR}/../tools/java/cpp-build/target")
  set (JAR_PATH "${JAR_PATH}/cpp-build-1.0-SNAPSHOT-jar-with-dependencies.jar")

  add_custom_command (
    COMMAND ${JAVA_BIN} -jar
      ${JAR_PATH} BuildMetadataCppFromXml ${XML_FILE}
      ${CMAKE_SOURCE_DIR}/src/phonenumbers ${METADATA_TYPE}

    OUTPUT ${GEN_OUTPUT}
    DEPENDS ${XML_FILE}
  )
  add_custom_target (
    ${TARGET_NAME}
    DEPENDS ${GEN_OUTPUT}
    COMMENT "Generating Metadata code"
  )
endfunction (add_metadata_gen_target)

if (${USE_LITE_METADATA} STREQUAL "ON")
  # Add the lite metadata generation target.
  set (METADATA_TARGET "generate-lite-metadata")
  add_metadata_gen_target (
    ${METADATA_TARGET}
    "${RESOURCES_DIR}/PhoneNumberMetaData.xml"
    "lite_metadata"
    "metadata"
  )
  list (APPEND SOURCES "src/phonenumbers/lite_metadata.cc")
else ()
  # Add the metadata generation target.
  set (METADATA_TARGET "generate-metadata")
  add_metadata_gen_target (
    ${METADATA_TARGET}
    "${RESOURCES_DIR}/PhoneNumberMetaData.xml"
    "metadata"
    "metadata"
  )
  list (APPEND SOURCES "src/phonenumbers/metadata.cc")
endif ()

# Add the test metadata generation target.
set (TEST_METADATA_TARGET "generate-test-metadata")
add_metadata_gen_target (
  ${TEST_METADATA_TARGET}
  "${RESOURCES_DIR}/PhoneNumberMetaDataForTesting.xml"
  "test_metadata"
  "metadata"
)
list (APPEND TESTING_LIBRARY_SOURCES "src/phonenumbers/test_metadata.cc")

if (${USE_ICU_REGEXP} STREQUAL "ON")
  # Add alternate format metadata generation for the phone number matcher
  set (ALT_FORMAT_METADATA_TARGET "generate-alt-format-metadata")
  add_metadata_gen_target (
    ${ALT_FORMAT_METADATA_TARGET}
    "${RESOURCES_DIR}/PhoneNumberAlternateFormats.xml"
    "alternate_format"
    "alternate_format"
  )
endif ()

if (NOT WIN32)
  add_definitions ("-Wall -Werror")
endif ()

include_directories ("src")

# Build a static library (without -fPIC).
add_library (phonenumber STATIC ${SOURCES})
add_dependencies (phonenumber generate-sources ${METADATA_TARGET})
if (${USE_ICU_REGEXP} STREQUAL "ON")
  add_dependencies (phonenumber ${ALT_FORMAT_METADATA_TARGET})
endif ()

# Build a shared library (with -fPIC).
set (BUILD_SHARED_LIB true)

if (${USE_RE2} STREQUAL "ON")
  # RE2 is not always available as a shared library (e.g: package provided by
  # Ubuntu) therefore disable the shared library build in this case.
  if (${RE2_LIB} MATCHES ".*\\.a")
    message (WARNING
      "RE2 not available as a shared library, shared library build disabled")
    set (BUILD_SHARED_LIB false)
  endif ()
endif ()

if (BUILD_SHARED_LIB)
  add_library (phonenumber-shared SHARED ${SOURCES})
  add_dependencies (phonenumber-shared generate-sources ${METADATA_TARGET})
  if (${USE_ICU_REGEXP} STREQUAL "ON")
    add_dependencies (phonenumber ${ALT_FORMAT_METADATA_TARGET})
  endif ()
  set_target_properties (phonenumber-shared
    PROPERTIES
      OUTPUT_NAME "phonenumber"
      PREFIX "lib"
      SOVERSION ${libphonenumber_VERSION_MAJOR}
      VERSION ${libphonenumber_VERSION_MAJOR}.${libphonenumber_VERSION_MINOR})
endif ()

set (LIBRARY_DEPS ${PROTOBUF_LIB} ${ICU_LIB} ${Boost_LIBRARIES})

if (${USE_RE2} STREQUAL "ON")
  list (APPEND LIBRARY_DEPS ${RE2_LIB})
endif ()

if (APPLE)
  list (APPEND LIBRARY_DEPS ${COREFOUNDATION_LIB} ${FOUNDATION_LIB})
endif ()

target_link_libraries (phonenumber ${LIBRARY_DEPS})

if (BUILD_SHARED_LIB)
  target_link_libraries (phonenumber-shared ${LIBRARY_DEPS})
endif ()

# Build a specific library for testing purposes.
add_library (phonenumber_testing STATIC ${TESTING_LIBRARY_SOURCES})
target_link_libraries (phonenumber_testing ${LIBRARY_DEPS})
add_dependencies (phonenumber_testing generate-sources ${TEST_METADATA_TARGET})

# Test geocoding data cpp files generation
set (GEOCODING_TEST_DIR "${RESOURCES_DIR}/test/geocoding")
file (GLOB_RECURSE GEOCODING_TEST_SOURCES "${GEOCODING_TEST_DIR}/*.txt")

set (GEOCODING_TEST_DATA_OUTPUT
  "${CMAKE_SOURCE_DIR}/test/phonenumbers/geocoding/geocoding_test_data.cc"
)

add_custom_command (
  COMMAND generate_geocoding_data "${GEOCODING_TEST_DIR}"
    "${GEOCODING_TEST_DATA_OUTPUT}" "_test"

  OUTPUT ${GEOCODING_TEST_DATA_OUTPUT}
  DEPENDS ${GEOCODING_TEST_SOURCES} generate_geocoding_data
  COMMENT "Generating geocoding test data code"
)

set (TEST_SOURCES
  "test/phonenumbers/asyoutypeformatter_test.cc"
  "test/phonenumbers/geocoding/area_code_map_test.cc"
  "test/phonenumbers/geocoding/geocoding_data_test.cc"
  "test/phonenumbers/geocoding/geocoding_test_data.cc"
  "test/phonenumbers/geocoding/mapping_file_provider_test.cc"
  "test/phonenumbers/logger_test.cc"
  "test/phonenumbers/phonenumberutil_test.cc"
  "test/phonenumbers/regexp_adapter_test.cc"
  "test/phonenumbers/regexp_cache_test.cc"
  "test/phonenumbers/run_tests.cc"
  "test/phonenumbers/shortnumberutil_test.cc"
  "test/phonenumbers/stringutil_test.cc"
  "test/phonenumbers/test_util.cc"
  "test/phonenumbers/unicodestring_test.cc"
  "test/phonenumbers/utf/unicodetext_test.cc"
)
if (${USE_ICU_REGEXP} STREQUAL "ON")
  # Add the phone number matcher tests.
  list (APPEND TEST_SOURCES "test/phonenumbers/phonenumbermatch_test.cc")
  list (APPEND TEST_SOURCES "test/phonenumbers/phonenumbermatcher_test.cc")
endif ()

# Build the testing binary.
include_directories ("test")
add_executable (libphonenumber_test ${TEST_SOURCES})
set (TEST_LIBS phonenumber_testing ${GTEST_LIB})

if (NOT WIN32)
  list (APPEND TEST_LIBS pthread)
endif ()

target_link_libraries (libphonenumber_test ${TEST_LIBS})
add_custom_target (test
  COMMAND generate_geocoding_data_test
  COMMAND libphonenumber_test

  DEPENDS generate_geocoding_data_test libphonenumber_test
)

# Install rules.
install (FILES
  "src/phonenumbers/asyoutypeformatter.h"
  "src/phonenumbers/callback.h"
  "src/phonenumbers/logger.h"
  "src/phonenumbers/phonenumber.pb.h"
  "src/phonenumbers/phonemetadata.pb.h"
  "src/phonenumbers/phonenumberutil.h"
  "src/phonenumbers/regexp_adapter.h"
  "src/phonenumbers/regexp_cache.h"
  "src/phonenumbers/shortnumberutil.h"
  "src/phonenumbers/unicodestring.h"
  DESTINATION include/phonenumbers/
)

install (FILES "src/phonenumbers/utf/unicodetext.h"
         DESTINATION include/phonenumbers/utf/)

if (${USE_ICU_REGEXP} STREQUAL "ON")
  # Install the phone number matcher headers.
  install (FILES
    "src/phonenumbers/phonenumbermatch.h"
    "src/phonenumbers/phonenumbermatcher.h"
    "src/phonenumbers/regexp_adapter.h"
    DESTINATION include/phonenumbers/
  )
endif ()

install (FILES "src/base/basictypes.h" DESTINATION include/base/)

install (FILES
  "src/base/memory/scoped_ptr.h"
  "src/base/memory/singleton.h"
  DESTINATION include/base/memory/
)

install (FILES "src/base/synchronization/lock.h"
         DESTINATION include/base/synchronization/)

install (TARGETS phonenumber LIBRARY DESTINATION lib/ ARCHIVE DESTINATION lib/)

if (BUILD_SHARED_LIB)
  install (TARGETS phonenumber-shared LIBRARY DESTINATION lib/ ARCHIVE
           DESTINATION lib/)
endif ()