2010-05-15 Leandro Pereira <leandro@profusion.mobi>
[WebKit-https.git] / cmake / FindLibSoup2.cmake
1 # - Try to find libsoup
2 # Find libsoup headers, libraries and the answer to all questions.
3 #
4 #  LIBSOUP2_FOUND                True if libsoup2 got found
5 #  LIBSOUP2_INCLUDE_DIRS         Location of libsoup2 headers 
6 #  LIBSOUP2_LIBRARIES            List of libaries to use libsoup2
7 #  LIBSOUP2_LIBRARY_DIRS         Location of libsoup2 library
8 #
9 #  LIBSOUP22_FOUND               True if libsoup2.2 got found
10 #  LIBSOUP22_INCLUDE_DIRS        Location of libsoup2.2 headers 
11 #  LIBSOUP22_LIBRARIES           List of libaries to use libsoup2.2
12 #  LIBSOUP22_LIBRARY_DIRS        Location of libsoup2.2 library
13 #
14 #  LIBSOUP24_FOUND               True if libsoup2.4 got found
15 #  LIBSOUP24_INCLUDE_DIRS        Location of libsoup2.4 headers 
16 #  LIBSOUP24_LIBRARIES           List of libaries to use libsoup2.4
17 #  LIBSOUP24_LIBRARY_DIRS        Location of libsoup2.4 library
18 #
19 #  Set LIBSOUP2_MIN_VERSION to find libsoup2.2 or libsoup2.4 if only 
20 #  one of both libraries is supported
21 #
22 #  Don't use LIBSOUP2_MIN_VERSION if you want to support 
23 #  libsoup2.2 and libsoup2.4. 
24 #  Instead use LIBSPOUP22_MIN_VERSION and LIBSPOUP24_MIN_VERSION.
25 #
26 #  Set LIBSPOUP22_MIN_VERSION to find libsoup2.2 which version is
27 #  greater than LIBSPOUP22_MIN_VERSION
28 #
29 #  Set LIBSPOUP24_MIN_VERSION to find libsoup2.4 which version is
30 #  greater than LIBSPOUP24_MIN_VERSION
31 #
32 #  WARNING: It is not possible to set LIBSPOUP22_MIN_VERSION 
33 #  and support any version of libsoup2.4 at the same time.
34 #  In this situation you have to set LIBSPOUP24_MIN_VERSION also.
35 #  The same applies to LIBSPOUP24_MIN_VERSION and libsoup2.2.
36 #
37 #  Copyright (c) 2007 Daniel Gollub <gollub@b1-systems.de>
38 #  Copyright (c) 2008 Bjoern Ricks  <bjoern.ricks@gmail.com>
39 #
40 # Redistribution and use in source and binary forms, with or without
41 # modification, are permitted provided that the following conditions
42 # are met:
43
44 # 1. Redistributions of source code must retain the copyright
45 #    notice, this list of conditions and the following disclaimer.
46 # 2. Redistributions in binary form must reproduce the copyright
47 #    notice, this list of conditions and the following disclaimer in the
48 #    documentation and/or other materials provided with the distribution.
49 # 3. The name of the author may not be used to endorse or promote products
50 #    derived from this software without specific prior written permission.
51
52 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
53 # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
54 # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
55 # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
56 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
57 # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
58 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
59 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
60 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
61 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
62 #
63
64 INCLUDE( FindPkgConfig )
65
66 IF ( LibSoup2_FIND_REQUIRED )
67         SET( _pkgconfig_REQUIRED "REQUIRED" )
68 ELSE( LibSoup2_FIND_REQUIRED )
69         SET( _pkgconfig_REQUIRED "" )
70 ENDIF ( LibSoup2_FIND_REQUIRED )
71
72 IF ( LIBSOUP2_MIN_VERSION )
73         STRING(REGEX REPLACE "^(2)(\\.)([0-9]*)(\\.?)(.*)" "\\3" LIBSOUP2_VERSION_MINOR "${LIBSOUP2_MIN_VERSION}")
74         IF ( LIBSOUP2_VERSION_MINOR EQUAL "2" )
75                 SET( LIBSOUP22_MIN_VERSION "${LIBSOUP2_MIN_VERSION}" )
76         ELSE ( LIBSOUP2_VERSION_MINOR EQUAL "2" )
77                 SET( LIBSOUP24_MIN_VERSION "${LIBSOUP2_MIN_VERSION}" )
78         ENDIF ( LIBSOUP2_VERSION_MINOR EQUAL "2" )
79 ENDIF ( LIBSOUP2_MIN_VERSION )
80
81 # try to find libsoup2.2>=LIBSOUP22_MIN_VERSION
82 IF ( LIBSOUP22_MIN_VERSION )
83         PKG_SEARCH_MODULE( LIBSOUP22 libsoup-2.2>=${LIBSOUP22_MIN_VERSION} libsoup2>=${LIBSOUP22_MIN_VERSION} )
84 ENDIF ( LIBSOUP22_MIN_VERSION )
85
86 # try to find libsoup2.4>=LIBSOUP24_MIN_VERSION
87 IF ( LIBSOUP24_MIN_VERSION )
88         PKG_SEARCH_MODULE( LIBSOUP24 libsoup-2.4>=${LIBSOUP24_MIN_VERSION} libsoup2>=${LIBSOUP24_MIN_VERSION} )
89 ENDIF ( LIBSOUP24_MIN_VERSION ) 
90
91 # try to find any version of libsoup2.4 if LIBSOUP22_MIN_VERSION is not set
92 IF ( NOT LIBSOUP24_FOUND AND NOT LIBSOUP22_MIN_VERSION )
93         PKG_SEARCH_MODULE( LIBSOUP24 libsoup-2.4 libsoup2 )
94 ENDIF ( NOT LIBSOUP24_FOUND AND NOT LIBSOUP22_MIN_VERSION)
95
96 # try to find any version of libsoup2.2 if LIBSOUP24_MIN_VERSION is not set
97 IF ( NOT LIBSOUP22_FOUND AND NOT LIBSOUP24_MIN_VERSION )
98         PKG_SEARCH_MODULE( LIBSOUP22 libsoup-2.2 libsoup2 )
99 ENDIF ( NOT LIBSOUP22_FOUND AND NOT LIBSOUP24_MIN_VERSION)
100
101 # set LIBSOUP2_ variables
102 IF ( LIBSOUP24_FOUND )
103         # prefer libsoup2.4 to libsoup2.2 if both are found
104         SET( LIBSOUP2_FOUND ${LIBSOUP24_FOUND} CACHE INTERNAL "" )
105         SET( LIBSOUP2_INCLUDE_DIRS ${LIBSOUP24_INCLUDE_DIRS} CACHE INTERNAL "" )
106         SET( LIBSOUP2_LIBRARIES ${LIBSOUP24_LIBRARIES} CACHE INTERNAL "" )
107         SET( LIBSOUP2_LIBRARY_DIRS ${LIBSOUP24_LIBRARY_DIRS} CACHE INTERNAL "" )
108         SET( LIBSOUP2_VERSION ${LIBSOUP24_VERSION} CACHE INTERNAL "" )
109 ELSEIF ( LIBSOUP22_FOUND )
110         SET( LIBSOUP2_FOUND ${LIBSOUP22_FOUND} CACHE INTERNAL "" )
111         SET( LIBSOUP2_INCLUDE_DIRS ${LIBSOUP22_INCLUDE_DIRS} CACHE INTERNAL "" )
112         SET( LIBSOUP2_LIBRARIES ${LIBSOUP22_LIBRARIES} CACHE INTERNAL "" )
113         SET( LIBSOUP2_LIBRARY_DIRS ${LIBSOUP22_LIBRARY_DIRS} CACHE INTERNAL "" )
114         SET( LIBSOUP2_VERSION ${LIBSOUP22_VERSION} CACHE INTERNAL "" )
115 ELSEIF( PKG_CONFIG_FOUND AND LibSoup2_FIND_REQUIRED )
116         # raise an error if both libs are not found 
117         # and FIND_PACKAGE( LibSoup2 REQUIRED ) was called
118         MESSAGE( SEND_ERROR "package libsoup2 not found" )
119 ENDIF ( LIBSOUP24_FOUND )
120
121 IF( NOT LIBSOUP2_FOUND AND NOT PKG_CONFIG_FOUND )
122         # WARNING:
123         # This case is executed if pkg-config isn't installed.
124         # Currently in this case it is only checked if libsoup2.2 is available.
125         # Therefore please don't use this cmake module without pkg-config!
126         FIND_PATH( _libsoup2_include_DIR libsoup/soup.h PATH_SUFFIXES libsoup libsoup-2.2 )
127         FIND_LIBRARY( _libsoup2_LIBRARY soup-2.2)
128
129         IF ( _libsoup2_include_DIR AND _libsoup2_LIBRARY )
130                 SET ( _libsoup2_FOUND TRUE )
131         ENDIF ( _libsoup2_include_DIR AND _libsoup2_LIBRARY )
132
133         IF ( _libsoup2_FOUND )
134                 SET ( LIBSOUP2_INCLUDE_DIRS ${_libsoup2_include_DIR} )
135                 SET ( LIBSOUP2_LIBRARIES ${_libsoup2_LIBRARY} )
136         
137                 # find requited glib2
138                 IF( NOT GLIB2_FOUND )
139                         FIND_PACKAGE( GLIB2 REQUIRED )
140                         IF ( GLIB2_FOUND )
141                                 SET ( LIBSOUP2_INCLUDE_DIRS ${LIBSOUP2_INCLUDE_DIRS} ${GLIB2_INCLUDE_DIRS} )
142                                 SET ( LIBSOUP2_LIBRARIES ${LIBSOUP2_LIBRARIES} ${GLIB2_LIBRARIES} )
143                         ENDIF ( GLIB2_FOUND )
144                 ENDIF( NOT GLIB2_FOUND )
145                 
146                 # find required libxml2
147                 IF( NOT LIBXML2_FOUND )
148                         FIND_PACKAGE( LibXml2 REQUIRED )
149                         IF ( LIBXML2_FOUND )
150                                 SET ( LIBSOUP2_INCLUDE_DIRS ${LIBSOUP2_INCLUDE_DIRS} ${LIBXML2_INCLUDE_DIRS} )
151                                 SET ( LIBSOUP2_LIBRARIES ${LIBSOUP2_LIBRARIES} ${LIBXML2_LIBRARIES} )
152                         ENDIF( LIBXML2_FOUND )
153                 ENDIF( NOT LIBXML2_FOUND )
154                 
155                 # find required gnutls
156                 IF( NOT GNUTLS_FOUND )
157                         FIND_PACKAGE( GNUTLS REQUIRED )
158                         IF ( GNUTLS_FOUND )
159                                 SET ( LIBSOUP2_INCLUDE_DIRS ${LIBSOUP2_INCLUDE_DIRS} ${GNUTLS_INCLUDE_DIRS} )
160                                 SET ( LIBSOUP2_LIBRARIES ${LIBSOUP2_LIBRARIES} ${GNUTLS_LIBRARIES} )
161                         ENDIF( GNUTLS_FOUND )
162                 ENDIF( NOT GNUTLS_FOUND )
163         ENDIF ( _libsoup2_FOUND )
164
165         MARK_AS_ADVANCED( _libsoup2_include_DIR  _libsoup2_LIBRARY )
166
167         # Report results
168         IF ( LIBSOUP2_LIBRARIES AND LIBSOUP2_INCLUDE_DIRS AND _libsoup2_FOUND ) 
169                 SET( LIBSOUP2_FOUND 1 )
170                 IF ( NOT LibSoup2_FIND_QUIETLY )
171                         MESSAGE( STATUS "Found libsoup2: ${_libsoup2_LIBRARY}" )
172                 ENDIF ( NOT LibSoup2_FIND_QUIETLY )
173         ELSE ( LIBSOUP2_LIBRARIES AND LIBSOUP_INCLUDE_DIRS AND _libsoup2_FOUND )        
174                 IF ( LibSoup2_FIND_REQUIRED )
175                         MESSAGE( SEND_ERROR "Could NOT find libsoup2" )
176                 ELSE ( LibSoup2_FIND_REQUIRED )
177                         IF ( NOT LibSoup2_FIND_QUIETLY )
178                                 MESSAGE( STATUS "Could NOT find libsoup2" )     
179                         ENDIF ( NOT LibSoup2_FIND_QUIETLY )
180                 ENDIF ( LibSoup2_FIND_REQUIRED )
181         ENDIF ( LIBSOUP2_LIBRARIES AND LIBSOUP2_INCLUDE_DIRS AND _libsoup2_FOUND )
182 ENDIF( NOT LIBSOUP2_FOUND AND NOT PKG_CONFIG_FOUND )
183
184 # Hide advanced variables from CMake GUIs
185 MARK_AS_ADVANCED( LIBSOUP2_LIBRARIES LIBSOUP2_INCLUDE_DIRS )
186