1 # - Try to find libsoup
2 # Find libsoup headers, libraries and the answer to all questions.
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
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
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
19 # Set LIBSOUP2_MIN_VERSION to find libsoup2.2 or libsoup2.4 if only
20 # one of both libraries is supported
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.
26 # Set LIBSPOUP22_MIN_VERSION to find libsoup2.2 which version is
27 # greater than LIBSPOUP22_MIN_VERSION
29 # Set LIBSPOUP24_MIN_VERSION to find libsoup2.4 which version is
30 # greater than LIBSPOUP24_MIN_VERSION
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.
37 # Copyright (c) 2007 Daniel Gollub <gollub@b1-systems.de>
38 # Copyright (c) 2008 Bjoern Ricks <bjoern.ricks@gmail.com>
40 # Redistribution and use in source and binary forms, with or without
41 # modification, are permitted provided that the following conditions
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.
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.
64 INCLUDE( FindPkgConfig )
66 IF ( LibSoup2_FIND_VERSION AND NOT LIBSOUP2_MIN_VERSION AND NOT LIBSOUP24_MIN_VERSION )
67 SET( LIBSOUP2_MIN_VERSION "${LibSoup2_FIND_VERSION}" )
68 SET( LIBSOUP24_MIN_VERSION "${LibSoup2_FIND_VERSION}" )
69 ENDIF ( LibSoup2_FIND_VERSION AND NOT LIBSOUP2_MIN_VERSION AND NOT LIBSOUP24_MIN_VERSION )
71 IF ( LibSoup2_FIND_REQUIRED )
72 SET( _pkgconfig_REQUIRED "REQUIRED" )
73 ELSE( LibSoup2_FIND_REQUIRED )
74 SET( _pkgconfig_REQUIRED "" )
75 ENDIF ( LibSoup2_FIND_REQUIRED )
77 IF ( LIBSOUP2_MIN_VERSION )
78 STRING(REGEX REPLACE "^(2)(\\.)([0-9]*)(\\.?)(.*)" "\\3" LIBSOUP2_VERSION_MINOR "${LIBSOUP2_MIN_VERSION}")
79 IF ( LIBSOUP2_VERSION_MINOR EQUAL "2" )
80 SET( LIBSOUP22_MIN_VERSION "${LIBSOUP2_MIN_VERSION}" )
81 ELSE ( LIBSOUP2_VERSION_MINOR EQUAL "2" )
82 SET( LIBSOUP24_MIN_VERSION "${LIBSOUP2_MIN_VERSION}" )
83 ENDIF ( LIBSOUP2_VERSION_MINOR EQUAL "2" )
84 ENDIF ( LIBSOUP2_MIN_VERSION )
86 # try to find libsoup2.2>=LIBSOUP22_MIN_VERSION
87 IF ( LIBSOUP22_MIN_VERSION )
88 PKG_SEARCH_MODULE( LIBSOUP22 libsoup-2.2>=${LIBSOUP22_MIN_VERSION} libsoup2>=${LIBSOUP22_MIN_VERSION} )
89 ENDIF ( LIBSOUP22_MIN_VERSION )
91 # try to find libsoup2.4>=LIBSOUP24_MIN_VERSION
92 IF ( LIBSOUP24_MIN_VERSION )
93 PKG_SEARCH_MODULE( LIBSOUP24 libsoup-2.4>=${LIBSOUP24_MIN_VERSION} libsoup2>=${LIBSOUP24_MIN_VERSION} )
94 ENDIF ( LIBSOUP24_MIN_VERSION )
96 # try to find any version of libsoup2.4 if LIBSOUP22_MIN_VERSION is not set
97 IF ( NOT LIBSOUP24_FOUND AND NOT LIBSOUP22_MIN_VERSION AND NOT LIBSOUP24_MIN_VERSION )
98 PKG_SEARCH_MODULE( LIBSOUP24 libsoup-2.4 libsoup2 )
99 ENDIF ( NOT LIBSOUP24_FOUND AND NOT LIBSOUP22_MIN_VERSION AND NOT LIBSOUP24_MIN_VERSION )
101 # try to find any version of libsoup2.2 if LIBSOUP24_MIN_VERSION is not set
102 IF ( NOT LIBSOUP22_FOUND AND NOT LIBSOUP24_MIN_VERSION AND NOT LIBSOUP24_MIN_VERSION )
103 PKG_SEARCH_MODULE( LIBSOUP22 libsoup-2.2 libsoup2 )
104 ENDIF ( NOT LIBSOUP22_FOUND AND NOT LIBSOUP24_MIN_VERSION AND NOT LIBSOUP24_MIN_VERSION )
106 # set LIBSOUP2_ variables
107 IF ( LIBSOUP24_FOUND )
108 # prefer libsoup2.4 to libsoup2.2 if both are found
109 SET( LIBSOUP2_FOUND ${LIBSOUP24_FOUND} CACHE INTERNAL "" )
110 SET( LIBSOUP2_INCLUDE_DIRS ${LIBSOUP24_INCLUDE_DIRS} CACHE INTERNAL "" )
111 SET( LIBSOUP2_LIBRARIES ${LIBSOUP24_LIBRARIES} CACHE INTERNAL "" )
112 SET( LIBSOUP2_LIBRARY_DIRS ${LIBSOUP24_LIBRARY_DIRS} CACHE INTERNAL "" )
113 SET( LIBSOUP2_VERSION ${LIBSOUP24_VERSION} CACHE INTERNAL "" )
114 ELSEIF ( LIBSOUP22_FOUND )
115 SET( LIBSOUP2_FOUND ${LIBSOUP22_FOUND} CACHE INTERNAL "" )
116 SET( LIBSOUP2_INCLUDE_DIRS ${LIBSOUP22_INCLUDE_DIRS} CACHE INTERNAL "" )
117 SET( LIBSOUP2_LIBRARIES ${LIBSOUP22_LIBRARIES} CACHE INTERNAL "" )
118 SET( LIBSOUP2_LIBRARY_DIRS ${LIBSOUP22_LIBRARY_DIRS} CACHE INTERNAL "" )
119 SET( LIBSOUP2_VERSION ${LIBSOUP22_VERSION} CACHE INTERNAL "" )
120 ELSEIF( PKG_CONFIG_FOUND AND LibSoup2_FIND_REQUIRED )
121 # raise an error if both libs are not found
122 # and FIND_PACKAGE( LibSoup2 REQUIRED ) was called
123 MESSAGE( FATAL_ERROR "package libsoup2 not found" )
124 ENDIF ( LIBSOUP24_FOUND )
126 IF( NOT LIBSOUP2_FOUND AND NOT PKG_CONFIG_FOUND )
128 # This case is executed if pkg-config isn't installed.
129 # Currently in this case it is only checked if libsoup2.2 is available.
130 # Therefore please don't use this cmake module without pkg-config!
131 FIND_PATH( _libsoup2_include_DIR libsoup/soup.h PATH_SUFFIXES libsoup libsoup-2.2 )
132 FIND_LIBRARY( _libsoup2_LIBRARY soup-2.2)
134 IF ( _libsoup2_include_DIR AND _libsoup2_LIBRARY )
135 SET ( _libsoup2_FOUND TRUE )
136 ENDIF ( _libsoup2_include_DIR AND _libsoup2_LIBRARY )
138 IF ( _libsoup2_FOUND )
139 SET ( LIBSOUP2_INCLUDE_DIRS ${_libsoup2_include_DIR} )
140 SET ( LIBSOUP2_LIBRARIES ${_libsoup2_LIBRARY} )
142 # find requited glib2
143 IF( NOT GLIB2_FOUND )
144 FIND_PACKAGE( GLIB2 REQUIRED )
146 SET ( LIBSOUP2_INCLUDE_DIRS ${LIBSOUP2_INCLUDE_DIRS} ${GLIB2_INCLUDE_DIRS} )
147 SET ( LIBSOUP2_LIBRARIES ${LIBSOUP2_LIBRARIES} ${GLIB2_LIBRARIES} )
148 ENDIF ( GLIB2_FOUND )
149 ENDIF( NOT GLIB2_FOUND )
151 # find required libxml2
152 IF( NOT LIBXML2_FOUND )
153 FIND_PACKAGE( LibXml2 REQUIRED )
155 SET ( LIBSOUP2_INCLUDE_DIRS ${LIBSOUP2_INCLUDE_DIRS} ${LIBXML2_INCLUDE_DIRS} )
156 SET ( LIBSOUP2_LIBRARIES ${LIBSOUP2_LIBRARIES} ${LIBXML2_LIBRARIES} )
157 ENDIF( LIBXML2_FOUND )
158 ENDIF( NOT LIBXML2_FOUND )
160 # find required gnutls
161 IF( NOT GNUTLS_FOUND )
162 FIND_PACKAGE( GNUTLS REQUIRED )
164 SET ( LIBSOUP2_INCLUDE_DIRS ${LIBSOUP2_INCLUDE_DIRS} ${GNUTLS_INCLUDE_DIRS} )
165 SET ( LIBSOUP2_LIBRARIES ${LIBSOUP2_LIBRARIES} ${GNUTLS_LIBRARIES} )
166 ENDIF( GNUTLS_FOUND )
167 ENDIF( NOT GNUTLS_FOUND )
168 ENDIF ( _libsoup2_FOUND )
170 MARK_AS_ADVANCED( _libsoup2_include_DIR _libsoup2_LIBRARY )
173 IF ( LIBSOUP2_LIBRARIES AND LIBSOUP2_INCLUDE_DIRS AND _libsoup2_FOUND )
174 SET( LIBSOUP2_FOUND 1 )
175 IF ( NOT LibSoup2_FIND_QUIETLY )
176 MESSAGE( STATUS "Found libsoup2: ${_libsoup2_LIBRARY}" )
177 ENDIF ( NOT LibSoup2_FIND_QUIETLY )
178 ELSE ( LIBSOUP2_LIBRARIES AND LIBSOUP_INCLUDE_DIRS AND _libsoup2_FOUND )
179 IF ( LibSoup2_FIND_REQUIRED )
180 MESSAGE( SEND_ERROR "Could NOT find libsoup2" )
181 ELSE ( LibSoup2_FIND_REQUIRED )
182 IF ( NOT LibSoup2_FIND_QUIETLY )
183 MESSAGE( STATUS "Could NOT find libsoup2" )
184 ENDIF ( NOT LibSoup2_FIND_QUIETLY )
185 ENDIF ( LibSoup2_FIND_REQUIRED )
186 ENDIF ( LIBSOUP2_LIBRARIES AND LIBSOUP2_INCLUDE_DIRS AND _libsoup2_FOUND )
187 ENDIF( NOT LIBSOUP2_FOUND AND NOT PKG_CONFIG_FOUND )
189 # Hide advanced variables from CMake GUIs
190 MARK_AS_ADVANCED( LIBSOUP2_LIBRARIES LIBSOUP2_INCLUDE_DIRS )