Adding dummy RE2Cache interface. Patch contributed by roubert@google.com
[platform/upstream/libphonenumber.git] / cpp / CMakeLists.txt
1 # Copyright (C) 2011 Google Inc.
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 cmake_minimum_required (VERSION 2.8)
16
17 project (libphonenumber)
18
19 # Find Google Test library
20 find_path (GTEST_INCLUDE_DIR gtest/gtest.h)
21
22 if (GTEST_INCLUDE_DIR STREQUAL "GTEST_INCLUDE_DIR-NOTFOUND")
23   message (FATAL_ERROR
24     "Can't find Google Test framework headers. Please read README.")
25 endif ()
26
27 include_directories (${GTEST_INCLUDE_DIR})
28
29 find_library (GTEST_LIB gtest)
30
31 if (GTEST_LIB STREQUAL "GTEST_LIB-NOTFOUND")
32   message (FATAL_ERROR
33     "Can't find Google Test framework library. Please read README.")
34 endif ()
35
36
37 # Find Google RE2 library
38 find_path (RE2_INCLUDE_DIR re2/re2.h)
39
40 if (RE2_INCLUDE_DIR STREQUAL "RE2_INCLUDE_DIR-NOTFOUND")
41   message (FATAL_ERROR
42     "Can't find Google RE2 headers. Please read README.")
43 endif ()
44
45 include_directories (${RE2_INCLUDE_DIR})
46
47 find_library (RE2_LIB re2)
48
49 if (RE2_LIB STREQUAL "RE2_LIB-NOTFOUND")
50   message (FATAL_ERROR
51     "Can't find Google RE2 library. Please read README.")
52 endif ()
53
54
55 # Find Protocol Buffers compiler
56 find_program (PROTOC NAMES protoc)
57
58 if (PROTOC STREQUAL "PROTOC-NOTFOUND")
59   message (FATAL_ERROR
60       "Can't find Google Protocol Buffers compiler (protoc). "
61       "Please read README.")
62 endif ()
63
64 # Add protoc (Protocol Buffers compiler) target
65 set (
66   PROTOBUF_SOURCES "${CMAKE_SOURCE_DIR}/src/phonemetadata.proto"
67                    "${CMAKE_SOURCE_DIR}/src/phonenumber.proto"
68
69 )
70
71 set (
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"
76 )
77
78 add_custom_command (
79   COMMAND ${PROTOC} --cpp_out=${CMAKE_SOURCE_DIR}
80     --proto_path=${CMAKE_SOURCE_DIR} ${PROTOBUF_SOURCES}
81
82   OUTPUT ${PROTOBUF_OUTPUT}
83   DEPENDS ${PROTOBUF_SOURCES}
84 )
85
86 add_custom_target (
87   generate-sources
88
89   DEPENDS ${PROTOBUF_OUTPUT}
90   COMMENT "Generating Protocol Buffers code"
91 )
92
93 # Platform independent sources
94 set (
95   SOURCES
96   "src/base/at_exit.cc"
97   "src/base/lazy_instance.cc"
98   "src/base/synchronization/lock.cc"
99   "src/base/threading/thread_restrictions.cc"
100   "src/phonenumberutil.cc"
101   "src/re2_cache.cc"
102   "src/stringutil.cc"
103   "src/utf/rune.c"
104 )
105
106 if (UNIX)
107   if (CMAKE_COMPILER_IS_GNUCXX)
108     add_definitions ("-Wall -Wextra -Werror")
109
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")
113
114     if (${CMAKE_SYSTEM_PROCESSOR} MATCHES "x86.*")
115       add_definitions ("-DARCH_CPU_X86_FAMILY")
116
117       # Add GCC specific sources
118       list (APPEND SOURCES "src/base/atomicops_internals_x86_gcc.cc")
119     endif ()
120
121     # TODO: add support for ARCM arch
122   endif ()
123
124   # Add POSIX specific sources
125   list (
126     APPEND 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"
130   )
131 else (WIN32)
132   # TODO: add Windows support (define COMPILER_MSVC, OS_WIN)
133   list (
134     APPEND SOURCES
135     "src/base/synchronization/lock_impl_win.cc"
136     "src/base/threading/platform_thread_win.cc"
137     "src/base/threading/thread_local_win.cc"
138   )
139   # TODO: Windows specific flags
140 endif ()
141
142
143 include_directories ("src")
144                           
145 add_library (phonenumber STATIC ${SOURCES})
146 add_dependencies (phonenumber generate-sources)
147
148 target_link_libraries (phonenumber re2)
149
150 # Tests
151
152 set (TEST_SOURCES
153   "src/phonenumberutil_test.cc"
154   "src/re2_cache_test.cc"
155   "src/run_tests.cc"
156   "src/stringutil_test.cc"
157 )
158
159 add_executable (libphonenumber_test ${TEST_SOURCES})
160
161 target_link_libraries (libphonenumber_test phonenumber gtest pthread)