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