fix tricky regression noticed by Vyacheslav Tokarev on Google Reader.
[kdelibs.git] / ConfigureChecks.cmake
blob0318597901b799d8a29ab3edf71f49f3342b6f5a
1 # NOTE: only add something here if it is really needed by all of kdelibs.
2 #     Otherwise please prefer adding to the relevant config-foo.h.cmake file,
3 #     and the CMakeLists.txt that generates it (or a separate ConfigureChecks.make file if you prefer)
4 #     to minimize recompilations and increase modularity.
6 include(CheckIncludeFile)
7 include(CheckIncludeFiles)
8 include(CheckSymbolExists)
9 include(CheckFunctionExists)
10 include(CheckLibraryExists)
11 include(CheckPrototypeExists)
12 include(CheckTypeSize)
13 include(CheckStructMember)
14 include(CheckCXXSourceCompiles)
16 # The FindKDE4.cmake module sets _KDE4_PLATFORM_DEFINITIONS with
17 # definitions like _GNU_SOURCE that are needed on each platform.
18 set(CMAKE_REQUIRED_DEFINITIONS ${_KDE4_PLATFORM_DEFINITIONS})
20 set( KDELIBSUFF ${LIB_SUFFIX} )
22 #check for libz using the cmake supplied FindZLIB.cmake
23 macro_bool_to_01(ZLIB_FOUND HAVE_LIBZ)                  # zlib is required
25 macro_bool_to_01(BZIP2_FOUND HAVE_BZIP2_SUPPORT)        # kdecore
26 if(BZIP2_FOUND AND BZIP2_NEED_PREFIX)
27    set(NEED_BZ2_PREFIX 1)
28 endif(BZIP2_FOUND AND BZIP2_NEED_PREFIX)
30 macro_bool_to_01(CARBON_FOUND HAVE_CARBON)              # kdecore
32 macro_bool_to_01(LIBINTL_FOUND ENABLE_NLS)              # kdecore, khtml, kjs
34 # FIXME: Make this changeable!
35 # khtml svg support
36 set(SVG_SUPPORT 1)              # unused yet, but for the future
38 # now check for dlfcn.h using the cmake supplied CHECK_INCLUDE_FILES() macro
39 # If definitions like -D_GNU_SOURCE are needed for these checks they
40 # should be added to _KDE4_PLATFORM_DEFINITIONS when it is originally
41 # defined outside this file.  Here we include these definitions in
42 # CMAKE_REQUIRED_DEFINITIONS so they will be included in the build of
43 # checks below.
44 set(CMAKE_REQUIRED_DEFINITIONS ${_KDE4_PLATFORM_DEFINITIONS})
46 check_include_files(stdio.h       HAVE_STDIO_H)                        # various
47 check_include_files(stdlib.h      HAVE_STDLIB_H)                       # various
48 check_include_files(string.h      HAVE_STRING_H)                       # various
49 check_include_files(strings.h     HAVE_STRINGS_H)                      # various
50 check_include_files(malloc.h      HAVE_MALLOC_H)                       # khtml
51 check_include_files(dlfcn.h       HAVE_DLFCN_H)                        # various
52 check_include_files(sys/time.h    TIME_WITH_SYS_TIME)                  # kdecore, kioslave
53 check_include_files(crt_externs.h HAVE_CRT_EXTERNS_H)                  # kinit, config.h
55 check_include_files(alloca.h      HAVE_ALLOCA_H)                       # kdecore, khtml
56 check_include_files(fstab.h       HAVE_FSTAB_H)                        # kio, kdecore
57 check_include_files(limits.h      HAVE_LIMITS_H)                       # various
58 check_include_files(mntent.h      HAVE_MNTENT_H)                       # solid, kio, kdecore
59 check_include_files(sysent.h      HAVE_SYSENT_H)                       # kdecore
60 check_include_files("sys/types.h;sys/mman.h" HAVE_SYS_MMAN_H)          # kdecore
61 check_include_files(sys/stat.h    HAVE_SYS_STAT_H)                     # various
62 check_include_files(sys/ucred.h   HAVE_SYS_UCRED_H)                    # kio
63 check_include_files(sys/types.h   HAVE_SYS_TYPES_H)                    # various
64 check_include_files(sys/select.h  HAVE_SYS_SELECT_H)                   # various
65 check_include_files(sys/param.h   HAVE_SYS_PARAM_H)                    # various
66 check_include_files("stdio.h;sys/mnttab.h"  HAVE_SYS_MNTTAB_H)         # kio, kdecore
67 check_include_files(sys/mntent.h  HAVE_SYS_MNTENT_H)                   # solid, kio, kdecore
68 check_include_files("sys/param.h;sys/mount.h"  HAVE_SYS_MOUNT_H)       # kio, kdecore
69 check_include_files(unistd.h      HAVE_UNISTD_H)                       # various
70 check_include_files(stdint.h      HAVE_STDINT_H)                       # various
71 check_include_files("sys/types.h;netinet/in.h"  HAVE_NETINET_IN_H)     # kio
72 check_include_files(paths.h       HAVE_PATHS_H)                        # kdecore, kio
74 check_include_files(errno.h       HAVE_ERRNO_H)                        # kjs, errno.h is used in many places, but only guarded in kjs/
75 check_include_files(sys/time.h    HAVE_SYS_TIME_H)                     # various
76 check_include_files(valgrind/memcheck.h   HAVE_VALGRIND_MEMCHECK_H)    # khtml
77 check_include_files(crtdbg.h      HAVE_CRTDBG_H)                       # kjs
78 check_include_files(langinfo.h    HAVE_LANGINFO_H)                     # kdecore
80 check_include_files(arpa/nameser8_compat.h HAVE_ARPA_NAMESER8_COMPAT_H) # kio
82 macro_bool_to_01(X11_XTest_FOUND HAVE_XTEST)                                                   # kdecore
83 macro_bool_to_01(X11_Xcursor_FOUND HAVE_XCURSOR)                                               # kdeui
84 macro_bool_to_01(X11_Xfixes_FOUND HAVE_XFIXES)                                                 # kdeui
85 macro_bool_to_01(X11_Xrender_FOUND HAVE_XRENDER)                                               # kio
88 # Use check_symbol_exists to check for symbols in a reliable
89 # cross-platform manner.  It accounts for different calling
90 # conventions and the possibility that the symbol is defined as a
91 # macro.  Note that some symbols require multiple includes in a
92 # specific order.  Refer to the man page for each symbol for which a
93 # check is to be added to get the proper set of headers.
94 check_symbol_exists(strcmp          "string.h"                 HAVE_STRCMP)      # libltdl
95 check_symbol_exists(strrchr         "string.h"                 HAVE_STRRCHR)     # libltdl
96 check_symbol_exists(strtoll         "stdlib.h"                 HAVE_STRTOLL)     # kioslave
97 check_symbol_exists(S_ISSOCK        "sys/stat.h"               HAVE_S_ISSOCK)    # config.h
98 check_symbol_exists(vsnprintf       "stdio.h"                  HAVE_VSNPRINTF)   # config.h
101 check_function_exists(posix_fadvise    HAVE_FADVISE)                  # kioslave
102 check_function_exists(backtrace        HAVE_BACKTRACE)                # kdecore, kio
103 check_function_exists(getpagesize      HAVE_GETPAGESIZE)              # khtml
104 check_function_exists(getpeereid       HAVE_GETPEEREID)               # kdesu
105 check_function_exists(madvise         HAVE_MADVISE)                   # kdecore
106 check_function_exists(mmap            HAVE_MMAP)                      # kdecore, khtml
107 if(NOT WIN32)
108   # we don't have it on windows but need to export it to be backward compatible
109   # can be removed when 4.1 is out
110   check_function_exists(readdir_r     HAVE_READDIR_R)                 # kio
111 endif(NOT WIN32)
112 check_function_exists(sendfile        HAVE_SENDFILE)                  # kioslave
113 check_function_exists(setlocale       HAVE_SETPRIORITY)               # kdesu
114 check_function_exists(srandom         HAVE_SRANDOM)                   # config.h
115 check_function_exists(_NSGetEnviron   HAVE_NSGETENVIRON)              # kinit, config.h
116 check_function_exists(gettimeofday    HAVE_GETTIMEOFDAY)              # testkjs
118 check_library_exists(volmgt volmgt_running "" HAVE_VOLMGT)            # various
120 # Check for libresolv
121 # e.g. on slackware 9.1 res_init() is only a define for __res_init, so we check both, Alex
122 set(HAVE_RESOLV_LIBRARY FALSE)                                        # kdecore, kdecore/network, kpac
123 check_library_exists(resolv res_init "" HAVE_RES_INIT_IN_RESOLV_LIBRARY)
124 check_library_exists(resolv __res_init "" HAVE___RES_INIT_IN_RESOLV_LIBRARY)
125 if (HAVE___RES_INIT_IN_RESOLV_LIBRARY OR HAVE_RES_INIT_IN_RESOLV_LIBRARY)
126    set(HAVE_RESOLV_LIBRARY TRUE)
127 endif (HAVE___RES_INIT_IN_RESOLV_LIBRARY OR HAVE_RES_INIT_IN_RESOLV_LIBRARY)
129 if (UNIX)
131   # for kdecore (kpty) & kdesu
133   check_include_files("sys/types.h;libutil.h" HAVE_LIBUTIL_H)
134   check_include_files(util.h       HAVE_UTIL_H)
135   check_include_files(termios.h    HAVE_TERMIOS_H)
136   check_include_files(termio.h     HAVE_TERMIO_H)
137   check_include_files(pty.h        HAVE_PTY_H)
138   check_include_files(sys/stropts.h HAVE_SYS_STROPTS_H)
139   check_include_files(sys/filio.h  HAVE_SYS_FILIO_H)
141   set(UTIL_LIBRARY)
143   check_library_exists(utempter addToUtmp "" HAVE_ADDTOUTEMP)
144   check_include_files(utempter.h HAVE_UTEMPTER_H)
145   if (HAVE_ADDTOUTEMP AND HAVE_UTEMPTER_H)
146     set(HAVE_UTEMPTER 1)
147     set(UTEMPTER_LIBRARY utempter)
148   else (HAVE_ADDTOUTEMP AND HAVE_UTEMPTER_H)
149     check_function_exists(login login_in_libc)
150     if (NOT login_in_libc)
151       check_library_exists(util login "" login_in_libutil)
152       if (login_in_libutil)
153         set(UTIL_LIBRARY util)
154       endif (login_in_libutil)
155     endif (NOT login_in_libc)
156     if (CMAKE_SYSTEM_NAME MATCHES Linux OR CMAKE_SYSTEM_NAME MATCHES Darwin OR CMAKE_SYSTEM_NAME MATCHES GNU/FreeBSD)
157       set (HAVE_UTMPX)
158     else (CMAKE_SYSTEM_NAME MATCHES Linux OR CMAKE_SYSTEM_NAME MATCHES Darwin OR CMAKE_SYSTEM_NAME MATCHES GNU/FreeBSD)
159       check_function_exists(getutxent HAVE_UTMPX)
160     endif (CMAKE_SYSTEM_NAME MATCHES Linux OR CMAKE_SYSTEM_NAME MATCHES Darwin OR CMAKE_SYSTEM_NAME MATCHES GNU/FreeBSD)
161     if (HAVE_UTMPX)
162       set(utmp utmpx)
163       if (login_in_libutil)
164         check_library_exists(util loginx "" HAVE_LOGINX)
165       endif (login_in_libutil)
166     else (HAVE_UTMPX)
167       set(utmp utmp)
168     endif (HAVE_UTMPX)
169     if (login_in_libc OR login_in_libutil)
170       set(HAVE_LOGIN 1)
171     else (login_in_libc OR login_in_libutil)
172       set(HAVE_LOGIN)
173       check_struct_member("struct ${utmp}" "ut_type" "${utmp}.h" HAVE_STRUCT_UTMP_UT_TYPE)
174       check_struct_member("struct ${utmp}" "ut_pid" "${utmp}.h" HAVE_STRUCT_UTMP_UT_PID)
175       check_struct_member("struct ${utmp}" "ut_session" "${utmp}.h" HAVE_STRUCT_UTMP_UT_SESSION)
176     endif (login_in_libc OR login_in_libutil)
177     check_struct_member("struct ${utmp}" "ut_syslen" "${utmp}.h" HAVE_STRUCT_UTMP_UT_SYSLEN)
178     check_struct_member("struct ${utmp}" "ut_id" "${utmp}.h" HAVE_STRUCT_UTMP_UT_ID)
179   endif (HAVE_ADDTOUTEMP AND HAVE_UTEMPTER_H)
181   check_function_exists(openpty openpty_in_libc)
182   if (NOT openpty_in_libc)
183     check_library_exists(util openpty "" openpty_in_libutil)
184     if (openpty_in_libutil)
185       set(UTIL_LIBRARY util)
186     endif (openpty_in_libutil)
187   endif (NOT openpty_in_libc)
188   if (openpty_in_libc OR openpty_in_libutil)
189     set(HAVE_OPENPTY 1)
190   else (openpty_in_libc OR openpty_in_libutil)
191     set(HAVE_OPENPTY)
193     EXECUTE_PROCESS(
194       COMMAND sh -c "
195         for ptm in ptc ptmx ptm ptym/clone; do
196           if test -c /dev/$ptm; then
197             echo /dev/$ptm
198             break
199           fi
200         done"
201       OUTPUT_VARIABLE PTM_DEVICE
202       OUTPUT_STRIP_TRAILING_WHITESPACE)
203     message(STATUS "PTY multiplexer: ${PTM_DEVICE}")
205     check_function_exists(revoke     HAVE_REVOKE)
206     check_function_exists(_getpty    HAVE__GETPTY)
207     check_function_exists(getpt      HAVE_GETPT)
208     check_function_exists(grantpt    HAVE_GRANTPT)
209     check_function_exists(unlockpt   HAVE_UNLOCKPT)
210     check_function_exists(posix_openpt HAVE_POSIX_OPENPT)
211   endif (openpty_in_libc OR openpty_in_libutil)
213   check_function_exists(ptsname    HAVE_PTSNAME)
214 endif (UNIX)
216 # it seems this isn't used anywhere
217 #find_library(ICE_LIB NAMES ICE PATHS /usr/X11/lib)
218 #check_library_exists(${ICE_LIB} _IceTransNoListen "" HAVE__ICETRANSNOLISTEN)
220 #set(CMAKE_REQUIRED_LIBRARIES crypt)
221 #check_function_exists(crypt "" HAVE_CRYPT)
222 #set(CMAKE_REQUIRED_LIBRARIES)
224 check_function_exists(getmntinfo HAVE_GETMNTINFO)        # kdecore, kio
225 check_function_exists(initgroups HAVE_INITGROUPS)        # kdecore, kdesu
226 check_function_exists(mkstemps   HAVE_MKSTEMPS)          # dcop, kdecore/fakes.c
227 check_function_exists(mkstemp    HAVE_MKSTEMP)           # kdecore/fakes.c
228 check_function_exists(mkdtemp    HAVE_MKDTEMP)           # kdecore/fakes.c
229 check_function_exists(random     HAVE_RANDOM)            # kdecore/fakes.c
230 check_function_exists(strlcpy    HAVE_STRLCPY)           # kdecore/fakes.c
231 check_function_exists(strlcat    HAVE_STRLCAT)           # kdecore/fakes.c
232 check_function_exists(strcasestr HAVE_STRCASESTR)        # kdecore/fakes.c
233 check_function_exists(setenv     HAVE_SETENV)            # kdecore/fakes.c
234 check_function_exists(seteuid    HAVE_SETEUID)           # kdecore/fakes.c
235 check_function_exists(setmntent  HAVE_SETMNTENT)         # solid, kio, kdecore
236 check_function_exists(unsetenv   HAVE_UNSETENV)          # kdecore/fakes.c
237 check_function_exists(usleep     HAVE_USLEEP)            # kdecore/fakes.c, kdeui/qxembed
239 # check for prototypes [for functions provided by kdefakes when not available]
241 check_prototype_exists(mkstemps "stdlib.h;unistd.h" HAVE_MKSTEMPS_PROTO)
242 check_prototype_exists(mkdtemp "stdlib.h;unistd.h"  HAVE_MKDTEMP_PROTO)
243 check_prototype_exists(mkstemp "stdlib.h;unistd.h"  HAVE_MKSTEMP_PROTO)
244 check_prototype_exists(strlcat string.h             HAVE_STRLCAT_PROTO)
245 check_prototype_exists(strcasestr string.h          HAVE_STRCASESTR_PROTO)
246 check_prototype_exists(strlcpy string.h             HAVE_STRLCPY_PROTO)
247 check_prototype_exists(random stdlib.h              HAVE_RANDOM_PROTO)
248 check_prototype_exists(res_init "sys/types.h;netinet/in.h;arpa/nameser.h;resolv.h" HAVE_RES_INIT_PROTO)
249 check_prototype_exists(setenv stdlib.h              HAVE_SETENV_PROTO)
250 check_prototype_exists(srandom stdlib.h             HAVE_SRANDOM_PROTO)
251 check_prototype_exists(unsetenv stdlib.h            HAVE_UNSETENV_PROTO)
252 check_prototype_exists(usleep unistd.h              HAVE_USLEEP_PROTO)
253 check_prototype_exists(initgroups "unistd.h;sys/types.h;unistd.h;grp.h" HAVE_INITGROUPS_PROTO)
254 check_prototype_exists(setreuid unistd.h            HAVE_SETREUID_PROTO)
255 check_prototype_exists(seteuid unistd.h             HAVE_SETEUID_PROTO)
256 check_prototype_exists(trunc math.h                 HAVE_TRUNC)
258 # check for existing datatypes
260 set(CMAKE_EXTRA_INCLUDE_FILES sys/socket.h)
261 check_type_size("struct ucred" STRUCT_UCRED)              # kdesu
262 check_type_size(time_t SIZEOF_TIME_T)                          # kdecore
264 set(CMAKE_EXTRA_INCLUDE_FILES)  #reset CMAKE_EXTRA_INCLUDE_FILES
266 check_cxx_source_compiles("
267   #include <sys/types.h>
268   #include <sys/statvfs.h>
269   int main(){
270     struct statvfs *mntbufp;
271     int flags;
272     return getmntinfo(&mntbufp, flags);
273   }
274 " GETMNTINFO_USES_STATVFS )
276 check_struct_member(tm tm_zone time.h HAVE_STRUCT_TM_TM_ZONE)  # kdecore
277 check_struct_member(tm tm_gmtoff time.h HAVE_TM_GMTOFF)        # kdecore
278 check_struct_member(dirent d_type dirent.h HAVE_DIRENT_D_TYPE) # kdecore, kded
279 include(TestBigEndian)
280 test_big_endian(WORDS_BIGENDIAN)
282 # TODO: for the more capable cmake authors: we need at least gcc's and MSVC's version in here
283 set (KDE_COMPILER_VERSION ${CMAKE_C_COMPILER})
284 string(REGEX REPLACE ^.*/ "" KDE_COMPILER_VERSION ${KDE_COMPILER_VERSION})