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