debian: fix build-deps for focal
[amule.git] / cmake / glib21.cmake
blob7a5e3d014c6ef2461891477bdfe1956eb04dce0e
1 include (CheckFunctionExists)
2 include (CheckIncludeFile)
3 include (CheckIncludeFileCXX)
5 if (BUILD_MONOLITHIC OR BUILD_DAEMON)
6         check_function_exists (fallocate HAVE_FALLOCATE)
7         check_function_exists (getrlimit HAVE_GETRLIMIT)
8         check_function_exists (setrlimit HAVE_SETRLIMIT)
9         check_include_file (fcntl.h HAVE_FCNTL_H)
10         check_include_file (sys/resource.h HAVE_SYS_RESOURCE_H)
11         check_include_file (sys/statvfs.h HAVE_SYS_STATVFS_H)
13         set (TEST_APP "#include <features.h>
14                 #ifdef __GNU_LIBRARY__
15                         #if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 1) || (__GLIBC__ > 2)
16                                 Lucky GNU user
17                         #endif
18                 #endif"
19         )
21         execute_process (COMMAND echo ${TEST_APP}
22                 COMMAND ${CMAKE_C_COMPILER} -E -xc -
23                 OUTPUT_VARIABLE GLIB_TEST_OUTPUT
24         )
26         string (REGEX MATCH "Lucky GNU user" MATCH "${GLIB_TEST_OUTPUT}")
28         if (${MATCH})
29                 set (__GLIBC__ TRUE)
30                 message (STATUS "glibc -- found")
31         endif()
33         check_function_exists (posix_fallocate HAVE_POSIX_FALLOCATE)
34 endif()
36 if (BUILD_DAEMON)
37         check_include_file (sys/select.h HAVE_SYS_SELECT_H)
38         check_include_file (sys/time.h HAVE_SYS_TIME_H)
39         check_include_file (sys/wait.h HAVE_SYS_WAIT_H)
40         check_include_file (unistd.h HAVE_UNISTD_H)
41 endif()
43 if (BUILD_DAEMON OR BUILD_WEBSERVER)
44         check_include_file (sys/types.h HAVE_SYS_TYPES_H)
45 endif()
47 if (BUILD_DAEMON OR BUILD_WEBSERVER OR NEED_LIB_MULECOMMON)
48         include (CheckTypeSize) #Sets also HAVE_SYS_TYPES_H, HAVE_STDINT_H, and HAVE_STDDEF_H
49         check_type_size (int INTSIZE)
50 endif()
52 if (NEED_LIB_MULEAPPCORE)
53         check_include_file (errno.h HAVE_ERRNO_H)
54         check_include_file (float.h HAVE_FLOAT_H)
55         check_include_file (signal.h HAVE_SIGNAL_H)
56         check_include_file (stdarg.h HAVE_STDARG_H)
57         check_include_file (stdlib.h HAVE_STDLIB_H)
58         check_include_file (string.h HAVE_STRING_H)
60         if (HAVE_STDLIB_H)
61                 set (CMAKE_REQUIRED_INCLUDES stdlib.h)
62                 check_function_exists (free HAVE_FREE)
63                 unset (CMAKE_REQUIRED_INCLUDES)
64         endif()
66         if (HAVE_FREE AND HAVE_FLOAT_H AND HAVE_STDARG_H AND HAVE_STRING_H)
67                 set (STDC_HEADERS TRUE)
68         endif()
70         if (ENABLE_MMAP)
71                 check_include_file (sys/mman.h HAVE_SYS_MMAN_H)
73                 if (HAVE_SYS_MMAN_H)
74                         check_function_exists (munmap HAVE_MUNMAP)
76                         if (HAVE_MUNMAP)
77                                 check_function_exists (sysconf HAVE_SYSCONF)
79                                 if (HAVE_SYSCONF AND STDC_HEADERS)
80                                         try_run (PS_RUN_RESULT PS_COMPILE_RESULT
81                                                 ${CMAKE_BINARY_DIR}
82                                                 ${amule_SOURCE_DIR}/cmake/mmap-test.cpp
83                                                 RUN_OUTPUT_VARIABLE PS_OUTPUT
84                                         )
86                                         if (PS_RUN_RESULT EQUAL 0)
87                                                 message (STATUS "_SC_PAGESIZE found")
88                                                 set (HAVE__SC_PAGESIZE TRUE)
89                                         else()
90                                                 message (STATUS "_SC_PAGESIZE not defined, mmap support is disabled")
91                                         endif()
92                                 else()
93                                         message (STATUS "sysconf function not found, mmap support is disabled")
94                                 endif()
95                         else()
96                                 message (STATUS "munmap function not found, mmap support is disabled")
97                         endif()
98                 else()
99                         message (STATUS "sys/mman.h wasn't found, mmap support is disabled")
100                 endif()
101         endif()
102 endif()
104 if (NEED_LIB_MULECOMMON)
105         check_include_file_cxx (cxxabi.h HAVE_CXXABI)
106         check_include_file (execinfo.h HAVE_EXECINFO)
107         check_include_file (inttypes.h HAVE_INTTYPES_H)
109         if (HAVE_INTTYPES_H AND HAVE_SYS_TYPES_H)
110                 set (TEST_APP "#include <sys/types.h>
111                         #include <inttypes.h>"
112                 )
114                 EXECUTE_PROCESS (COMMAND echo ${TEST_APP}
115                         COMMAND ${CMAKE_C_COMPILER} -c -xc -
116                         ERROR_VARIABLE INTTYPES_SYSTYPES_TEST_ERRORS
117                 )
119                 if (INTTYPES_SYSTYPES_TEST_ERRORS)
120                         set (HAVE_INTTYPES_H FALSE)
121                 else()
122                         set (TEST_APP "#include <sys/types.h>
123                                 #include <inttypes.h>
124                                 uintmax_t i = (uintmax_t) -1\;"
125                         )
127                         EXECUTE_PROCESS (COMMAND echo ${TEST_APP}
128                                 COMMAND ${CMAKE_C_COMPILER} -c -xc -
129                                 ERROR_VARIABLE INTTYPES_SYSTYPES_UINTMAX_TEST_ERRORS
130                         )
132                         if (NOT INTTYPES_SYSTYPES_UINTMAX_TEST_ERRORS)
133                                 set (HAVE_INTTYPES_H_WITH_UINTMAX TRUE)
134                         endif()
135                 endif()
136         endif()
138         if (HAVE_INTTYPES_H)
139                 set (TEST_APP "#include <inttypes.h>
140                         #ifdef PRId32
141                         char *p = PRId32\;
142                         #endif"
143                 )
145                 EXECUTE_PROCESS (COMMAND echo ${TEST_APP}
146                         COMMAND ${CMAKE_C_COMPILER} -c -xc -
147                         ERROR_VARIABLE INTTYPES_BROKEN_PRI_TEST_ERRORS
148                 )
150                 if (INTTYPES_BROKEN_PRI_TEST_ERRORS)
151                         set (PRI_MACROS_BROKEN TRUE)
152                 endif()
153         endif()
155         check_function_exists (strerror_r HAVE_STRERROR_R)
157         if (HAVE_STRERROR_R)
158                 set (TEST_APP "int main ()
159                         {
160                                 char buf[100]\;
161                                 char x = *strerror_r (0, buf, sizeof buf)\;
162                         }"
163                 )
165                 EXECUTE_PROCESS (COMMAND echo ${TEST_APP}
166                         COMMAND ${CMAKE_C_COMPILER} -E -xc -
167                         OUTPUT_VARIABLE STR_ERROR_CHAR_P_OUTPUT
168                         ERROR_VARIABLE STR_ERROR_CHAR_P_TEST
169                 )
171                 if (STR_ERROR_CHAR_P_TEST)
172                         set (STRERROR_R_CHAR_P TRUE)
173                         message (STATUS "strerror_r returns char*")
174                 endif()
175         endif()
176 endif()