1 # Copyright (C) 2011 Google Inc.
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
7 # http://www.apache.org/licenses/LICENSE-2.0
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.
15 cmake_minimum_required (VERSION 2.8)
17 project (libphonenumber)
19 # Find Google Test library
20 find_path (GTEST_INCLUDE_DIR gtest/gtest.h)
22 if (GTEST_INCLUDE_DIR STREQUAL "GTEST_INCLUDE_DIR-NOTFOUND")
24 "Can't find Google Test framework headers. Please read README.")
27 include_directories (${GTEST_INCLUDE_DIR})
29 find_library (GTEST_LIB gtest)
31 if (GTEST_LIB STREQUAL "GTEST_LIB-NOTFOUND")
33 "Can't find Google Test framework library. Please read README.")
37 # Find Google RE2 library
38 find_path (RE2_INCLUDE_DIR re2/re2.h)
40 if (RE2_INCLUDE_DIR STREQUAL "RE2_INCLUDE_DIR-NOTFOUND")
42 "Can't find Google RE2 headers. Please read README.")
45 include_directories (${RE2_INCLUDE_DIR})
47 find_library (RE2_LIB re2)
49 if (RE2_LIB STREQUAL "RE2_LIB-NOTFOUND")
51 "Can't find Google RE2 library. Please read README.")
55 # Find Protocol Buffers compiler
56 find_program (PROTOC NAMES protoc)
58 if (PROTOC STREQUAL "PROTOC-NOTFOUND")
60 "Can't find Google Protocol Buffers compiler (protoc). "
61 "Please read README.")
64 # Add protoc (Protocol Buffers compiler) target
66 PROTOBUF_SOURCES "${CMAKE_SOURCE_DIR}/src/phonemetadata.proto"
67 "${CMAKE_SOURCE_DIR}/src/phonenumber.proto"
72 PROTOBUF_OUTPUT "${CMAKE_SOURCE_DIR}/src/phonemetadata.pb.cc"
73 "${CMAKE_SOURCE_DIR}/src/phonemetadata.pb.h"
74 "${CMAKE_SOURCE_DIR}/src/phonenumber.pb.cc"
75 "${CMAKE_SOURCE_DIR}/src/phonenumber.pb.h"
79 COMMAND ${PROTOC} --cpp_out=${CMAKE_SOURCE_DIR}
80 --proto_path=${CMAKE_SOURCE_DIR} ${PROTOBUF_SOURCES}
82 OUTPUT ${PROTOBUF_OUTPUT}
83 DEPENDS ${PROTOBUF_SOURCES}
89 DEPENDS ${PROTOBUF_OUTPUT}
90 COMMENT "Generating Protocol Buffers code"
93 # Platform independent sources
97 "src/base/lazy_instance.cc"
98 "src/base/synchronization/lock.cc"
99 "src/base/threading/thread_restrictions.cc"
100 "src/phonenumberutil.cc"
107 if (CMAKE_COMPILER_IS_GNUCXX)
108 add_definitions ("-Wall -Wextra -Werror")
110 # The next flags are needed by base/ source files to compile
111 # low level code needed by Singleton
112 add_definitions ("-DCOMPILER_GCC -DOS_POSIX -DOS_LINUX")
114 if (${CMAKE_SYSTEM_PROCESSOR} MATCHES "x86.*")
115 add_definitions ("-DARCH_CPU_X86_FAMILY")
117 # Add GCC specific sources
118 list (APPEND SOURCES "src/base/atomicops_internals_x86_gcc.cc")
121 # TODO: add support for ARCM arch
124 # Add POSIX specific sources
127 "src/base/synchronization/lock_impl_posix.cc"
128 "src/base/threading/platform_thread_posix.cc"
129 "src/base/threading/thread_local_posix.cc"
132 # TODO: add Windows support (define COMPILER_MSVC, OS_WIN)
135 "src/base/synchronization/lock_impl_win.cc"
136 "src/base/threading/platform_thread_win.cc"
137 "src/base/threading/thread_local_win.cc"
139 # TODO: Windows specific flags
143 include_directories ("src")
145 add_library (phonenumber STATIC ${SOURCES})
146 add_dependencies (phonenumber generate-sources)
148 target_link_libraries (phonenumber re2)
153 "src/phonenumberutil_test.cc"
154 "src/re2_cache_test.cc"
156 "src/stringutil_test.cc"
159 add_executable (libphonenumber_test ${TEST_SOURCES})
161 target_link_libraries (libphonenumber_test phonenumber gtest pthread)