File: ConfigureChecks.cmake

package info (click to toggle)
kleopatra 4:18.08.3-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 21,544 kB
  • sloc: cpp: 51,822; ansic: 382; xml: 119; sh: 51; makefile: 8
file content (182 lines) | stat: -rw-r--r-- 5,933 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# assuan configure checks
include(CheckFunctionExists)

if ( ASSUAN2_FOUND )
  set ( ASSUAN_SUFFIX "2" )
else ( ASSUAN2_FOUND )
  # TODO Clean this up with assuan 2 as hard dependency.
  message(FATAL_ERROR "At least version 2 of libassuan is required for Kleopatra.")
endif ( ASSUAN2_FOUND )

set( USABLE_ASSUAN_FOUND false )

if ( ASSUAN${ASSUAN_SUFFIX}_FOUND )

  set( CMAKE_REQUIRED_INCLUDES ${ASSUAN${ASSUAN_SUFFIX}_INCLUDES} )

  if ( ASSUAN2_FOUND )
    set( CMAKE_REQUIRED_LIBRARIES ${ASSUAN2_LIBRARIES} )
    set( USABLE_ASSUAN_FOUND true )
  elseif ( WIN32 AND ASSUAN_VANILLA_FOUND )
    set( CMAKE_REQUIRED_LIBRARIES ${ASSUAN_VANILLA_LIBRARIES} )
    set( USABLE_ASSUAN_FOUND true )
  elseif( NOT WIN32 AND ASSUAN_PTHREAD_FOUND )
    set( CMAKE_REQUIRED_LIBRARIES ${ASSUAN_PTHREAD_LIBRARIES} )
    set( USABLE_ASSUAN_FOUND true )
  endif( ASSUAN2_FOUND )

  # TODO: this workaround will be removed as soon as we find better solution
  if(MINGW)
    set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES} ${KDEWIN32_INCLUDE_DIR}/mingw)
  elseif(MSVC)
    set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES} ${KDEWIN32_INCLUDE_DIR}/msvc)
  endif(MINGW)

endif( ASSUAN${ASSUAN_SUFFIX}_FOUND )

if ( USABLE_ASSUAN_FOUND )
  # check if assuan.h can be compiled standalone (it couldn't, on
  # Windows, until recently, because of a HAVE_W32_SYSTEM #ifdef in
  # there)
  check_cxx_source_compiles( "
       #include <assuan.h>
       int main() {
           return 1;
       }
       "
       USABLE_ASSUAN_FOUND )
endif( USABLE_ASSUAN_FOUND )

if ( USABLE_ASSUAN_FOUND )

  # check whether assuan and gpgme may be linked to simultaneously
  check_function_exists( "assuan_get_pointer" USABLE_ASSUAN_FOUND )

endif( USABLE_ASSUAN_FOUND )

