Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(387)

Side by Side Diff: third_party/libphonenumber/cpp/CMakeLists.txt

Issue 6930013: Re-committing http://codereview.chromium.org/6803005/ after fixing multi-dll build: (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
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 cmake_minimum_required (VERSION 2.8)
18
19 project (libphonenumber)
20
21 # Helper functions dealing with finding libraries and programs this library
22 # depends on.
23
24 function (print_error DESCRIPTION FILE)
25 message (FATAL_ERROR
26 "Can't find ${DESCRIPTION}: can't locate ${FILE}. Please read the README.")
27 endfunction ()
28
29 # Find a library. If it has not been found, stop CMake with a fatal error
30 # message.
31 function (find_required_library NAME HEADER LIBRARY DESCRIPTION)
32 # Check the header.
33 find_path (${NAME}_INCLUDE_DIR ${HEADER})
34 set (INCLUDE_DIR ${${NAME}_INCLUDE_DIR})
35
36 if (${INCLUDE_DIR} STREQUAL "${INCLUDE_DIR}-NOTFOUND")
37 print_error (${DESCRIPTION} ${HEADER})
38 endif ()
39 include_directories (${INCLUDE_DIR})
40 # Check the binary.
41 find_library (${NAME}_LIB ${LIBRARY})
42 set (LIB ${NAME}_LIB)
43
44 if (${LIB} STREQUAL "${LIB}-NOTFOUND")
45 print_error (${DESCRIPTION} ${LIBRARY})
46 endif ()
47 endfunction (find_required_library)
48
49 # Check the library version (if pkg-config available).
50 find_package (PkgConfig)
51 function (check_library_version NAME LIBRARY VERSION)
52 if (PKG_CONFIG_EXECUTABLE)
53 pkg_check_modules (NAME REQUIRED ${LIBRARY}>=${VERSION})
54 endif (PKG_CONFIG_EXECUTABLE)
55 endfunction ()
56
57 # Find a program. If it has not been found, stop CMake with a fatal error
58 # message.
59 function (find_required_program NAME FILENAME DESCRIPTION)
60 find_program (${NAME}_BIN NAMES ${FILENAME})
61
62 if (${NAME}_BIN STREQUAL "${${NAME}_BIN}-NOTFOUND")
63 print_error (${DESCRIPTION} ${FILENAME})
64 endif ()
65 endfunction (find_required_program)
66
67 # Find all the required libraries and programs.
68 find_required_library (GTEST gtest/gtest.h gtest "Google Test framework")
69
70 find_required_library (RE2 re2/re2.h re2 "Google RE2")
71
72 find_required_library (PROTOBUF google/protobuf/message_lite.h protobuf
73 "Google Protocol Buffers")
74 check_library_version (PC_PROTOBUF protobuf 2.4)
75
76 find_required_library (ICU unicode/unistr.h icui18n "ICU")
77 check_library_version (PC_ICU icui18n 4.4)
78
79 find_required_program (PROTOC protoc
80 "Google Protocol Buffers compiler (protoc)")
81
82 find_required_program (JAVA java
83 "Java Runtime Environment")
84
85 # Add protoc (Protocol Buffers compiler) target.
86 set (RESOURCES_DIR "${CMAKE_SOURCE_DIR}/../resources")
87
88 set (
89 PROTOBUF_SOURCES "${RESOURCES_DIR}/phonemetadata.proto"
90 "${RESOURCES_DIR}/phonenumber.proto"
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_BIN} --cpp_out="${CMAKE_SOURCE_DIR}/src"
102 --proto_path=${RESOURCES_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 # Add metadata code generation targets.
116
117 # This function is invoked twice to create metadata & test metadata code
118 # generation targets.
119 function (add_metadata_gen_target TARGET_NAME
120 XML_FILE
121 FOR_TESTING)
122 if (${FOR_TESTING} STREQUAL "true")
123 set (GEN_OUTPUT_PREFIX "${CMAKE_SOURCE_DIR}/src/metadata")
124 elseif (${FOR_TESTING} STREQUAL "false")
125 set (GEN_OUTPUT_PREFIX "${CMAKE_SOURCE_DIR}/src/test_metadata")
126 else ()
127 message (FATAL_ERROR
128 "Unexpected value '${FOR_TESTING}' for testing parameter")
129 endif ()
130
131 set (GEN_OUTPUT "${GEN_OUTPUT_PREFIX}.cc ${GEN_OUTPUT_PREFIX}.h")
132 set (JAR_PATH "${CMAKE_SOURCE_DIR}/../tools/java/cpp-build/target")
133 set (JAR_PATH "${JAR_PATH}/cpp-build-1.0-SNAPSHOT-jar-with-dependencies.jar")
134
135 add_custom_command (
136 COMMAND ${JAVA_BIN} -jar
137 ${JAR_PATH} BuildMetadataCppFromXml ${XML_FILE} ${CMAKE_SOURCE_DIR}/src
138 ${FOR_TESTING}
139
140 OUTPUT ${GEN_OUTPUT}
141 DEPENDS ${XML_FILE}
142 )
143 add_custom_target (
144 ${TARGET_NAME}
145 DEPENDS ${GEN_OUTPUT}
146 COMMENT "Generating Metadata code"
147 )
148 endfunction (add_metadata_gen_target)
149
150 # Add metadata generation target.
151 add_metadata_gen_target (
152 "generate-metadata"
153 "${RESOURCES_DIR}/PhoneNumberMetaData.xml"
154 "false"
155 )
156
157 # Add test metadata generation target.
158 add_metadata_gen_target (
159 "generate-test-metadata"
160 "${RESOURCES_DIR}/PhoneNumberMetaDataForTesting.xml"
161 "true"
162 )
163
164 # Platform independent sources.
165 set (
166 SOURCES
167 "src/base/at_exit.cc"
168 "src/base/lazy_instance.cc"
169 "src/base/string_piece.cc"
170 "src/base/synchronization/lock.cc"
171 "src/base/threading/thread_restrictions.cc"
172 "src/default_logger.cc"
173 "src/logger_adapter.cc"
174 "src/metadata.cc" # Generated by build tools.
175 "src/phonemetadata.pb.cc" # Generated by Protocol Buffers.
176 "src/phonenumber.cc"
177 "src/phonenumber.pb.cc" # Generated by Protocol Buffers.
178 "src/phonenumberutil.cc"
179 "src/re2_cache.cc"
180 "src/regexp_adapter_re2.cc",
181 "src/stringutil.cc"
182 "src/utf/rune.c"
183 "src/utf/unicodetext.cc"
184 "src/utf/unilib.cc"
185 )
186
187 if (UNIX)
188 if (CMAKE_COMPILER_IS_GNUCXX)
189 add_definitions ("-Wall -Wextra -Werror")
190
191 # The next flags are needed by base/ source files to compile low level code
192 # needed by Singleton.
193 add_definitions ("-DCOMPILER_GCC -DOS_POSIX -DOS_LINUX")
194
195 if (${CMAKE_SYSTEM_PROCESSOR} MATCHES "x86.*")
196 add_definitions ("-DARCH_CPU_X86_FAMILY")
197 # Add GCC specific sources.
198 list (APPEND SOURCES "src/base/atomicops_internals_x86_gcc.cc")
199
200 elseif (${CMAKE_SYSTEM_PROCESSOR} MATCHES ".*arm.*")
201 add_definitions ("-DARCH_CPU_ARM_FAMILY")
202 endif ()
203 endif ()
204
205 # Add POSIX specific sources.
206 list (
207 APPEND SOURCES
208 "src/base/synchronization/lock_impl_posix.cc"
209 "src/base/threading/platform_thread_posix.cc"
210 "src/base/threading/thread_local_posix.cc"
211 )
212 else (WIN32)
213 # TODO: add Windows support (define COMPILER_MSVC, OS_WIN).
214 list (
215 APPEND SOURCES
216 "src/base/synchronization/lock_impl_win.cc"
217 "src/base/threading/platform_thread_win.cc"
218 "src/base/threading/thread_local_win.cc"
219 )
220 # TODO: Windows specific flags.
221 endif ()
222
223 include_directories ("src")
224 include_directories (".")
225
226 add_library (phonenumber STATIC ${SOURCES})
227 add_dependencies (phonenumber generate-sources)
228
229 target_link_libraries (phonenumber ${RE2_LIB} ${PROTOBUF_LIB} ${ICU_LIB})
230
231 # Tests.
232 set (TEST_SOURCES
233 "src/phonenumberutil_test.cc"
234 "src/re2_cache_test.cc"
235 "src/regexp_adapter_unittest.cc",
236 "src/run_tests.cc"
237 "src/stringutil_test.cc"
238 "src/test_metadata.cc" # Generated by build tools.
239 )
240
241 add_executable (libphonenumber_test ${TEST_SOURCES})
242 target_link_libraries (libphonenumber_test phonenumber ${GTEST_LIB} pthread)
OLDNEW
« no previous file with comments | « third_party/libphonenumber/chrome/regexp_adapter_icuregexp.cc ('k') | third_party/libphonenumber/cpp/LICENSE » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698