Fix includes
[kdepim.git] / kleopatra / ConfigureChecks.cmake
blob51cede554f1bb0b668580c6a98236ff84f3de1c7
1 # assuan configure checks
2 include(CheckFunctionExists)
4 find_package(Assuan2)
5 if ( ASSUAN2_FOUND )
6   set ( ASSUAN_SUFFIX "2" )
7 else ( ASSUAN2_FOUND )
8   find_package(Assuan)
9   set ( ASSUAN_SUFFIX )
10 endif ( ASSUAN2_FOUND )
12 set( USABLE_ASSUAN_FOUND false )
14 if ( ASSUAN${ASSUAN_SUFFIX}_FOUND )
16   set( CMAKE_REQUIRED_INCLUDES ${ASSUAN${ASSUAN_SUFFIX}_INCLUDES} )
18   if ( ASSUAN2_FOUND )
19     set( CMAKE_REQUIRED_LIBRARIES ${ASSUAN2_LIBRARIES} )
20     set( USABLE_ASSUAN_FOUND true )
21   elseif ( WIN32 AND ASSUAN_VANILLA_FOUND )
22     set( CMAKE_REQUIRED_LIBRARIES ${ASSUAN_VANILLA_LIBRARIES} )
23     set( USABLE_ASSUAN_FOUND true )
24   elseif( NOT WIN32 AND ASSUAN_PTHREAD_FOUND )
25     set( CMAKE_REQUIRED_LIBRARIES ${ASSUAN_PTHREAD_LIBRARIES} )
26     set( USABLE_ASSUAN_FOUND true )
27   endif( ASSUAN2_FOUND )
29   # TODO: this workaround will be removed as soon as we find better solution
30   if(MINGW)
31     set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES} ${KDEWIN32_INCLUDE_DIR}/mingw)
32   elseif(MSVC)
33     set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES} ${KDEWIN32_INCLUDE_DIR}/msvc)
34   endif(MINGW)
36 endif( ASSUAN${ASSUAN_SUFFIX}_FOUND )
38 if ( USABLE_ASSUAN_FOUND )
39   # check if assuan.h can be compiled standalone (it couldn't, on
40   # Windows, until recently, because of a HAVE_W32_SYSTEM #ifdef in
41   # there)
42   check_cxx_source_compiles( "
43        #include <assuan.h>
44        int main() {
45            return 1;
46        }
47        "
48        USABLE_ASSUAN_FOUND )
49 endif( USABLE_ASSUAN_FOUND )
51 if ( USABLE_ASSUAN_FOUND )
53   # check whether assuan and gpgme may be linked to simultaneously
54   check_function_exists( "assuan_get_pointer" USABLE_ASSUAN_FOUND )
56 endif( USABLE_ASSUAN_FOUND )
58 if ( USABLE_ASSUAN_FOUND AND NOT ASSUAN2_FOUND )
60   # check if assuan has assuan_fd_t
61   check_cxx_source_compiles("
62         #include <assuan.h>
63         int main() {
64             assuan_fd_t fd = ASSUAN_INVALID_FD;
65             return fd ? 1 : 0 ;
66         }
67         "
68     HAVE_ASSUAN_FD_T )
70   if ( WIN32 AND NOT HAVE_ASSUAN_FD_T )
71     set( USABLE_ASSUAN_FOUND false )
72   endif ( WIN32 AND NOT HAVE_ASSUAN_FD_T )
74   # check if assuan has assuan_inquire_ext, old style
75   check_function_exists( "assuan_inquire_ext" HAVE_ASSUAN_INQUIRE_EXT )
77   if ( NOT HAVE_ASSUAN_INQUIRE_EXT )
78     set( USABLE_ASSUAN_FOUND false )
79   endif( NOT HAVE_ASSUAN_INQUIRE_EXT )
81   # check if assuan has new-style assuan_inquire_ext:
82   check_cxx_source_compiles("
83         #include <assuan.h>
84         static int handler( void *, int, unsigned char*, size_t ) { return 0; }
85         int main() {
86             assuan_context_t ctx = 0;
87             const size_t maxSize = 0U;
88             assuan_error_t err = assuan_inquire_ext( ctx, \"FOO\", maxSize, handler, (void*)0 );
89             return err ? 1 : 0 ;
90         }
91         "
92     HAVE_NEW_STYLE_ASSUAN_INQUIRE_EXT )
94 endif( USABLE_ASSUAN_FOUND AND NOT ASSUAN2_FOUND )
96 if ( USABLE_ASSUAN_FOUND )
98   # check if gpg-error already has GPG_ERR_SOURCE_KLEO
99   check_cxx_source_compiles("
100         #include <gpg-error.h>
101         static gpg_err_source_t src = GPG_ERR_SOURCE_KLEO;
102         int main() { return 0; }
103         "
104     HAVE_GPG_ERR_SOURCE_KLEO )
106 endif ( USABLE_ASSUAN_FOUND )
108 if ( USABLE_ASSUAN_FOUND AND NOT ASSUAN2_FOUND )
110   # check if assuan has assuan_sock_get_nonce (via assuan_sock_nonce_t)
111   # function_exists runs into linking errors - libassuan is static,
112   # and assuan_sock_get_nonce drags in stuff that needs linking
113   # against winsock2.
114   check_cxx_source_compiles("
115         #include <assuan.h>
116         static assuan_sock_nonce_t nonce;
117         int main() { return 0; }
118         "
119     HAVE_ASSUAN_SOCK_GET_NONCE )
121   if ( WIN32 AND NOT HAVE_ASSUAN_SOCK_GET_NONCE )
122     set( USABLE_ASSUAN_FOUND false )
123   endif ( WIN32 AND NOT HAVE_ASSUAN_SOCK_GET_NONCE )  
125 endif ( USABLE_ASSUAN_FOUND AND NOT ASSUAN2_FOUND )
127 if ( USABLE_ASSUAN_FOUND )
128   message( STATUS "Usable assuan found for Kleopatra" )
129 else ( USABLE_ASSUAN_FOUND )
130   message( STATUS "NO usable assuan found for Kleopatra" )
131 endif ( USABLE_ASSUAN_FOUND )
133 if ( NOT ASSUAN2_FOUND )
136 # Check that libassuan (which is built statically) can be linked into a DSO
137 # (e.g. on amd64, this requires it to be compiled with -fPIC).
140 set ( ASSUAN_LINKABLE_TO_DSO false )
142 endif ( NOT ASSUAN2_FOUND )
144 OPTION( BUILD_libkleopatraclient "Build directory kleopatra/libkleopatraclient" ${USABLE_ASSUAN_FOUND} )
146 if ( NOT USABLE_ASSUAN_FOUND )
147   set( BUILD_libkleopatraclient false )
148 endif ( NOT USABLE_ASSUAN_FOUND )
150 if ( BUILD_libkleopatraclient AND NOT ASSUAN2_FOUND )
152   message( STATUS "Checking whether libassuan can be linked against from DSO's" )
154   set ( YUP TRUE )
155   if ( YUP )
156     set ( ASSUAN_LINKABLE_TO_DSO true )
157     message( STATUS "--> Assuming that it can. If compilation of libkleopatraclient fails on AMD64, check that libassuan is compiled with -fPIC and try again. Otherwise, pass -DBUILD_libkleopatraclient=OFF." )
158   else ( YUP )
159   # TODO: make this one executed at configure time, so the check below works:
160   add_library( dso_with_assuan_check SHARED ${CMAKE_SOURCE_DIR}/kleopatra/dso_with_assuan_check.c )
162   set( CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} dso_with_assuan_check )
163   check_cxx_source_compiles( "int main() { return 0; }" ASSUAN_LINKABLE_TO_DSO )
165   if ( ASSUAN_LINKABLE_TO_DSO )
166     message( STATUS "Usable assuan found for libkleopatraclient" )
167   else ( ASSUAN_LINKABLE_TO_DSO )
168     message( STATUS "NO usable assuan found for libkleopatraclient - if this is AMD64, check that libassuan is compiled with -fPIC" )
169   endif ( ASSUAN_LINKABLE_TO_DSO )
170   endif ( YUP )
172 endif ( BUILD_libkleopatraclient AND NOT ASSUAN2_FOUND )
174 macro_bool_to_01( USABLE_ASSUAN_FOUND  HAVE_USABLE_ASSUAN )
175 macro_bool_to_01( ASSUAN2_FOUND HAVE_ASSUAN2 )
176 if ( ASSUAN2_FOUND )
177 macro_bool_to_01( USABLE_ASSUAN_FOUND  HAVE_KLEOPATRACLIENT_LIBRARY )
178 else ( ASSUAN2_FOUND )
179 macro_bool_to_01( ASSUAN_LINKABLE_TO_DSO HAVE_KLEOPATRACLIENT_LIBRARY )
180 endif ( ASSUAN2_FOUND )
182 set(CMAKE_REQUIRED_INCLUDES)
183 set(CMAKE_REQUIRED_LIBRARIES)