1# Copyright (C) 2011 The Libphonenumber Authors 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14 15# Author: Philippe Liard 16 17cmake_minimum_required (VERSION 2.8.5) 18 19project (libphonenumber) 20set (libphonenumber_VERSION_MAJOR 8) 21set (libphonenumber_VERSION_MINOR 12) 22set (libphonenumber_VERSION_PATCH 0) 23 24if (32BIT) 25 set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m32") 26 set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32") 27 set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -m32") 28 set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -m32") 29endif () 30 31# Helper functions dealing with finding libraries and programs this library 32# depends on. 33 34include (GNUInstallDirs) 35include (../tools/cpp/gtest.cmake) 36 37function (print_error DESCRIPTION FILE) 38 message (FATAL_ERROR 39 "Can't find ${DESCRIPTION}: can't locate ${FILE}. Please read the README.") 40endfunction () 41 42# Find a library. If it has not been found, stop CMake with a fatal error 43# message. 44function (find_required_library NAME HEADER LIBRARY DESCRIPTION) 45 # Check the header. 46 find_path (${NAME}_INCLUDE_DIR ${HEADER}) 47 set (INCLUDE_DIR ${${NAME}_INCLUDE_DIR}) 48 49 if (${INCLUDE_DIR} STREQUAL "${INCLUDE_DIR}-NOTFOUND") 50 print_error (${DESCRIPTION} ${HEADER}) 51 endif () 52 include_directories (${INCLUDE_DIR}) 53 # Check the binary. 54 find_library (${NAME}_LIB ${LIBRARY}) 55 set (LIB ${NAME}_LIB) 56 57 if (${LIB} STREQUAL "${LIB}-NOTFOUND") 58 print_error (${DESCRIPTION} ${LIBRARY}) 59 endif () 60endfunction (find_required_library) 61 62# Check the library version (if pkg-config available). 63find_package (PkgConfig) 64function (check_library_version VARNAME LIBRARY_WITH_VERSION) 65 if (PKG_CONFIG_FOUND) 66 pkg_check_modules (${VARNAME} ${LIBRARY_WITH_VERSION}) 67 endif () 68endfunction () 69 70# Find a program. If it has not been found, stop CMake with a fatal error 71# message. 72function (find_required_program NAME FILENAME DESCRIPTION) 73 find_program (${NAME}_BIN NAMES ${FILENAME}) 74 75 if (${NAME}_BIN STREQUAL "${${NAME}_BIN}-NOTFOUND") 76 print_error (${DESCRIPTION} ${FILENAME}) 77 endif () 78endfunction (find_required_program) 79 80# Options that can be passed to CMake using 'cmake -DKEY=VALUE'. 81option ("BUILD_GEOCODER" "Build the offline phone number geocoder" "ON") 82option ("USE_ALTERNATE_FORMATS" "Use alternate formats" "ON") 83option ("USE_BOOST" "Use Boost" "ON") 84option ("USE_ICU_REGEXP" "Use ICU regexp engine" "ON") 85option ("USE_LITE_METADATA" "Use lite metadata" "OFF") 86option ("USE_RE2" "Use RE2" "OFF") 87option ("USE_STD_MAP" "Force the use of std::map" "OFF") 88option ("BUILD_STATIC_LIB" "Build static libraries" "ON") 89 90if (${USE_ALTERNATE_FORMATS} STREQUAL "ON") 91 add_definitions ("-DI18N_PHONENUMBERS_USE_ALTERNATE_FORMATS") 92endif () 93 94# Find all the required libraries and programs. 95if (${USE_BOOST} STREQUAL "ON") 96 add_definitions ("-DI18N_PHONENUMBERS_USE_BOOST") 97 if (WIN32) 98 set (Boost_USE_STATIC_LIBS ON) 99 endif () 100 find_package (Boost 1.40.0 COMPONENTS date_time system thread) 101 if (NOT Boost_FOUND) 102 print_error ("Boost Date_Time/System/Thread" "Boost") 103 endif () 104 include_directories (${Boost_INCLUDE_DIRS}) 105endif () 106 107find_or_build_gtest () 108 109if (${USE_RE2} STREQUAL "ON") 110 find_required_library (RE2 re2/re2.h re2 "Google RE2") 111endif () 112 113find_required_library (PROTOBUF google/protobuf/message_lite.h protobuf 114 "Google Protocol Buffers") 115check_library_version (PC_PROTOBUF protobuf>=2.4) 116 117find_required_library (ICU_UC unicode/uchar.h icuuc "ICU") 118check_library_version (PC_ICU_UC icu-uc>=4.4) 119 120set (ICU_INCLUDE_DIR ${ICU_UC_INCLUDE_DIR}) 121set (ICU_LIB ${ICU_UC_LIB}) 122# If ICU regexp engine is used or if the geocoder is built, use icui18n as well. 123if (${USE_ICU_REGEXP} STREQUAL "ON" OR ${BUILD_GEOCODER} STREQUAL "ON") 124 find_required_library (ICU_I18N unicode/regex.h icui18n "ICU") 125 check_library_version (PC_ICU_I18N icu-i18n>=4.4) 126 list (APPEND ICU_INCLUDE_DIR ${ICU_I18N_INCLUDE_DIR}) 127 list (APPEND ICU_LIB ${ICU_I18N_LIB}) 128endif () 129 130find_required_program (PROTOC protoc 131 "Google Protocol Buffers compiler (protoc)") 132 133find_required_program (JAVA java 134 "Java Runtime Environment") 135 136if (APPLE) 137 FIND_LIBRARY (COREFOUNDATION_LIB CoreFoundation) 138 FIND_LIBRARY (FOUNDATION_LIB Foundation) 139 set (CMAKE_MACOSX_RPATH "OFF") 140 set (CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS 141 "${CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS} -undefined dynamic_lookup") 142endif () 143 144if (${USE_STD_MAP} STREQUAL "OFF") 145 INCLUDE (CheckIncludeFileCXX) 146 CHECK_INCLUDE_FILE_CXX ("tr1/unordered_map" HAVE_CXX_TR1_UNORDERED_MAP) 147 if (HAVE_CXX_TR1_UNORDERED_MAP) 148 add_definitions ("-DI18N_PHONENUMBERS_USE_TR1_UNORDERED_MAP") 149 endif () 150endif () 151 152# Add protoc (Protocol Buffers compiler) target. 153set (RESOURCES_DIR "${CMAKE_SOURCE_DIR}/../resources") 154 155set ( 156 PROTOBUF_SOURCES "${RESOURCES_DIR}/phonemetadata.proto" 157 "${RESOURCES_DIR}/phonenumber.proto" 158) 159 160set ( 161 PROTOBUF_OUTPUT "${CMAKE_SOURCE_DIR}/src/phonenumbers/phonemetadata.pb.cc" 162 "${CMAKE_SOURCE_DIR}/src/phonenumbers/phonemetadata.pb.h" 163 "${CMAKE_SOURCE_DIR}/src/phonenumbers/phonenumber.pb.cc" 164 "${CMAKE_SOURCE_DIR}/src/phonenumbers/phonenumber.pb.h" 165) 166 167add_custom_command ( 168 COMMAND ${PROTOC_BIN} --cpp_out=${CMAKE_SOURCE_DIR}/src/phonenumbers/ 169 --proto_path=${RESOURCES_DIR} ${PROTOBUF_SOURCES} 170 171 OUTPUT ${PROTOBUF_OUTPUT} 172 DEPENDS ${PROTOBUF_SOURCES} 173) 174 175if (${BUILD_GEOCODER} STREQUAL "ON") 176 # Geocoding data cpp file generation 177 set (TOOLS_DIR "${CMAKE_CURRENT_BINARY_DIR}/tools") 178 add_subdirectory("${CMAKE_SOURCE_DIR}/../tools/cpp" "${TOOLS_DIR}") 179 180 set (GEOCODING_DIR "${RESOURCES_DIR}/geocoding") 181 file (GLOB_RECURSE GEOCODING_SOURCES "${GEOCODING_DIR}/*.txt") 182 183 set (GEOCODING_DATA_OUTPUT 184 "${CMAKE_SOURCE_DIR}/src/phonenumbers/geocoding/geocoding_data.cc" 185 ) 186 187 add_custom_command ( 188 COMMAND generate_geocoding_data "${GEOCODING_DIR}" 189 "${GEOCODING_DATA_OUTPUT}" 190 191 OUTPUT ${GEOCODING_DATA_OUTPUT} 192 DEPENDS ${GEOCODING_SOURCES} 193 generate_geocoding_data 194 COMMENT "Generating geocoding data code" 195 ) 196endif () 197 198set ( 199 SOURCES 200 "src/phonenumbers/asyoutypeformatter.cc" 201 "src/phonenumbers/base/strings/string_piece.cc" 202 "src/phonenumbers/default_logger.cc" 203 "src/phonenumbers/logger.cc" 204 "src/phonenumbers/phonemetadata.pb.cc" # Generated by Protocol Buffers. 205 "src/phonenumbers/phonenumber.cc" 206 "src/phonenumbers/phonenumber.pb.cc" # Generated by Protocol Buffers. 207 "src/phonenumbers/phonenumberutil.cc" 208 "src/phonenumbers/regex_based_matcher.cc" 209 "src/phonenumbers/regexp_cache.cc" 210 "src/phonenumbers/shortnumberinfo.cc" 211 "src/phonenumbers/string_byte_sink.cc" 212 "src/phonenumbers/stringutil.cc" 213 "src/phonenumbers/unicodestring.cc" 214 "src/phonenumbers/utf/rune.c" 215 "src/phonenumbers/utf/unicodetext.cc" 216 "src/phonenumbers/utf/unilib.cc" 217) 218 219if (${BUILD_GEOCODER} STREQUAL "ON") 220 set ( 221 GEOCODING_SOURCES 222 "src/phonenumbers/geocoding/area_code_map.cc" 223 "src/phonenumbers/geocoding/default_map_storage.cc" 224 "src/phonenumbers/geocoding/geocoding_data.cc" 225 "src/phonenumbers/geocoding/mapping_file_provider.cc" 226 "src/phonenumbers/geocoding/phonenumber_offline_geocoder.cc" 227 "src/phonenumbers/phonenumber.pb.h" # Forces proto buffer generation. 228 ) 229endif () 230 231# Add regexp engine-dependent sources. ICU is used by default. 232if (${USE_RE2} STREQUAL "ON") 233 # Add a flag to select the right regexp factory implementation used by 234 # regexp_factory.h and regexp_adapter_test.cc. 235 # When both ICU regexp and RE2 are defined, the regexp engine adapter defaults 236 # to RE2 unless the ICU implementation is instantiated explictly obviously. 237 add_definitions ("-DI18N_PHONENUMBERS_USE_RE2") 238 list (APPEND SOURCES "src/phonenumbers/regexp_adapter_re2.cc") 239endif () 240 241if (${USE_ICU_REGEXP} STREQUAL "ON") 242 add_definitions ("-DI18N_PHONENUMBERS_USE_ICU_REGEXP") 243 list (APPEND SOURCES "src/phonenumbers/regexp_adapter_icu.cc") 244 # The phone number matcher needs ICU. 245 list (APPEND SOURCES "src/phonenumbers/phonenumbermatch.cc") 246 list (APPEND SOURCES "src/phonenumbers/phonenumbermatcher.cc") 247 if (${USE_ALTERNATE_FORMATS} STREQUAL "ON") 248 list (APPEND SOURCES "src/phonenumbers/alternate_format.cc") 249 endif () 250endif () 251 252# Library sources excluding the metadata files, since special metadata is used 253# for unit-testing. Note that a single testing library is built for both 254# libphonenumber and geocoding. 255set (TESTING_LIBRARY_SOURCES ${SOURCES}) 256if (${BUILD_GEOCODER} STREQUAL "ON") 257 list (APPEND TESTING_LIBRARY_SOURCES ${GEOCODING_SOURCES}) 258endif () 259 260# Add metadata code generation targets. 261 262# This function is invoked to create metadata, test metadata and lite metadata 263# code generation targets. 264function (add_metadata_gen_target TARGET_NAME 265 XML_FILE 266 METADATA_TYPE 267 METADATA_HEADER) 268 set (METADATA_SOURCE_DIR "${CMAKE_SOURCE_DIR}/src/phonenumbers") 269 set (GEN_OUTPUT "${METADATA_SOURCE_DIR}/${METADATA_TYPE}.cc" 270 "${METADATA_SOURCE_DIR}/${METADATA_HEADER}.h") 271 set (JAR_PATH "${CMAKE_SOURCE_DIR}/../tools/java/cpp-build/target") 272 set (JAR_PATH "${JAR_PATH}/cpp-build-1.0-SNAPSHOT-jar-with-dependencies.jar") 273 274 add_custom_command ( 275 COMMAND ${JAVA_BIN} -jar 276 ${JAR_PATH} BuildMetadataCppFromXml ${XML_FILE} 277 ${CMAKE_SOURCE_DIR}/src/phonenumbers ${METADATA_TYPE} 278 279 OUTPUT ${GEN_OUTPUT} 280 DEPENDS ${XML_FILE} 281 ) 282 add_custom_target ( 283 ${TARGET_NAME} 284 DEPENDS ${GEN_OUTPUT} 285 COMMENT "Generating Metadata code" 286 ) 287endfunction (add_metadata_gen_target) 288 289if (${USE_LITE_METADATA} STREQUAL "ON") 290 # Add the lite metadata generation target. 291 set (METADATA_TARGET "generate-lite-metadata") 292 add_metadata_gen_target ( 293 ${METADATA_TARGET} 294 "${RESOURCES_DIR}/PhoneNumberMetadata.xml" 295 "lite_metadata" 296 "metadata" 297 ) 298 list (APPEND SOURCES "src/phonenumbers/lite_metadata.cc") 299else () 300 # Add the metadata generation target. 301 set (METADATA_TARGET "generate-metadata") 302 add_metadata_gen_target ( 303 ${METADATA_TARGET} 304 "${RESOURCES_DIR}/PhoneNumberMetadata.xml" 305 "metadata" 306 "metadata" 307 ) 308 list (APPEND SOURCES "src/phonenumbers/metadata.cc") 309endif () 310 311# Add the test metadata generation target. 312set (TEST_METADATA_TARGET "generate-test-metadata") 313add_metadata_gen_target ( 314 ${TEST_METADATA_TARGET} 315 "${RESOURCES_DIR}/PhoneNumberMetadataForTesting.xml" 316 "test_metadata" 317 "metadata" 318) 319list (APPEND TESTING_LIBRARY_SOURCES "src/phonenumbers/test_metadata.cc") 320 321# Add the short metadata generation target. 322set (SHORT_METADATA_TARGET "generate-short-number-metadata") 323add_metadata_gen_target ( 324 ${SHORT_METADATA_TARGET} 325 "${RESOURCES_DIR}/ShortNumberMetadata.xml" 326 "short_metadata" 327 "short_metadata" 328) 329# This is used both for the real library and for testing. 330list (APPEND SOURCES "src/phonenumbers/short_metadata.cc") 331list (APPEND TESTING_LIBRARY_SOURCES "src/phonenumbers/short_metadata.cc") 332 333if (${USE_ICU_REGEXP} STREQUAL "ON") 334 if (${USE_ALTERNATE_FORMATS} STREQUAL "ON") 335 # Add alternate format metadata generation for the phone number matcher. 336 set (ALT_FORMAT_METADATA_TARGET "generate-alt-format-metadata") 337 add_metadata_gen_target ( 338 ${ALT_FORMAT_METADATA_TARGET} 339 "${RESOURCES_DIR}/PhoneNumberAlternateFormats.xml" 340 "alternate_format" 341 "alternate_format" 342 ) 343 endif () 344endif () 345 346if (NOT WIN32) 347 add_definitions ("-Wall -Werror") 348endif () 349 350include_directories ("src") 351 352if (${BUILD_STATIC_LIB} STREQUAL "ON") 353 # Build a static library (without -fPIC). 354 add_library (phonenumber STATIC ${SOURCES}) 355 if (${BUILD_GEOCODER} STREQUAL "ON") 356 add_dependencies (phonenumber generate_geocoding_data) 357 endif () 358 if (${USE_ICU_REGEXP} STREQUAL "ON") 359 if (${USE_ALTERNATE_FORMATS} STREQUAL "ON") 360 add_dependencies (phonenumber ${ALT_FORMAT_METADATA_TARGET}) 361 endif () 362 endif () 363endif () 364 365if (${BUILD_GEOCODER} STREQUAL "ON") 366 if (${BUILD_STATIC_LIB} STREQUAL "ON") 367 add_library (geocoding STATIC ${GEOCODING_SOURCES}) 368 add_dependencies (geocoding generate_geocoding_data) 369 endif () 370 # The geocoder doesn't use RE2 so there is no reason not to build a shared 371 # library for it. 372 add_library (geocoding-shared SHARED ${GEOCODING_SOURCES}) 373 add_dependencies (geocoding-shared generate_geocoding_data) 374 set_target_properties (geocoding-shared 375 PROPERTIES 376 OUTPUT_NAME "geocoding" 377 PREFIX "lib" 378 SOVERSION ${libphonenumber_VERSION_MAJOR} 379 VERSION ${libphonenumber_VERSION_MAJOR}.${libphonenumber_VERSION_MINOR}) 380endif () 381 382# Build a shared library (with -fPIC). 383set (BUILD_SHARED_LIB true) 384 385if (${USE_RE2} STREQUAL "ON") 386 # RE2 is not always available as a shared library (e.g: package provided by 387 # Ubuntu) therefore disable the shared library build in this case. 388 if (${RE2_LIB} MATCHES ".*\\.a") 389 message (WARNING 390 "RE2 not available as a shared library, shared library build disabled") 391 set (BUILD_SHARED_LIB false) 392 endif () 393endif () 394 395if (BUILD_SHARED_LIB) 396 add_library (phonenumber-shared SHARED ${SOURCES}) 397 if (${BUILD_GEOCODER} STREQUAL "ON") 398 add_dependencies (phonenumber-shared generate_geocoding_data) 399 endif () 400 if (${USE_ICU_REGEXP} STREQUAL "ON") 401 if (${USE_ALTERNATE_FORMATS} STREQUAL "ON") 402 add_dependencies (phonenumber-shared ${ALT_FORMAT_METADATA_TARGET}) 403 endif () 404 endif () 405 set_target_properties (phonenumber-shared 406 PROPERTIES 407 OUTPUT_NAME "phonenumber" 408 PREFIX "lib" 409 SOVERSION ${libphonenumber_VERSION_MAJOR} 410 VERSION ${libphonenumber_VERSION_MAJOR}.${libphonenumber_VERSION_MINOR}) 411endif () 412 413# Libraries used by both libphonenumber and libgeocoding. 414set (COMMON_DEPS ${ICU_LIB}) 415 416set (LIBRARY_DEPS ${PROTOBUF_LIB}) 417 418if (${USE_BOOST} STREQUAL "ON") 419 list (APPEND LIBRARY_DEPS ${Boost_LIBRARIES}) 420endif () 421 422if (${USE_RE2} STREQUAL "ON") 423 list (APPEND LIBRARY_DEPS ${RE2_LIB}) 424endif () 425 426if (APPLE) 427 list (APPEND COMMON_DEPS ${COREFOUNDATION_LIB} ${FOUNDATION_LIB}) 428endif () 429 430list (APPEND LIBRARY_DEPS ${COMMON_DEPS}) 431 432if (${BUILD_STATIC_LIB} STREQUAL "ON") 433 target_link_libraries (phonenumber ${LIBRARY_DEPS}) 434endif () 435 436if (BUILD_SHARED_LIB) 437 target_link_libraries (phonenumber-shared ${LIBRARY_DEPS}) 438endif () 439 440if (${BUILD_GEOCODER} STREQUAL "ON") 441 list (APPEND GEOCODER_DEPS ${COMMON_DEPS}) 442 # Note that the subset of base/ on which the geocoder relies is implemented 443 # on top of Boost header-only libraries (e.g. scoped_ptr.hpp). 444 target_link_libraries (geocoding ${LIBRARY_DEPS}) 445 target_link_libraries (geocoding-shared ${LIBRARY_DEPS}) 446endif () 447 448# Build a specific library for testing purposes. 449add_library (phonenumber_testing STATIC ${TESTING_LIBRARY_SOURCES}) 450if (${BUILD_GEOCODER} STREQUAL "ON") 451 add_dependencies (phonenumber_testing generate_geocoding_data) 452endif () 453target_link_libraries (phonenumber_testing ${LIBRARY_DEPS}) 454 455if (${BUILD_GEOCODER} STREQUAL "ON") 456 # Test geocoding data cpp files generation. 457 set (GEOCODING_TEST_DIR "${RESOURCES_DIR}/test/geocoding") 458 file (GLOB_RECURSE GEOCODING_TEST_SOURCES "${GEOCODING_TEST_DIR}/*.txt") 459 460 set (GEOCODING_TEST_DATA_OUTPUT 461 "${CMAKE_SOURCE_DIR}/test/phonenumbers/geocoding/geocoding_test_data.cc" 462 ) 463 464 add_custom_command ( 465 COMMAND generate_geocoding_data "${GEOCODING_TEST_DIR}" 466 "${GEOCODING_TEST_DATA_OUTPUT}" "_test" 467 468 OUTPUT ${GEOCODING_TEST_DATA_OUTPUT} 469 DEPENDS ${GEOCODING_TEST_SOURCES} generate_geocoding_data 470 COMMENT "Generating geocoding test data code" 471 ) 472endif () 473 474 475set (TEST_SOURCES 476 "test/phonenumbers/asyoutypeformatter_test.cc" 477 "test/phonenumbers/logger_test.cc" 478 "test/phonenumbers/matcher_test.cc" 479 "test/phonenumbers/phonenumberutil_test.cc" 480 "test/phonenumbers/regexp_adapter_test.cc" 481 "test/phonenumbers/regexp_cache_test.cc" 482 "test/phonenumbers/run_tests.cc" 483 "test/phonenumbers/shortnumberinfo_test.cc" 484 "test/phonenumbers/stringutil_test.cc" 485 "test/phonenumbers/test_util.cc" 486 "test/phonenumbers/unicodestring_test.cc" 487 "test/phonenumbers/utf/unicodetext_test.cc" 488) 489 490if (${BUILD_GEOCODER} STREQUAL "ON") 491 set (GEOCODING_TEST_SOURCES 492 "test/phonenumbers/geocoding/area_code_map_test.cc" 493 "test/phonenumbers/geocoding/geocoding_data_test.cc" 494 "test/phonenumbers/geocoding/geocoding_test_data.cc" 495 "test/phonenumbers/geocoding/mapping_file_provider_test.cc" 496 "test/phonenumbers/geocoding/phonenumber_offline_geocoder_test.cc" 497 ) 498 list (APPEND TEST_SOURCES ${GEOCODING_TEST_SOURCES}) 499endif () 500 501if (${USE_ICU_REGEXP} STREQUAL "ON") 502 # Add the phone number matcher tests. 503 list (APPEND TEST_SOURCES "test/phonenumbers/phonenumbermatch_test.cc") 504 list (APPEND TEST_SOURCES "test/phonenumbers/phonenumbermatcher_test.cc") 505endif () 506 507# Build the testing binary. 508include_directories ("test") 509add_executable (libphonenumber_test ${TEST_SOURCES}) 510set (TEST_LIBS phonenumber_testing ${GTEST_LIB}) 511 512if (NOT WIN32) 513 list (APPEND TEST_LIBS pthread) 514endif () 515 516target_link_libraries (libphonenumber_test ${TEST_LIBS}) 517 518# Unfortunately add_custom_target() can't accept a single command provided as a 519# list of commands. 520if (${BUILD_GEOCODER} STREQUAL "ON") 521 add_custom_target (tests 522 COMMAND generate_geocoding_data_test 523 COMMAND libphonenumber_test 524 DEPENDS generate_geocoding_data_test libphonenumber_test 525 ) 526else () 527 add_custom_target (tests 528 COMMAND libphonenumber_test 529 DEPENDS libphonenumber_test 530 ) 531endif () 532 533# Install rules. 534install (FILES 535 "src/phonenumbers/asyoutypeformatter.h" 536 "src/phonenumbers/callback.h" 537 "src/phonenumbers/logger.h" 538 "src/phonenumbers/matcher_api.h" 539 "src/phonenumbers/phonenumber.pb.h" 540 "src/phonenumbers/phonemetadata.pb.h" 541 "src/phonenumbers/phonenumberutil.h" 542 "src/phonenumbers/regexp_adapter.h" 543 "src/phonenumbers/regexp_cache.h" 544 "src/phonenumbers/region_code.h" 545 "src/phonenumbers/shortnumberinfo.h" 546 "src/phonenumbers/unicodestring.h" 547 DESTINATION include/phonenumbers/ 548) 549 550install (FILES "src/phonenumbers/utf/unicodetext.h" 551 DESTINATION include/phonenumbers/utf/) 552 553if (${USE_ICU_REGEXP} STREQUAL "ON") 554 # Install the phone number matcher headers. 555 install (FILES 556 "src/phonenumbers/phonenumbermatch.h" 557 "src/phonenumbers/phonenumbermatcher.h" 558 "src/phonenumbers/regexp_adapter.h" 559 DESTINATION include/phonenumbers/ 560 ) 561endif () 562 563if (${BUILD_GEOCODER} STREQUAL "ON") 564 install (FILES 565 "src/phonenumbers/geocoding/phonenumber_offline_geocoder.h" 566 DESTINATION include/phonenumbers/geocoding 567 ) 568endif () 569 570install ( 571 FILES 572 "src/phonenumbers/base/basictypes.h" 573 "src/phonenumbers/base/template_util.h" 574 "src/phonenumbers/base/logging.h" 575 "src/phonenumbers/base/thread_checker.h" 576 DESTINATION include/phonenumbers/base/ 577) 578 579install (FILES 580 "src/phonenumbers/base/memory/scoped_ptr.h" 581 "src/phonenumbers/base/memory/singleton.h" 582 "src/phonenumbers/base/memory/singleton_posix.h" 583 DESTINATION include/phonenumbers/base/memory/ 584) 585 586install (FILES "src/phonenumbers/base/synchronization/lock.h" 587 "src/phonenumbers/base/synchronization/lock_posix.h" 588 DESTINATION include/phonenumbers/base/synchronization/) 589 590set (LIBDIR ${CMAKE_INSTALL_LIBDIR}) 591 592if (${BUILD_STATIC_LIB} STREQUAL "ON") 593 install (TARGETS phonenumber LIBRARY DESTINATION ${LIBDIR} ARCHIVE DESTINATION ${LIBDIR}) 594endif () 595 596if (BUILD_SHARED_LIB) 597 install (TARGETS phonenumber-shared LIBRARY DESTINATION ${LIBDIR} ARCHIVE 598 DESTINATION ${LIBDIR}) 599endif () 600 601if (${BUILD_GEOCODER} STREQUAL "ON") 602 install (TARGETS geocoding LIBRARY DESTINATION ${LIBDIR} ARCHIVE DESTINATION ${LIBDIR}) 603 install (TARGETS geocoding-shared LIBRARY DESTINATION ${LIBDIR} ARCHIVE 604 DESTINATION ${LIBDIR}) 605endif () 606 607# Build an example program using geocoding, mainly to make sure that both 608# libraries are built properly. 609if (${BUILD_GEOCODER} STREQUAL "ON") 610 add_executable ( 611 geocoding_test_program 612 "test/phonenumbers/geocoding/geocoding_test_program.cc" 613 ) 614 target_link_libraries (geocoding_test_program geocoding phonenumber) 615endif () 616 617# Build an RPM 618set (CPACK_PACKAGE_VERSION ${libphonenumber_VERSION_MAJOR}.${libphonenumber_VERSION_MINOR}.${libphonenumber_VERSION_PATCH}) 619set (CPACK_GENERATOR "RPM") 620set (CPACK_PACKAGE_NAME "libphonenumber") 621set (CPACK_RPM_PACKAGE_RELEASE 1) 622set (CPACK_PACKAGE_DESCRIPTION_SUMMARY "Google's phone number handling library") 623if (32BIT) 624 set (CPACK_RPM_PACKAGE_ARCHITECTURE i686) 625else () 626 set (CPACK_RPM_PACKAGE_ARCHITECTURE x86_64) 627endif () 628set (CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-${CPACK_RPM_PACKAGE_RELEASE}.${CPACK_RPM_PACKAGE_ARCHITECTURE}") 629include (CPack) 630