not quite so much needs to be delayed to the init() function
[personal-kdebase.git] / workspace / cmake / modules / FindPAM.cmake
blob349983651a586ce50f6948091b39fc54ae98859f
1 # - Try to find the PAM libraries
2 # Once done this will define
4 #  PAM_FOUND - system has pam
5 #  PAM_INCLUDE_DIR - the pam include directory
6 #  PAM_LIBRARIES - libpam library
8 if (PAM_INCLUDE_DIR AND PAM_LIBRARY)
9         # Already in cache, be silent
10         set(PAM_FIND_QUIETLY TRUE)
11 endif (PAM_INCLUDE_DIR AND PAM_LIBRARY)
13 find_path(PAM_INCLUDE_DIR NAMES security/pam_appl.h pam/pam_appl.h)
14 find_library(PAM_LIBRARY pam)
15 find_library(DL_LIBRARY dl)
17 if (PAM_INCLUDE_DIR AND PAM_LIBRARY)
18         set(PAM_FOUND TRUE)
19         if (DL_LIBRARY)
20                 set(PAM_LIBRARIES ${PAM_LIBRARY} ${DL_LIBRARY})
21         else (DL_LIBRARY)
22                 set(PAM_LIBRARIES ${PAM_LIBRARY})
23         endif (DL_LIBRARY)
25         if (EXISTS ${PAM_INCLUDE_DIR}/pam/pam_appl.h)
26                 # darwin claims to be something special
27                 set(HAVE_PAM_PAM_APPL_H 1)
28         endif (EXISTS ${PAM_INCLUDE_DIR}/pam/pam_appl.h)
30         if (NOT DEFINED PAM_MESSAGE_CONST)
31                 include(CheckCXXSourceCompiles)
32                 # XXX does this work with plain c?
33                 check_cxx_source_compiles("
34 #if ${HAVE_PAM_PAM_APPL_H}+0
35 # include <pam/pam_appl.h>
36 #else
37 # include <security/pam_appl.h>
38 #endif
40 static int PAM_conv(
41         int num_msg,
42         const struct pam_message **msg, /* this is the culprit */
43         struct pam_response **resp,
44         void *ctx)
46         return 0;
49 int main(void)
51         struct pam_conv PAM_conversation = {
52                 &PAM_conv, /* this bombs out if the above does not match */
53                 0
54         };
56         return 0;
58 " PAM_MESSAGE_CONST)
59         endif (NOT DEFINED PAM_MESSAGE_CONST)
60         set(PAM_MESSAGE_CONST ${PAM_MESSAGE_CONST} CACHE BOOL "PAM expects a conversation function with const pam_message")
62 endif (PAM_INCLUDE_DIR AND PAM_LIBRARY)
64 if (PAM_FOUND)
65         if (NOT PAM_FIND_QUIETLY)
66                 message(STATUS "Found PAM: ${PAM_LIBRARIES}")
67         endif (NOT PAM_FIND_QUIETLY)
68 else (PAM_FOUND)
69         if (PAM_FIND_REQUIRED)
70                 message(FATAL_ERROR "PAM was not found")
71         endif(PAM_FIND_REQUIRED)
72 endif (PAM_FOUND)
74 mark_as_advanced(PAM_INCLUDE_DIR PAM_LIBRARY DL_LIBRARY PAM_MESSAGE_CONST)