~phablet-team/history-service/trunk

« back to all changes in this revision

Viewing changes to cmake/modules/LibFindMacros.cmake

Use libphonenumber for phone number validation, normalization and comparison. Fixes: #1471545, #1473028
Approved by: PS Jenkins bot

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Version 1.0 (2013-04-12)
 
2
# Public Domain, originally written by Lasse Kärkkäinen <tronic@zi.fi>
 
3
# Published at http://www.cmake.org/Wiki/CMake:How_To_Find_Libraries
 
4
 
 
5
# If you improve the script, please modify the forementioned wiki page because
 
6
# I no longer maintain my scripts (hosted as static files at zi.fi). Feel free
 
7
# to remove this entire header if you use real version control instead.
 
8
 
 
9
# Changelog:
 
10
# 2013-04-12  Added version number (1.0) and this header, no other changes
 
11
# 2009-10-08  Originally published
 
12
 
 
13
 
 
14
# Works the same as find_package, but forwards the "REQUIRED" and "QUIET" arguments
 
15
# used for the current package. For this to work, the first parameter must be the
 
16
# prefix of the current package, then the prefix of the new package etc, which are
 
17
# passed to find_package.
 
18
macro (libfind_package PREFIX)
 
19
  set (LIBFIND_PACKAGE_ARGS ${ARGN})
 
20
  if (${PREFIX}_FIND_QUIETLY)
 
21
    set (LIBFIND_PACKAGE_ARGS ${LIBFIND_PACKAGE_ARGS} QUIET)
 
22
  endif (${PREFIX}_FIND_QUIETLY)
 
23
  if (${PREFIX}_FIND_REQUIRED)
 
24
    set (LIBFIND_PACKAGE_ARGS ${LIBFIND_PACKAGE_ARGS} REQUIRED)
 
25
  endif (${PREFIX}_FIND_REQUIRED)
 
26
  find_package(${LIBFIND_PACKAGE_ARGS})
 
27
endmacro (libfind_package)
 
28
 
 
29
# CMake developers made the UsePkgConfig system deprecated in the same release (2.6)
 
30
# where they added pkg_check_modules. Consequently I need to support both in my scripts
 
31
# to avoid those deprecated warnings. Here's a helper that does just that.
 
32
# Works identically to pkg_check_modules, except that no checks are needed prior to use.
 
33
macro (libfind_pkg_check_modules PREFIX PKGNAME)
 
34
  if (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4)
 
35
    include(UsePkgConfig)
 
36
    pkgconfig(${PKGNAME} ${PREFIX}_INCLUDE_DIRS ${PREFIX}_LIBRARY_DIRS ${PREFIX}_LDFLAGS ${PREFIX}_CFLAGS)
 
37
  else (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4)
 
38
    find_package(PkgConfig)
 
39
    if (PKG_CONFIG_FOUND)
 
40
      pkg_check_modules(${PREFIX} ${PKGNAME})
 
41
    endif (PKG_CONFIG_FOUND)
 
42
  endif (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4)
 
43
endmacro (libfind_pkg_check_modules)
 
44
 
 
45
# Do the final processing once the paths have been detected.
 
46
# If include dirs are needed, ${PREFIX}_PROCESS_INCLUDES should be set to contain
 
47
# all the variables, each of which contain one include directory.
 
48
# Ditto for ${PREFIX}_PROCESS_LIBS and library files.
 
49
# Will set ${PREFIX}_FOUND, ${PREFIX}_INCLUDE_DIRS and ${PREFIX}_LIBRARIES.
 
50
# Also handles errors in case library detection was required, etc.
 
51
macro (libfind_process PREFIX)
 
52
  # Skip processing if already processed during this run
 
53
  if (NOT ${PREFIX}_FOUND)
 
54
    # Start with the assumption that the library was found
 
55
    set (${PREFIX}_FOUND TRUE)
 
56
 
 
57
    # Process all includes and set _FOUND to false if any are missing
 
58
    foreach (i ${${PREFIX}_PROCESS_INCLUDES})
 
59
      if (${i})
 
60
        set (${PREFIX}_INCLUDE_DIRS ${${PREFIX}_INCLUDE_DIRS} ${${i}})
 
61
        mark_as_advanced(${i})
 
62
      else (${i})
 
63
        set (${PREFIX}_FOUND FALSE)
 
64
      endif (${i})
 
65
    endforeach (i)
 
66
 
 
67
    # Process all libraries and set _FOUND to false if any are missing
 
68
    foreach (i ${${PREFIX}_PROCESS_LIBS})
 
69
      if (${i})
 
70
        set (${PREFIX}_LIBRARIES ${${PREFIX}_LIBRARIES} ${${i}})
 
71
        mark_as_advanced(${i})
 
72
      else (${i})
 
73
        set (${PREFIX}_FOUND FALSE)
 
74
      endif (${i})
 
75
    endforeach (i)
 
76
 
 
77
    # Print message and/or exit on fatal error
 
78
    if (${PREFIX}_FOUND)
 
79
      if (NOT ${PREFIX}_FIND_QUIETLY)
 
80
        message (STATUS "Found ${PREFIX} ${${PREFIX}_VERSION}")
 
81
      endif (NOT ${PREFIX}_FIND_QUIETLY)
 
82
    else (${PREFIX}_FOUND)
 
83
      if (${PREFIX}_FIND_REQUIRED)
 
84
        foreach (i ${${PREFIX}_PROCESS_INCLUDES} ${${PREFIX}_PROCESS_LIBS})
 
85
          message("${i}=${${i}}")
 
86
        endforeach (i)
 
87
        message (FATAL_ERROR "Required library ${PREFIX} NOT FOUND.\nInstall the library (dev version) and try again. If the library is already installed, use ccmake to set the missing variables manually.")
 
88
      endif (${PREFIX}_FIND_REQUIRED)
 
89
    endif (${PREFIX}_FOUND)
 
90
  endif (NOT ${PREFIX}_FOUND)
 
91
endmacro (libfind_process)
 
92
 
 
93
macro(libfind_library PREFIX basename)
 
94
  set(TMP "")
 
95
  if(MSVC80)
 
96
    set(TMP -vc80)
 
97
  endif(MSVC80)
 
98
  if(MSVC90)
 
99
    set(TMP -vc90)
 
100
  endif(MSVC90)
 
101
  set(${PREFIX}_LIBNAMES ${basename}${TMP})
 
102
  if(${ARGC} GREATER 2)
 
103
    set(${PREFIX}_LIBNAMES ${basename}${TMP}-${ARGV2})
 
104
    string(REGEX REPLACE "\\." "_" TMP ${${PREFIX}_LIBNAMES})
 
105
    set(${PREFIX}_LIBNAMES ${${PREFIX}_LIBNAMES} ${TMP})
 
106
  endif(${ARGC} GREATER 2)
 
107
  find_library(${PREFIX}_LIBRARY
 
108
    NAMES ${${PREFIX}_LIBNAMES}
 
109
    PATHS ${${PREFIX}_PKGCONF_LIBRARY_DIRS}
 
110
  )
 
111
endmacro(libfind_library)
 
112