[evolution-data-server/wip/cmake] FindPhonenumber.cmake
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server/wip/cmake] FindPhonenumber.cmake
- Date: Tue, 20 Sep 2016 13:22:49 +0000 (UTC)
commit 9cef45d9d46830830cf992cc88fcb0a62e0c4c88
Author: Milan Crha <mcrha redhat com>
Date: Tue Sep 20 15:22:47 2016 +0200
FindPhonenumber.cmake
CMakeLists.txt | 1 +
cmake/modules/FindKRB5.cmake | 2 +-
cmake/modules/FindPhonenumber.cmake | 77 +++++++++++++++++++++++++++++++++++
config.h.in | 13 +++---
4 files changed, 85 insertions(+), 8 deletions(-)
---
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 4d2f876..8b1ac4f 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -133,6 +133,7 @@ include(SetupBuildFlags)
include(UninstallTarget)
include(FindKRB5)
+include(FindPhonenumber)
include(FindSMIME)
add_printable_option(ENABLE_MAINTAINER_MODE "Enable maintainer mode" OFF)
diff --git a/cmake/modules/FindKRB5.cmake b/cmake/modules/FindKRB5.cmake
index a586eb5..941923f 100644
--- a/cmake/modules/FindKRB5.cmake
+++ b/cmake/modules/FindKRB5.cmake
@@ -6,7 +6,7 @@
# HAVE_KRB5 - set to ON, if Kerberos 5 support is enabled and libraries found
# HAVE_MIT_KRB5 - set to ON, when found MIT implementation
# HAVE_HEIMDAL_KRB5 - set to ON, when found Heimdal implementation
-# KRB5_CFLAGS - CFLAGS to use with target_compile_options() and similarcomands
+# KRB5_CFLAGS - CFLAGS to use with target_compile_options() and similar commands
# KRB5_LDFLAGS - LDFLAGS to use with target_link_libraries() and similar commands
include(CheckCSourceCompiles)
diff --git a/cmake/modules/FindPhonenumber.cmake b/cmake/modules/FindPhonenumber.cmake
new file mode 100644
index 0000000..cf54804
--- /dev/null
+++ b/cmake/modules/FindPhonenumber.cmake
@@ -0,0 +1,77 @@
+# FindPhonenumber.cmake
+#
+# Searches for Google's libphonenumber library
+#
+# Defines -DWITH_PHONENUMBER=PATH variable, which defaults to OFF.
+# The output is:
+# ENABLE_PHONENUMBER - ON, when the libphonenumber is used
+# PHONENUMBER_RAW_INPUT_NEEDED - Whether Parse() or ParseAndKeepRawInput() must be used to get the
country-code source
+# PHONENUMBER_CXXFLAGS - CXXFLAGS to use with target_compile_options() and similar commands
+# PHONENUMBER_LDFLAGS - LDFLAGS to use with target_link_libraries() and similar commands
+
+include(PrintableOptions)
+include(CheckCXXSourceCompiles)
+
+add_printable_variable_path(WITH_PHONENUMBER "Path prefix where the libphonenumber is installed" OFF)
+
+if(NOT WITH_PHONENUMBER)
+ return()
+endif(NOT WITH_PHONENUMBER)
+
+set(PHONENUMBER_CXXFLAGS -DI18N_PHONENUMBERS_USE_BOOST)
+set(PHONENUMBER_LDFLAGS -lphonenumber)
+
+string(LENGTH "${CMAKE_BINARY_DIR}" bindirlen)
+string(SUBSTRING "${WITH_PHONENUMBER}" 0 ${bindirlen} substr)
+string(TOUPPER "${WITH_PHONENUMBER}" optupper)
+
+if(("${optupper}" STREQUAL "ON") OR ("${substr}" STREQUAL "${CMAKE_BINARY_DIR}"))
+ set(WITH_PHONENUMBER "ON")
+else(("${optupper}" STREQUAL "ON") OR ("${substr}" STREQUAL "${CMAKE_BINARY_DIR}"))
+ set(PHONENUMBER_CXXFLAGS "-I${WITH_PHONENUMBER}/include ${PHONENUMBER_CXXFLAGS}")
+ set(PHONENUMBER_LDFLAGS "-L${WITH_PHONENUMBER}/lib${LIB_SUFFIX} ${PHONENUMBER_LDFLAGS}")
+endif(("${optupper}" STREQUAL "ON") OR ("${substr}" STREQUAL "${CMAKE_BINARY_DIR}"))
+
+unset(bindirlen)
+unset(substr)
+unset(optupper)
+
+set(CMAKE_REQUIRED_FLAGS "${PHONENUMBER_CXXFLAGS}")
+
+foreach(lib boost_thread-mt boost_thread)
+ set(CMAKE_REQUIRED_LIBRARIES "${PHONENUMBER_LDFLAGS} -l${lib}")
+ CHECK_CXX_SOURCE_COMPILES("#include <phonenumbers/phonenumberutil.h>
+
+ int main(void) {
+ i18n::phonenumbers::PhoneNumberUtil::GetInstance();
+ return 0;
+ }" phone_number_with_${lib})
+ if(phone_number_with_${lib})
+ set(ENABLE_PHONENUMBER ON)
+ set(PHONENUMBER_LDFLAGS "${CMAKE_REQUIRED_LIBRARIES}")
+ break()
+ endif(phone_number_with_${lib})
+endforeach(lib)
+
+if(NOT ENABLE_PHONENUMBER)
+ message(FATAL_ERROR "libphonenumber cannot be used. Use -DWITH_PHONENUMBER=PATH to specify the
library prefix, or -DWITH_PHONENUMBER=OFF to disable it.")
+endif(NOT ENABLE_PHONENUMBER)
+
+CHECK_CXX_SOURCE_COMPILES("#include <phonenumbers/phonenumberutil.h>
+
+ int main(void) {
+ namespace pn = i18n::phonenumbers;
+
+ pn::PhoneNumber n;
+
+ if (pn::PhoneNumberUtil::GetInstance ()->
+ Parse(\"049(800)46663\", \"DE\", &n) ==
pn::PhoneNumberUtil::NO_PARSING_ERROR
+ && n.has_country_code_source ()
+ && n.country_code_source () == 49)
+ return EXIT_SUCCESS;
+
+ return EXIT_FAILURE;
+ }" PHONENUMBER_RAW_INPUT_NEEDED)
+
+unset(CMAKE_REQUIRED_FLAGS)
+unset(CMAKE_REQUIRED_LIBRARIES)
diff --git a/config.h.in b/config.h.in
index 38b4c8e..8b6eee1 100644
--- a/config.h.in
+++ b/config.h.in
@@ -141,6 +141,12 @@
/* Define if you have Sun Kerberosv5 */
#cmakedefine HAVE_SUN_KRB5 1
+/* Enable libphonenumber parsing */
+#cmakedefine ENABLE_PHONENUMBER 1
+
+/* Whether Parse() or ParseAndKeepRawInput() must be used to get the country-code source */
+#cmakedefine PHONENUMBER_RAW_INPUT_NEEDED 1
+
/* *************************************************** */
@@ -156,9 +162,6 @@
/* Define to 1 if using `alloca.c'. */
/* #undef C_ALLOCA */
-/* Enable phonenumber parsing */
-/* #undef ENABLE_PHONENUMBER */
-
/* Solaris-style gethostbyaddr_r */
/* #undef GETHOSTBYADDR_R_SEVEN_ARGS */
@@ -295,10 +298,6 @@
/* Define to the version of this package. */
#define PACKAGE_VERSION "3.22.0"
-/* Whether Parse() or ParseAndKeepRawInput() must be used to get the
- country-code source */
-/* #undef PHONENUMBER_RAW_INPUT_NEEDED */
-
/* If using the C implementation of alloca, define if you know the
direction of stack growth for your system; otherwise it will be
automatically deduced at runtime.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]