FindPAM.cmake 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. # - Try to find the PAM libraries
  2. # Once done this will define
  3. #
  4. # PAM_FOUND - system has pam
  5. # PAM_INCLUDE_DIR - the pam include directory
  6. # PAM_LIBRARIES - libpam library
  7. if (PAM_INCLUDE_DIR AND PAM_LIBRARY)
  8. # Already in cache, be silent
  9. set(PAM_FIND_QUIETLY TRUE)
  10. endif (PAM_INCLUDE_DIR AND PAM_LIBRARY)
  11. find_path(PAM_INCLUDE_DIR NAMES security/pam_appl.h pam/pam_appl.h)
  12. find_library(PAM_LIBRARY pam)
  13. find_library(DL_LIBRARY dl)
  14. if (PAM_INCLUDE_DIR AND PAM_LIBRARY)
  15. set(PAM_FOUND TRUE)
  16. if (DL_LIBRARY)
  17. set(PAM_LIBRARIES ${PAM_LIBRARY} ${DL_LIBRARY})
  18. else (DL_LIBRARY)
  19. set(PAM_LIBRARIES ${PAM_LIBRARY})
  20. endif (DL_LIBRARY)
  21. if (EXISTS ${PAM_INCLUDE_DIR}/pam/pam_appl.h)
  22. # darwin claims to be something special
  23. set(HAVE_PAM_PAM_APPL_H 1)
  24. endif (EXISTS ${PAM_INCLUDE_DIR}/pam/pam_appl.h)
  25. if (NOT DEFINED PAM_MESSAGE_CONST)
  26. include(CheckCXXSourceCompiles)
  27. # XXX does this work with plain c?
  28. check_cxx_source_compiles("
  29. #if ${HAVE_PAM_PAM_APPL_H}+0
  30. # include <pam/pam_appl.h>
  31. #else
  32. # include <security/pam_appl.h>
  33. #endif
  34. static int PAM_conv(
  35. int num_msg,
  36. const struct pam_message **msg, /* this is the culprit */
  37. struct pam_response **resp,
  38. void *ctx)
  39. {
  40. return 0;
  41. }
  42. int main(void)
  43. {
  44. struct pam_conv PAM_conversation = {
  45. &PAM_conv, /* this bombs out if the above does not match */
  46. 0
  47. };
  48. return 0;
  49. }
  50. " PAM_MESSAGE_CONST)
  51. endif (NOT DEFINED PAM_MESSAGE_CONST)
  52. set(PAM_MESSAGE_CONST ${PAM_MESSAGE_CONST} CACHE BOOL "PAM expects a conversation function with const pam_message")
  53. endif (PAM_INCLUDE_DIR AND PAM_LIBRARY)
  54. if (PAM_FOUND)
  55. if (NOT PAM_FIND_QUIETLY)
  56. message(STATUS "Found PAM: ${PAM_LIBRARIES}")
  57. endif (NOT PAM_FIND_QUIETLY)
  58. else (PAM_FOUND)
  59. if (PAM_FIND_REQUIRED)
  60. message(FATAL_ERROR "PAM was not found")
  61. endif(PAM_FIND_REQUIRED)
  62. endif (PAM_FOUND)
  63. mark_as_advanced(PAM_INCLUDE_DIR PAM_LIBRARY DL_LIBRARY PAM_MESSAGE_CONST)