1
2# Copyright (c) 2010, 2018, Oracle and/or its affiliates. All rights reserved.
3#
4# This program is free software; you can redistribute it and/or modify
5# it under the terms of the GNU General Public License, version 2.0,
6# as published by the Free Software Foundation.
7#
8# This program is also distributed with certain software (including
9# but not limited to OpenSSL) that is licensed under separate terms,
10# as designated in a particular file or component or in included license
11# documentation.  The authors of MySQL hereby grant you an additional
12# permission to link the program and your derivative works with the
13# separately licensed software that they have included with MySQL.
14#
15# This program is distributed in the hope that it will be useful,
16# but WITHOUT ANY WARRANTY; without even the implied warranty of
17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18# GNU General Public License, version 2.0, for more details.
19#
20# You should have received a copy of the GNU General Public License
21# along with this program; if not, write to the Free Software
22# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
23#
24
25#
26# Run platform checks and create ndb_config.h
27#
28
29
30# Include the platform-specific file. To allow exceptions, this code
31# looks for files in order of how specific they are. If there is, for
32# example, a generic Linux.cmake and a version-specific
33# Linux-2.6.28-11-generic, it will pick Linux-2.6.28-11-generic and
34# include it. It is then up to the file writer to include the generic
35# version if necessary.
36FOREACH(_base
37        ${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_VERSION}-${CMAKE_SYSTEM_PROCESSOR}
38        ${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_VERSION}
39        ${CMAKE_SYSTEM_NAME})
40  SET(_file ${CMAKE_CURRENT_SOURCE_DIR}/cmake/os/${_base}.cmake)
41  IF(EXISTS ${_file})
42    INCLUDE(${_file})
43    BREAK()
44  ENDIF()
45ENDFOREACH()
46
47
48INCLUDE(CheckFunctionExists)
49INCLUDE(CheckIncludeFiles)
50INCLUDE(CheckCSourceCompiles)
51INCLUDE(CheckCXXSourceCompiles)
52INCLUDE(CheckCXXSourceRuns)
53INCLUDE(ndb_require_variable)
54
55CHECK_FUNCTION_EXISTS(posix_memalign HAVE_POSIX_MEMALIGN)
56CHECK_FUNCTION_EXISTS(clock_gettime HAVE_CLOCK_GETTIME)
57CHECK_FUNCTION_EXISTS(pthread_condattr_setclock HAVE_PTHREAD_CONDATTR_SETCLOCK)
58CHECK_FUNCTION_EXISTS(pthread_self HAVE_PTHREAD_SELF)
59CHECK_FUNCTION_EXISTS(sched_get_priority_min HAVE_SCHED_GET_PRIORITY_MIN)
60CHECK_FUNCTION_EXISTS(sched_get_priority_max HAVE_SCHED_GET_PRIORITY_MAX)
61CHECK_FUNCTION_EXISTS(sched_setaffinity HAVE_SCHED_SETAFFINITY)
62CHECK_FUNCTION_EXISTS(sched_setscheduler HAVE_SCHED_SETSCHEDULER)
63CHECK_FUNCTION_EXISTS(processor_bind HAVE_PROCESSOR_BIND)
64CHECK_FUNCTION_EXISTS(epoll_create HAVE_EPOLL_CREATE)
65CHECK_FUNCTION_EXISTS(memalign HAVE_MEMALIGN)
66CHECK_FUNCTION_EXISTS(sysconf HAVE_SYSCONF)
67CHECK_FUNCTION_EXISTS(directio HAVE_DIRECTIO)
68CHECK_FUNCTION_EXISTS(atomic_swap_32 HAVE_ATOMIC_SWAP32)
69CHECK_FUNCTION_EXISTS(mlock HAVE_MLOCK)
70CHECK_FUNCTION_EXISTS(ffs HAVE_FFS)
71CHECK_FUNCTION_EXISTS(pthread_mutexattr_init HAVE_PTHREAD_MUTEXATTR_INIT)
72CHECK_FUNCTION_EXISTS(pthread_mutexattr_settype HAVE_PTHREAD_MUTEXATTR_SETTYPE)
73CHECK_FUNCTION_EXISTS(pthread_setschedparam HAVE_PTHREAD_SETSCHEDPARAM)
74CHECK_FUNCTION_EXISTS(bzero HAVE_BZERO)
75
76CHECK_INCLUDE_FILES(sun_prefetch.h HAVE_SUN_PREFETCH_H)
77
78CHECK_CXX_SOURCE_COMPILES("
79unsigned A = 7;
80int main()
81{
82  unsigned a = __builtin_ffs(A);
83  return 0;
84}"
85HAVE___BUILTIN_FFS)
86
87CHECK_C_SOURCE_COMPILES("
88#include <intrin.h>
89unsigned long A = 7;
90int main()
91{
92  unsigned long a;
93  unsigned char res = _BitScanForward(&a, A);
94  return (int)a;
95}"
96HAVE__BITSCANFORWARD)
97
98# Linux scheduling and locking support
99CHECK_C_SOURCE_COMPILES("
100#ifndef _GNU_SOURCE
101#define _GNU_SOURCE
102#endif
103#include <sys/types.h>
104#include <unistd.h>
105#include <sched.h>
106#include <sys/syscall.h>
107int main()
108{
109  const cpu_set_t *p= (const cpu_set_t*)0;
110  struct sched_param loc_sched_param;
111  int policy = 0;
112  pid_t tid = (unsigned)syscall(SYS_gettid);
113  tid = getpid();
114  int ret = sched_setaffinity(tid, sizeof(* p), p);
115  ret = sched_setscheduler(tid, policy, &loc_sched_param);
116}"
117HAVE_LINUX_SCHEDULING)
118
119# Solaris affinity support
120CHECK_C_SOURCE_COMPILES("
121#include <sys/types.h>
122#include <sys/lwp.h>
123#include <sys/processor.h>
124#include <sys/procset.h>
125int main()
126{
127  processorid_t cpu_id = (processorid_t)0;
128  id_t tid = _lwp_self();
129  int ret = processor_bind(P_LWPID, tid, cpu_id, 0);
130}"
131HAVE_SOLARIS_AFFINITY)
132
133# Linux futex support
134CHECK_C_SOURCE_COMPILES("
135#ifndef _GNU_SOURCE
136#define _GNU_SOURCE
137#endif
138#include <sys/types.h>
139#include <unistd.h>
140#include <errno.h>
141#include <sys/syscall.h>]
142#define FUTEX_WAIT        0
143#define FUTEX_WAKE        1
144#define FUTEX_FD          2
145#define FUTEX_REQUEUE     3
146#define FUTEX_CMP_REQUEUE 4
147#define FUTEX_WAKE_OP     5
148int main()
149{
150  int a = 0; int * addr = &a;
151  return syscall(SYS_futex, addr, FUTEX_WAKE, 1, 0, 0, 0) == 0 ? 0 : errno;
152}"
153HAVE_LINUX_FUTEX)
154
155OPTION(WITH_NDBMTD
156  "Build the MySQL Cluster multithreadded data node" ON)
157
158IF(WITH_NDBMTD)
159  # checking atomic.h needed for spinlock's on sparc and Sun Studio
160  CHECK_INCLUDE_FILES(atomic.h HAVE_ATOMIC_H)
161
162  # checking assembler needed for ndbmtd
163  CHECK_CXX_SOURCE_RUNS("
164  #define HAVE_ATOMIC_H ${HAVE_ATOMIC_H}
165  #include \"${CMAKE_SOURCE_DIR}/storage/ndb/src/kernel/vm/mt-asm.h\"
166  int main()
167  {
168    unsigned int a = 0;
169    volatile unsigned int *ap = (volatile unsigned int*)&a;
170    #ifdef NDB_HAVE_XCNG
171      a = xcng(ap, 1);
172      cpu_pause();
173    #endif
174    mb();
175    * ap = 2;
176    rmb();
177    * ap = 1;
178    wmb();
179    * ap = 0;
180    read_barrier_depends();
181    return a;
182  }"
183  NDB_BUILD_NDBMTD)
184ELSE()
185  SET(NDB_BUILD_NDBMTD CACHE INTERNAL "")
186ENDIF()
187
188SET(WITH_NDB_PORT "" CACHE INTEGER
189  "Default port used by MySQL Cluster management server")
190IF(WITH_NDB_PORT GREATER 0)
191  SET(NDB_PORT ${WITH_NDB_PORT})
192  MESSAGE(STATUS "Setting MySQL Cluster management server port to ${NDB_PORT}")
193ENDIF()
194
195CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/include/ndb_config.h.in
196               ${CMAKE_CURRENT_BINARY_DIR}/include/ndb_config.h)
197
198# Define HAVE_NDB_CONFIG_H to make ndb_global.h include the
199# generated ndb_config.h
200ADD_DEFINITIONS(-DHAVE_NDB_CONFIG_H)
201
202# check zlib
203IF(NOT DEFINED WITH_ZLIB)
204  # Hardcode use of the bundled zlib if not set by MySQL
205  MESSAGE(STATUS "Using bundled zlib (hardcoded)")
206  SET(ZLIB_LIBRARY zlib)
207  INCLUDE_DIRECTORIES(SYSTEM ${CMAKE_SOURCE_DIR}/zlib)
208ENDIF()
209NDB_REQUIRE_VARIABLE(ZLIB_LIBRARY)
210
211IF(WITH_CLASSPATH)
212  MESSAGE(STATUS "Using supplied classpath: ${WITH_CLASSPATH}")
213ELSE()
214  SET(WITH_CLASSPATH "$ENV{CLASSPATH}")
215  IF(WITH_CLASSPATH)
216    MESSAGE(STATUS "Using CLASSPATH from environment: ${WITH_CLASSPATH}")
217  ENDIF()
218ENDIF()
219