Cpp: adding ARM support to CMakeLists. Patch contributed by philip.liard.
[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 # Author: Philippe Liard
16
17
18 cmake_minimum_required (VERSION 2.8)
19
20 project (libphonenumber)
21
22 # Find Google Test library
23 find_path (GTEST_INCLUDE_DIR gtest/gtest.h)
24
25 if (GTEST_INCLUDE_DIR STREQUAL "GTEST_INCLUDE_DIR-NOTFOUND")
26   message (FATAL_ERROR
27     "Can't find Google Test framework headers. Please read README.")
28 endif ()
29
30 include_directories (${GTEST_INCLUDE_DIR})
31
32 find_library (GTEST_LIB gtest)
33
34 if (GTEST_LIB STREQUAL "GTEST_LIB-NOTFOUND")
35   message (FATAL_ERROR
36     "Can't find Google Test framework library. Please read README.")
37 endif ()
38
39
40 # Find Google RE2 library
41 find_path (RE2_INCLUDE_DIR re2/re2.h)
42
43 if (RE2_INCLUDE_DIR STREQUAL "RE2_INCLUDE_DIR-NOTFOUND")
44   message (FATAL_ERROR
45     "Can't find Google RE2 headers. Please read README.")
46 endif ()
47
48 include_directories (${RE2_INCLUDE_DIR})
49
50 find_library (RE2_LIB re2)
51
52 if (RE2_LIB STREQUAL "RE2_LIB-NOTFOUND")
53   message (FATAL_ERROR
54     "Can't find Google RE2 library. Please read README.")
55 endif ()
56
57
58 # Find Protocol Buffers compiler
59 find_program (PROTOC NAMES protoc)
60
61 if (PROTOC STREQUAL "PROTOC-NOTFOUND")
62   message (FATAL_ERROR
63       "Can't find Google Protocol Buffers compiler (protoc). "
64       "Please read README.")
65 endif ()
66
67
68 # Find ICU
69 find_path (ICU_INCLUDE_DIR unicode/unistr.h unicode/normlzr.h)
70
71 if (ICU_INCLUDE_DIR STREQUAL "ICU_INCLUDE_DIR-NOTFOUND")
72   message (FATAL_ERROR
73     "Can't find ICU headers. Please read README.")
74 endif ()
75
76 include_directories (${ICU_INCLUDE_DIR})
77
78 find_library (ICU_LIB icui18n)
79
80 if (ICU_LIB STREQUAL "ICU_LIB-NOTFOUND")
81   message (FATAL_ERROR
82     "Can't find ICU library. Please read README.")
83 endif ()
84
85
86 # Add protoc (Protocol Buffers compiler) target
87 set (
88   PROTOBUF_SOURCES "${CMAKE_SOURCE_DIR}/src/phonemetadata.proto"
89                    "${CMAKE_SOURCE_DIR}/src/phonenumber.proto"
90
91 )
92
93 set (
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"
98 )
99
100 add_custom_command (
101   COMMAND ${PROTOC} --cpp_out=${CMAKE_SOURCE_DIR}
102     --proto_path=${CMAKE_SOURCE_DIR} ${PROTOBUF_SOURCES}
103
104   OUTPUT ${PROTOBUF_OUTPUT}
105   DEPENDS ${PROTOBUF_SOURCES}
106 )
107
108 add_custom_target (
109   generate-sources
110
111   DEPENDS ${PROTOBUF_OUTPUT}
112   COMMENT "Generating Protocol Buffers code"
113 )
114
115 # Platform independent sources
116 set (
117   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"
129   "src/re2_cache.cc"
130   "src/stringutil.cc"
131   "src/utf/rune.c"
132   "src/utf/unicodetext.cc"
133   "src/utf/unilib.cc"
134 )
135
136 if (UNIX)
137   if (CMAKE_COMPILER_IS_GNUCXX)
138     add_definitions ("-Wall -Wextra -Werror")
139
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")
143
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")
148
149     elseif (${CMAKE_SYSTEM_PROCESSOR} MATCHES ".*arm.*")
150       add_definitions ("-DARCH_CPU_ARM_FAMILY")
151     endif ()
152   endif ()
153
154   # Add POSIX specific sources
155   list (
156     APPEND 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"
160   )
161 else (WIN32)
162   # TODO: add Windows support (define COMPILER_MSVC, OS_WIN)
163   list (
164     APPEND SOURCES
165     "src/base/synchronization/lock_impl_win.cc"
166     "src/base/threading/platform_thread_win.cc"
167     "src/base/threading/thread_local_win.cc"
168   )
169   # TODO: Windows specific flags
170 endif ()
171
172
173 include_directories ("src")
174 include_directories (".")
175                           
176 add_library (phonenumber STATIC ${SOURCES})
177 add_dependencies (phonenumber generate-sources)
178
179 target_link_libraries (phonenumber re2 protobuf icui18n)
180
181 # Tests
182
183 set (TEST_SOURCES
184   "src/phonenumberutil_test.cc"
185   "src/re2_cache_test.cc"
186   "src/run_tests.cc"
187   "src/stringutil_test.cc"
188   "src/test_metadata.cc"
189 )
190
191 add_executable (libphonenumber_test ${TEST_SOURCES})
192
193 target_link_libraries (libphonenumber_test phonenumber gtest pthread)