pam_matrix: Add OpenPAM (BSD) support
[slow/pam_wrapper.git] / ConfigureChecks.cmake
1 include(CheckIncludeFile)
2 include(CheckSymbolExists)
3 include(CheckFunctionExists)
4 include(CheckLibraryExists)
5 include(CheckTypeSize)
6 include(CheckStructHasMember)
7 include(CheckPrototypeDefinition)
8 include(TestBigEndian)
9
10 set(PACKAGE ${APPLICATION_NAME})
11 set(VERSION ${APPLICATION_VERSION})
12 set(DATADIR ${DATA_INSTALL_DIR})
13 set(LIBDIR ${LIB_INSTALL_DIR})
14 set(PLUGINDIR "${PLUGIN_INSTALL_DIR}-${LIBRARY_SOVERSION}")
15 set(SYSCONFDIR ${SYSCONF_INSTALL_DIR})
16
17 set(BINARYDIR ${CMAKE_BINARY_DIR})
18 set(SOURCEDIR ${CMAKE_SOURCE_DIR})
19
20 function(COMPILER_DUMPVERSION _OUTPUT_VERSION)
21     # Remove whitespaces from the argument.
22     # This is needed for CC="ccache gcc" cmake ..
23     string(REPLACE " " "" _C_COMPILER_ARG "${CMAKE_C_COMPILER_ARG1}")
24
25     execute_process(
26         COMMAND
27             ${CMAKE_C_COMPILER} ${_C_COMPILER_ARG} -dumpversion
28         OUTPUT_VARIABLE _COMPILER_VERSION
29     )
30
31     string(REGEX REPLACE "([0-9])\\.([0-9])(\\.[0-9])?" "\\1\\2"
32            _COMPILER_VERSION "${_COMPILER_VERSION}")
33
34     set(${_OUTPUT_VERSION} ${_COMPILER_VERSION} PARENT_SCOPE)
35 endfunction()
36
37 # HEADERS
38 check_include_file(sys/types.h HAVE_SYS_TYPES_H)
39 check_include_file(unistd.h HAVE_UNISTD_H)
40 check_include_file(security/pam_appl.h HAVE_SECURITY_PAM_APPL_H)
41 check_include_file(security/pam_modules.h HAVE_SECURITY_PAM_MODULES_H)
42 check_include_file(security/pam_ext.h HAVE_SECURITY_PAM_EXT_H)
43
44 # FUNCTIONS
45 check_function_exists(strncpy HAVE_STRNCPY)
46 check_function_exists(vsnprintf HAVE_VSNPRINTF)
47 check_function_exists(snprintf HAVE_SNPRINTF)
48
49 set(CMAKE_REQUIRED_LIBRARIES pam)
50 check_function_exists(pam_vsyslog HAVE_PAM_VSYSLOG)
51 check_function_exists(pam_syslog HAVE_PAM_SYSLOG)
52 set(CMAKE_REQUIRED_LIBRARIES)
53
54 check_prototype_definition(pam_vprompt
55     "int pam_vprompt(const pam_handle_t *_pamh, int _style, char **_resp, const char *_fmt, va_list _ap)"
56     "-1"
57     "stdio.h;sys/types.h;security/pam_appl.h;security/pam_modules.h"
58     HAVE_PAM_VPROMPT_CONST)
59
60 check_prototype_definition(pam_prompt
61     "int pam_prompt(const pam_handle_t *_pamh, int _style, char **_resp, const char *_fmt, ...)"
62     "-1"
63     "stdio.h;sys/types.h;security/pam_appl.h;security/pam_modules.h"
64     HAVE_PAM_PROMPT_CONST)
65
66 check_prototype_definition(pam_strerror
67     "const char *pam_strerror(const pam_handle_t *_pamh, int _error_number)"
68     "NULL"
69     "stdio.h;sys/types.h;security/pam_appl.h;security/pam_modules.h"
70     HAVE_PAM_STRERROR_CONST)
71
72 # LIBRARIES
73 find_library(PAM_LIBRARY NAMES libpam.so.0 pam)
74 set(PAM_LIBRARY ${PAM_LIBRARY})
75 find_library(PAM_MISC_LIBRARY NAMES pam_misc)
76 if (PAM_MISC_LIBRARY)
77         set(HAVE_PAM_MISC TRUE)
78 endif()
79
80 check_library_exists(${PAM_LIBRARY} openpam_set_option "" HAVE_OPENPAM)
81
82 # PAM FUNCTIONS
83 set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${PAM_LIBRARY})
84 check_function_exists(pam_syslog HAVE_PAM_SYSLOG)
85 check_function_exists(pam_vsyslog HAVE_PAM_VSYSLOG)
86
87 # OPTIONS
88
89 if (LINUX)
90     if (HAVE_SYS_SYSCALL_H)
91        list(APPEND CMAKE_REQUIRED_DEFINITIONS "-DHAVE_SYS_SYSCALL_H")
92     endif (HAVE_SYS_SYSCALL_H)
93     if (HAVE_SYSCALL_H)
94         list(APPEND CMAKE_REQUIRED_DEFINITIONS "-DHAVE_SYSCALL_H")
95     endif (HAVE_SYSCALL_H)
96
97     set(CMAKE_REQUIRED_DEFINITIONS)
98 endif (LINUX)
99
100 # COMPAT
101 if (HAVE_OPENPAM_H)
102     set(HAVE_OPENPAM    1)
103 endif ()
104
105 check_c_source_compiles("
106 #include <stdbool.h>
107 int main(void) {
108     bool x;
109     bool *p_x = &x;
110     __atomic_load(p_x, &x, __ATOMIC_RELAXED);
111     return 0;
112 }" HAVE_GCC_ATOMIC_BUILTINS)
113
114 check_c_source_compiles("
115 __thread int tls;
116
117 int main(void) {
118     return 0;
119 }" HAVE_GCC_THREAD_LOCAL_STORAGE)
120
121 check_c_source_compiles("
122 void test_constructor_attribute(void) __attribute__ ((constructor));
123
124 void test_constructor_attribute(void)
125 {
126      return;
127 }
128
129 int main(void) {
130      return 0;
131 }" HAVE_CONSTRUCTOR_ATTRIBUTE)
132
133 check_c_source_compiles("
134 void test_destructor_attribute(void) __attribute__ ((destructor));
135
136 void test_destructor_attribute(void)
137 {
138     return;
139 }
140
141 int main(void) {
142     return 0;
143 }" HAVE_DESTRUCTOR_ATTRIBUTE)
144
145 check_c_source_compiles("
146 void log_fn(const char *format, ...) __attribute__ ((format (printf, 1, 2)));
147
148 int main(void) {
149     return 0;
150 }" HAVE_FUNCTION_ATTRIBUTE_FORMAT)
151
152 # SYSTEM LIBRARIES
153
154 check_library_exists(dl dlopen "" HAVE_LIBDL)
155 if (HAVE_LIBDL)
156     find_library(DLFCN_LIBRARY dl)
157     set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${DLFCN_LIBRARY})
158 endif (HAVE_LIBDL)
159
160 if (OSX)
161     set(HAVE_APPLE 1)
162 endif (OSX)
163
164 # ENDIAN
165 if (NOT WIN32)
166     test_big_endian(WORDS_BIGENDIAN)
167 endif (NOT WIN32)
168
169 set(UIDWRAP_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} CACHE INTERNAL "uidwrap required system libraries")