1## feature detection
2find_package(Threads)
3find_package(ZLIB REQUIRED)
4
5option(USE_VALGRIND "Build to run safely under valgrind (often slower)." ON)
6if(USE_VALGRIND)
7  find_package(Valgrind REQUIRED)
8endif()
9
10option(TOKU_DEBUG_PARANOID "Enable paranoid asserts." ON)
11
12include(CheckIncludeFiles)
13
14## check for some include files
15check_include_files(alloca.h HAVE_ALLOCA_H)
16check_include_files(arpa/inet.h HAVE_ARPA_INET_H)
17check_include_files(bits/functexcept.h HAVE_BITS_FUNCTEXCEPT_H)
18check_include_files(byteswap.h HAVE_BYTESWAP_H)
19check_include_files(endian.h HAVE_ENDIAN_H)
20check_include_files(fcntl.h HAVE_FCNTL_H)
21check_include_files(inttypes.h HAVE_INTTYPES_H)
22check_include_files(libkern/OSAtomic.h HAVE_LIBKERN_OSATOMIC_H)
23check_include_files(libkern/OSByteOrder.h HAVE_LIBKERN_OSBYTEORDER_H)
24check_include_files(limits.h HAVE_LIMITS_H)
25check_include_files(machine/endian.h HAVE_MACHINE_ENDIAN_H)
26check_include_files(malloc.h HAVE_MALLOC_H)
27check_include_files(malloc/malloc.h HAVE_MALLOC_MALLOC_H)
28check_include_files(malloc_np.h HAVE_MALLOC_NP_H)
29check_include_files(pthread.h HAVE_PTHREAD_H)
30check_include_files(pthread_np.h HAVE_PTHREAD_NP_H)
31check_include_files(stdint.h HAVE_STDINT_H)
32check_include_files(stdlib.h HAVE_STDLIB_H)
33check_include_files(string.h HAVE_STRING_H)
34check_include_files(syscall.h HAVE_SYSCALL_H)
35check_include_files(sys/endian.h HAVE_SYS_ENDIAN_H)
36check_include_files(sys/file.h HAVE_SYS_FILE_H)
37check_include_files(sys/malloc.h HAVE_SYS_MALLOC_H)
38check_include_files(sys/prctl.h HAVE_SYS_PRCTL_H)
39check_include_files(sys/resource.h HAVE_SYS_RESOURCE_H)
40check_include_files(sys/statvfs.h HAVE_SYS_STATVFS_H)
41check_include_files(sys/syscall.h HAVE_SYS_SYSCALL_H)
42check_include_files(sys/sysctl.h HAVE_SYS_SYSCTL_H)
43check_include_files(sys/syslimits.h HAVE_SYS_SYSLIMITS_H)
44check_include_files(sys/time.h HAVE_SYS_TIME_H)
45check_include_files(unistd.h HAVE_UNISTD_H)
46
47include(CheckSymbolExists)
48
49## check whether we can set the mmap threshold like we can in gnu libc's malloc
50check_symbol_exists(M_MMAP_THRESHOLD "malloc.h" HAVE_M_MMAP_THRESHOLD)
51## check whether we have CLOCK_REALTIME
52check_symbol_exists(CLOCK_REALTIME "time.h" HAVE_CLOCK_REALTIME)
53## check how to do direct I/O
54if (NOT CMAKE_SYSTEM_NAME STREQUAL FreeBSD)
55  set(CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
56endif ()
57check_symbol_exists(O_DIRECT "fcntl.h" HAVE_O_DIRECT)
58check_symbol_exists(F_NOCACHE "fcntl.h" HAVE_F_NOCACHE)
59check_symbol_exists(MAP_ANONYMOUS "sys/mman.h" HAVE_MAP_ANONYMOUS)
60check_symbol_exists(PR_SET_PTRACER "sys/prctl.h" HAVE_PR_SET_PTRACER)
61check_symbol_exists(PR_SET_PTRACER_ANY "sys/prctl.h" HAVE_PR_SET_PTRACER_ANY)
62
63include(CheckFunctionExists)
64
65## check for the right way to get the actual allocation size of a pointer
66check_function_exists(malloc_size HAVE_MALLOC_SIZE)
67check_function_exists(malloc_usable_size HAVE_MALLOC_USABLE_SIZE)
68## check whether we have memalign or valloc (a weak substitute for memalign on darwin)
69check_function_exists(memalign HAVE_MEMALIGN)
70check_function_exists(valloc HAVE_VALLOC)
71## check whether we have random_r or nrand48 to use as a reentrant random function
72check_function_exists(nrand48 HAVE_NRAND48)
73check_function_exists(random_r HAVE_RANDOM_R)
74check_function_exists(mincore HAVE_MINCORE)
75
76## clear this out in case mysql modified it
77set(CMAKE_REQUIRED_LIBRARIES "")
78set(EXTRA_SYSTEM_LIBS "")
79check_function_exists(dlsym HAVE_DLSYM_WITHOUT_DL)
80if (NOT HAVE_DLSYM_WITHOUT_DL)
81  set(CMAKE_REQUIRED_LIBRARIES dl)
82  check_function_exists(dlsym HAVE_DLSYM_WITH_DL)
83  if (HAVE_DLSYM_WITH_DL)
84    list(APPEND EXTRA_SYSTEM_LIBS dl)
85  else ()
86    message(FATAL_ERROR "Cannot find dlsym(), even with -ldl.")
87  endif ()
88endif ()
89check_function_exists(backtrace HAVE_BACKTRACE_WITHOUT_EXECINFO)
90if (NOT HAVE_BACKTRACE_WITHOUT_EXECINFO)
91  set(CMAKE_REQUIRED_LIBRARIES execinfo)
92  check_function_exists(backtrace HAVE_BACKTRACE_WITH_EXECINFO)
93  if (HAVE_BACKTRACE_WITH_EXECINFO)
94    list(APPEND EXTRA_SYSTEM_LIBS execinfo)
95  else ()
96    message(WARNING "Cannot find backtrace(), even with -lexecinfo.")
97  endif ()
98endif ()
99
100if(HAVE_CLOCK_REALTIME AND (NOT APPLE))
101  list(APPEND EXTRA_SYSTEM_LIBS rt)
102else()
103  list(APPEND EXTRA_SYSTEM_LIBS System)
104endif()
105
106set(CMAKE_REQUIRED_LIBRARIES pthread)
107## check whether we can change rwlock preference
108check_function_exists(pthread_rwlockattr_setkind_np HAVE_PTHREAD_RWLOCKATTR_SETKIND_NP)
109## check for the right way to yield using pthreads
110check_function_exists(pthread_yield HAVE_PTHREAD_YIELD)
111check_function_exists(pthread_yield_np HAVE_PTHREAD_YIELD_NP)
112## check if we have pthread_threadid_np() (i.e. osx)
113check_function_exists(pthread_threadid_np HAVE_PTHREAD_THREADID_NP)
114## check if we have pthread_getthreadid_np() (i.e. freebsd)
115check_function_exists(pthread_getthreadid_np HAVE_PTHREAD_GETTHREADID_NP)
116check_function_exists(sched_getcpu HAVE_SCHED_GETCPU)
117
118include(CheckCSourceCompiles)
119
120if (HAVE_PTHREAD_YIELD)
121  include(CheckPrototypeDefinition)
122
123  check_prototype_definition(pthread_yield "void pthread_yield(void)" "(void)0" "pthread.h" PTHREAD_YIELD_RETURNS_VOID)
124  check_c_source_compiles("#include <pthread.h>
125int main(void) {
126  int r = pthread_yield();
127  return r;
128}" PTHREAD_YIELD_RETURNS_INT)
129endif (HAVE_PTHREAD_YIELD)
130
131## check whether we have gcc-style thread-local storage using a storage class modifier
132check_c_source_compiles("#include <pthread.h>
133static __thread int tlsvar = 0;
134int main(void) { return tlsvar; }" HAVE_GNU_TLS)
135
136## set TOKUDB_REVISION
137set(CMAKE_TOKUDB_REVISION 0 CACHE INTERNAL "Revision of tokudb.")
138