Use find_library to find libpam.0
[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
42 # FUNCTIONS
43 check_function_exists(strncpy HAVE_STRNCPY)
44 check_function_exists(vsnprintf HAVE_VSNPRINTF)
45 check_function_exists(snprintf HAVE_SNPRINTF)
46
47 # FUNCTIONS
48 find_library(PAM_LIBRARY NAMES libpam.so.0 pam)
49 set(PAM_LIBRARY ${PAM_LIBRARY})
50
51 # OPTIONS
52
53 if (LINUX)
54     if (HAVE_SYS_SYSCALL_H)
55        list(APPEND CMAKE_REQUIRED_DEFINITIONS "-DHAVE_SYS_SYSCALL_H")
56     endif (HAVE_SYS_SYSCALL_H)
57     if (HAVE_SYSCALL_H)
58         list(APPEND CMAKE_REQUIRED_DEFINITIONS "-DHAVE_SYSCALL_H")
59     endif (HAVE_SYSCALL_H)
60
61     set(CMAKE_REQUIRED_DEFINITIONS)
62 endif (LINUX)
63
64 check_c_source_compiles("
65 #include <stdbool.h>
66 int main(void) {
67     bool x;
68     bool *p_x = &x;
69     __atomic_load(p_x, &x, __ATOMIC_RELAXED);
70     return 0;
71 }" HAVE_GCC_ATOMIC_BUILTINS)
72
73 check_c_source_compiles("
74 __thread int tls;
75
76 int main(void) {
77     return 0;
78 }" HAVE_GCC_THREAD_LOCAL_STORAGE)
79
80 check_c_source_compiles("
81 void test_constructor_attribute(void) __attribute__ ((constructor));
82
83 void test_constructor_attribute(void)
84 {
85      return;
86 }
87
88 int main(void) {
89      return 0;
90 }" HAVE_CONSTRUCTOR_ATTRIBUTE)
91
92 check_c_source_compiles("
93 void test_destructor_attribute(void) __attribute__ ((destructor));
94
95 void test_destructor_attribute(void)
96 {
97     return;
98 }
99
100 int main(void) {
101     return 0;
102 }" HAVE_DESTRUCTOR_ATTRIBUTE)
103
104 check_c_source_compiles("
105 void log_fn(const char *format, ...) __attribute__ ((format (printf, 1, 2)));
106
107 int main(void) {
108     return 0;
109 }" HAVE_FUNCTION_ATTRIBUTE_FORMAT)
110
111 # SYSTEM LIBRARIES
112
113 check_library_exists(dl dlopen "" HAVE_LIBDL)
114 if (HAVE_LIBDL)
115     find_library(DLFCN_LIBRARY dl)
116     set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${DLFCN_LIBRARY})
117 endif (HAVE_LIBDL)
118
119 if (OSX)
120     set(HAVE_APPLE 1)
121 endif (OSX)
122
123 # ENDIAN
124 if (NOT WIN32)
125     test_big_endian(WORDS_BIGENDIAN)
126 endif (NOT WIN32)
127
128 set(UIDWRAP_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} CACHE INTERNAL "uidwrap required system libraries")