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.")
69 find_path (ICU_INCLUDE_DIR unicode/unistr.h unicode/normlzr.h)
71 if (ICU_INCLUDE_DIR STREQUAL "ICU_INCLUDE_DIR-NOTFOUND")
73 "Can't find ICU headers. Please read README.")
76 include_directories (${ICU_INCLUDE_DIR})
78 find_library (ICU_LIB icui18n)
80 if (ICU_LIB STREQUAL "ICU_LIB-NOTFOUND")
82 "Can't find ICU library. Please read README.")
86 # Add protoc (Protocol Buffers compiler) target
88 PROTOBUF_SOURCES "${CMAKE_SOURCE_DIR}/src/phonemetadata.proto"
89 "${CMAKE_SOURCE_DIR}/src/phonenumber.proto"
94 PROTOBUF_OUTPUT "${CMAKE_SOURCE_DIR}/src/phonemetadata.pb.cc"
95 "${CMAKE_SOURCE_DIR}/src/phonemetadata.pb.h"
96 "${CMAKE_SOURCE_DIR}/src/phonenumber.pb.cc"
97 "${CMAKE_SOURCE_DIR}/src/phonenumber.pb.h"
101 COMMAND ${PROTOC} --cpp_out=${CMAKE_SOURCE_DIR}
102 --proto_path=${CMAKE_SOURCE_DIR} ${PROTOBUF_SOURCES}
104 OUTPUT ${PROTOBUF_OUTPUT}
105 DEPENDS ${PROTOBUF_SOURCES}
111 DEPENDS ${PROTOBUF_OUTPUT}
112 COMMENT "Generating Protocol Buffers code"
115 # Platform independent sources
118 "src/base/at_exit.cc"
119 "src/base/lazy_instance.cc"
120 "src/base/string_piece.cc"
121 "src/base/synchronization/lock.cc"
122 "src/base/threading/thread_restrictions.cc"
123 "src/default_logger.cc"
124 "src/logger_adapter.cc"
125 "src/metadata.cc" # Generated by src/embed_binary_data.sh
126 "src/phonemetadata.pb.cc" # Generated by Protocol Buffers
127 "src/phonenumber.pb.cc" # Generated by Protocol Buffers
128 "src/phonenumberutil.cc"
132 "src/utf/unicodetext.cc"
137 if (CMAKE_COMPILER_IS_GNUCXX)
138 add_definitions ("-Wall -Wextra -Werror")
140 # The next flags are needed by base/ source files to compile
141 # low level code needed by Singleton
142 add_definitions ("-DCOMPILER_GCC -DOS_POSIX -DOS_LINUX")
144 if (${CMAKE_SYSTEM_PROCESSOR} MATCHES "x86.*")
145 add_definitions ("-DARCH_CPU_X86_FAMILY")
146 # Add GCC specific sources
147 list (APPEND SOURCES "src/base/atomicops_internals_x86_gcc.cc")
149 elseif (${CMAKE_SYSTEM_PROCESSOR} MATCHES ".*arm.*")
150 add_definitions ("-DARCH_CPU_ARM_FAMILY")
154 # Add POSIX specific sources
157 "src/base/synchronization/lock_impl_posix.cc"
158 "src/base/threading/platform_thread_posix.cc"
159 "src/base/threading/thread_local_posix.cc"
162 # TODO: add Windows support (define COMPILER_MSVC, OS_WIN)
165 "src/base/synchronization/lock_impl_win.cc"
166 "src/base/threading/platform_thread_win.cc"
167 "src/base/threading/thread_local_win.cc"
169 # TODO: Windows specific flags
173 include_directories ("src")
174 include_directories (".")
176 add_library (phonenumber STATIC ${SOURCES})
177 add_dependencies (phonenumber generate-sources)
179 target_link_libraries (phonenumber re2 protobuf icui18n)
184 "src/phonenumberutil_test.cc"
185 "src/re2_cache_test.cc"
187 "src/stringutil_test.cc"
188 "src/test_metadata.cc"
191 add_executable (libphonenumber_test ${TEST_SOURCES})
193 target_link_libraries (libphonenumber_test phonenumber gtest pthread)