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 # Author: Philippe Liard
18 cmake_minimum_required (VERSION 2.8)
20 project (libphonenumber)
22 # Find Google Test library
23 find_path (GTEST_INCLUDE_DIR gtest/gtest.h)
25 if (GTEST_INCLUDE_DIR STREQUAL "GTEST_INCLUDE_DIR-NOTFOUND")
27 "Can't find Google Test framework headers. Please read README.")
30 include_directories (${GTEST_INCLUDE_DIR})
32 find_library (GTEST_LIB gtest)
34 if (GTEST_LIB STREQUAL "GTEST_LIB-NOTFOUND")
36 "Can't find Google Test framework library. Please read README.")
40 # Find Google RE2 library
41 find_path (RE2_INCLUDE_DIR re2/re2.h)
43 if (RE2_INCLUDE_DIR STREQUAL "RE2_INCLUDE_DIR-NOTFOUND")
45 "Can't find Google RE2 headers. Please read README.")
48 include_directories (${RE2_INCLUDE_DIR})
50 find_library (RE2_LIB re2)
52 if (RE2_LIB STREQUAL "RE2_LIB-NOTFOUND")
54 "Can't find Google RE2 library. Please read README.")
58 # Find Protocol Buffers compiler
59 find_program (PROTOC NAMES protoc)
61 if (PROTOC STREQUAL "PROTOC-NOTFOUND")
63 "Can't find Google Protocol Buffers compiler (protoc). "
64 "Please read README.")
67 # Find Protocol Buffers library
68 find_path (PROTOBUF_INCLUDE_DIR google/protobuf/message_lite.h)
70 if (PROTOBUF_INCLUDE_DIR STREQUAL "PROTOBUF_INCLUDE_DIR-NOTFOUND")
72 "Can't find Google Protocol headers. Please read README.")
75 include_directories (${PROTOBUF_INCLUDE_DIR})
77 find_library (PROTOBUF_LIB protobuf)
79 if (PROTOBUF_LIB STREQUAL "PROTOBUF_LIB-NOTFOUND")
81 "Can't find Google Protocol Buffers library. Please read README.")
84 # Check Protocol Buffers version (if pkg-config available)
85 find_package (PkgConfig)
87 if (PKG_CONFIG_EXECUTABLE)
88 pkg_check_modules (PC_PROTOBUF REQUIRED protobuf>=2.4)
89 endif (PKG_CONFIG_EXECUTABLE)
92 find_path (ICU_INCLUDE_DIR unicode/unistr.h unicode/normlzr.h)
94 if (ICU_INCLUDE_DIR STREQUAL "ICU_INCLUDE_DIR-NOTFOUND")
96 "Can't find ICU headers. Please read README.")
99 include_directories (${ICU_INCLUDE_DIR})
101 find_library (ICU_LIB icui18n)
103 if (ICU_LIB STREQUAL "ICU_LIB-NOTFOUND")
105 "Can't find ICU library. Please read README.")
109 # Add protoc (Protocol Buffers compiler) target
111 PROTOBUF_SOURCES "${CMAKE_SOURCE_DIR}/src/phonemetadata.proto"
112 "${CMAKE_SOURCE_DIR}/src/phonenumber.proto"
117 PROTOBUF_OUTPUT "${CMAKE_SOURCE_DIR}/src/phonemetadata.pb.cc"
118 "${CMAKE_SOURCE_DIR}/src/phonemetadata.pb.h"
119 "${CMAKE_SOURCE_DIR}/src/phonenumber.pb.cc"
120 "${CMAKE_SOURCE_DIR}/src/phonenumber.pb.h"
124 COMMAND ${PROTOC} --cpp_out=${CMAKE_SOURCE_DIR}
125 --proto_path=${CMAKE_SOURCE_DIR} ${PROTOBUF_SOURCES}
127 OUTPUT ${PROTOBUF_OUTPUT}
128 DEPENDS ${PROTOBUF_SOURCES}
134 DEPENDS ${PROTOBUF_OUTPUT}
135 COMMENT "Generating Protocol Buffers code"
138 # Platform independent sources
141 "src/base/at_exit.cc"
142 "src/base/lazy_instance.cc"
143 "src/base/string_piece.cc"
144 "src/base/synchronization/lock.cc"
145 "src/base/threading/thread_restrictions.cc"
146 "src/default_logger.cc"
147 "src/logger_adapter.cc"
148 "src/metadata.cc" # Generated by src/embed_binary_data.sh
149 "src/phonemetadata.pb.cc" # Generated by Protocol Buffers
150 "src/phonenumber.pb.cc" # Generated by Protocol Buffers
151 "src/phonenumberutil.cc"
155 "src/utf/unicodetext.cc"
160 if (CMAKE_COMPILER_IS_GNUCXX)
161 add_definitions ("-Wall -Wextra -Werror")
163 # The next flags are needed by base/ source files to compile
164 # low level code needed by Singleton
165 add_definitions ("-DCOMPILER_GCC -DOS_POSIX -DOS_LINUX")
167 if (${CMAKE_SYSTEM_PROCESSOR} MATCHES "x86.*")
168 add_definitions ("-DARCH_CPU_X86_FAMILY")
169 # Add GCC specific sources
170 list (APPEND SOURCES "src/base/atomicops_internals_x86_gcc.cc")
172 elseif (${CMAKE_SYSTEM_PROCESSOR} MATCHES ".*arm.*")
173 add_definitions ("-DARCH_CPU_ARM_FAMILY")
177 # Add POSIX specific sources
180 "src/base/synchronization/lock_impl_posix.cc"
181 "src/base/threading/platform_thread_posix.cc"
182 "src/base/threading/thread_local_posix.cc"
185 # TODO: add Windows support (define COMPILER_MSVC, OS_WIN)
188 "src/base/synchronization/lock_impl_win.cc"
189 "src/base/threading/platform_thread_win.cc"
190 "src/base/threading/thread_local_win.cc"
192 # TODO: Windows specific flags
196 include_directories ("src")
197 include_directories (".")
199 add_library (phonenumber STATIC ${SOURCES})
200 add_dependencies (phonenumber generate-sources)
202 target_link_libraries (phonenumber ${RE2_LIB} ${PROTOBUF_LIB} ${ICU_LIB})
207 "src/phonenumberutil_test.cc"
208 "src/re2_cache_test.cc"
210 "src/stringutil_test.cc"
211 "src/test_metadata.cc"
214 add_executable (libphonenumber_test ${TEST_SOURCES})
216 target_link_libraries (libphonenumber_test phonenumber ${GTEST_LIB} pthread)