if ( USABLE_ASSUAN_FOUND AND NOT ASSUAN2_FOUND )

  # check if assuan has assuan_fd_t
  check_cxx_source_compiles("
        #include <assuan.h>
        int main() {
            assuan_fd_t fd = ASSUAN_INVALID_FD;
            return fd ? 1 : 0 ;
        }
        "
    HAVE_ASSUAN_FD_T )

  if ( WIN32 AND NOT HAVE_ASSUAN_FD_T )
    set( USABLE_ASSUAN_FOUND false )
  endif ( WIN32 AND NOT HAVE_ASSUAN_FD_T )

  # check if assuan has assuan_inquire_ext, old style
  check_function_exists( "assuan_inquire_ext" HAVE_ASSUAN_INQUIRE_EXT )

  if ( NOT HAVE_ASSUAN_INQUIRE_EXT )
    set( USABLE_ASSUAN_FOUND false )
  endif( NOT HAVE_ASSUAN_INQUIRE_EXT )

  # check if assuan has new-style assuan_inquire_ext:
  check_cxx_source_compiles("
        #include <assuan.h>
        static int handler( void *, int, unsigned char*, size_t ) { return 0; }
        int main() {
            assuan_context_t ctx = 0;
            const size_t maxSize = 0U;
            assuan_error_t err = assuan_inquire_ext( ctx, \"FOO\", maxSize, handler, (void*)0 );
            return err ? 1 : 0 ;
        }
        "
    HAVE_NEW_STYLE_ASSUAN_INQUIRE_EXT )

endif( USABLE_ASSUAN_FOUND AND NOT ASSUAN2_FOUND )

if ( USABLE_ASSUAN_FOUND )

  # check if gpg-error already has GPG_ERR_SOURCE_KLEO
  check_cxx_source_compiles("
        #include <gpg-error.h>
        static gpg_err_source_t src = GPG_ERR_SOURCE_KLEO;
        int main() { return 0; }
        "
    HAVE_GPG_ERR_SOURCE_KLEO )

endif ( USABLE_ASSUAN_FOUND )

if ( USABLE_ASSUAN_FOUND AND NOT ASSUAN2_FOUND )

  # check if assuan has assuan_sock_get_nonce (via assuan_sock_nonce_t)
  # function_exists runs into linking errors - libassuan is static,
  # and assuan_sock_get_nonce drags in stuff that needs linking
  # against winsock2.
  check_cxx_source_compiles("
        #include <assuan.h>
        static assuan_sock_nonce_t nonce;
        int main() { return 0; }
        "
    HAVE_ASSUAN_SOCK_GET_NONCE )

  if ( WIN32 AND NOT HAVE_ASSUAN_SOCK_GET_NONCE )
    set( USABLE_ASSUAN_FOUND false )
  endif ( WIN32 AND NOT HAVE_ASSUAN_SOCK_GET_NONCE )  

endif ( USABLE_ASSUAN_FOUND AND NOT ASSUAN2_FOUND )

if ( USABLE_ASSUAN_FOUND )
  message( STATUS "Usable assuan found for Kleopatra" )
else ( USABLE_ASSUAN_FOUND )
  message( STATUS "NO usable assuan found for Kleopatra" )
endif ( USABLE_ASSUAN_FOUND )

if ( NOT ASSUAN2_FOUND )

#
# Check that libassuan (which is built statically) can be linked into a DSO
# (e.g. on amd64, this requires it to be compiled with -fPIC).
#

set ( ASSUAN_LINKABLE_TO_DSO false )

endif ( NOT ASSUAN2_FOUND )

OPTION( BUILD_libkleopatraclient "Build directory kleopatra/libkleopatraclient" ${USABLE_ASSUAN_FOUND} )

if ( NOT USABLE_ASSUAN_FOUND )
  set( BUILD_libkleopatraclient false )
endif ( NOT USABLE_ASSUAN_FOUND )

if ( BUILD_libkleopatraclient AND NOT ASSUAN2_FOUND )

  message( STATUS "Checking whether libassuan can be linked against from DSO's" )

  set ( YUP TRUE )
  if ( YUP )
    set ( ASSUAN_LINKABLE_TO_DSO true )
    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." )
  else ( YUP )
  # TODO: make this one executed at configure time, so the check below works:
  add_library( dso_with_assuan_check SHARED ${CMAKE_SOURCE_DIR}/kleopatra/dso_with_assuan_check.c )

  set( CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} dso_with_assuan_check )
  check_cxx_source_compiles( "int main() { return 0; }" ASSUAN_LINKABLE_TO_DSO )

  if ( ASSUAN_LINKABLE_TO_DSO )
    message( STATUS "Usable assuan found for libkleopatraclient" )
  else ( ASSUAN_LINKABLE_TO_DSO )
    message( STATUS "NO usable assuan found for libkleopatraclient - if this is AMD64, check that libassuan is compiled with -fPIC" )
  endif ( ASSUAN_LINKABLE_TO_DSO )
  endif ( YUP )

endif ( BUILD_libkleopatraclient AND NOT ASSUAN2_FOUND )

if (USABLE_ASSUAN_FOUND)
  set (HAVE_USABLE_ASSUAN 1)
  set (HAVE_KLEOPATRACLIENT_LIBRARY 1)
else()
  set (HAVE_USABLE_ASSUAN 0)
  set (HAVE_KLEOPATRACLIENT_LIBRARY 0)
endif()

set(CMAKE_REQUIRED_INCLUDES)
set(CMAKE_REQUIRED_LIBRARIES)