2016-09-06 08:43:16 +02:00
# Copyright (c) 2006, 2016, Oracle and/or its affiliates. All rights reserved.
2019-03-27 11:26:11 +01:00
# Copyright (c) 2017, 2019, MariaDB Corporation.
2016-08-12 10:17:45 +02:00
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
# This is the CMakeLists for InnoDB
INCLUDE ( CheckFunctionExists )
INCLUDE ( CheckCSourceCompiles )
INCLUDE ( CheckCSourceRuns )
2017-03-27 11:03:23 +02:00
INCLUDE ( lz4.cmake )
INCLUDE ( lzo.cmake )
INCLUDE ( lzma.cmake )
INCLUDE ( bzip2.cmake )
INCLUDE ( snappy.cmake )
2017-05-29 07:30:21 +02:00
INCLUDE ( numa )
MDEV-17958 Make bug-endian innodb_checksum_algorithm=crc32 optional
In MySQL 5.7, it was noticed that files are not portable between
big-endian and little-endian processor architectures
(such as SPARC and x86), because the original implementation of
innodb_checksum_algorithm=crc32 was not byte order agnostic.
A byte order agnostic implementation of innodb_checksum_algorithm=crc32
was only added to MySQL 5.7, not backported to 5.6. Consequently,
MariaDB Server versions 10.0 and 10.1 only contain the CRC-32C
implementation that works incorrectly on big-endian architectures,
and MariaDB Server 10.2.2 got the byte-order agnostic CRC-32C
implementation from MySQL 5.7.
MySQL 5.7 introduced a "legacy crc32" variant that is functionally
equivalent to the big-endian version of the original crc32 implementation.
Thanks to this variant, old data files can be transferred from big-endian
systems to newer versions.
Introducing new variants of checksum algorithms (without introducing
new names for them, or something on the pages themselves to identify
the algorithm) generally is a bad idea, because each checksum algorithm
is like a lottery ticket. The more algorithms you try, the more likely
it will be for the checksum to match on a corrupted page.
So, essentially MySQL 5.7 weakened innodb_checksum_algorithm=crc32,
and MariaDB 10.2.2 inherited this weakening.
We introduce a build option that together with MDEV-17957
makes innodb_checksum_algorithm=strict_crc32 strict again
by only allowing one variant of the checksum to match.
WITH_INNODB_BUG_ENDIAN_CRC32: A new cmake option for enabling the
bug-compatible "legacy crc32" checksum. This is only enabled on
big-endian systems by default, to facilitate an upgrade from
MariaDB 10.0 or 10.1. Checked by #ifdef INNODB_BUG_ENDIAN_CRC32.
ut_crc32_byte_by_byte: Remove (unused function).
legacy_big_endian_checksum: Remove. This variable seems to have
unnecessarily complicated the logic. When the weakening is enabled,
we must always fall back to the buggy checksum.
buf_page_check_crc32(): A helper function to compute one or
two CRC-32C variants.
2018-12-13 16:57:10 +01:00
INCLUDE ( TestBigEndian )
2016-09-06 08:43:16 +02:00
MYSQL_CHECK_LZ4 ( )
MYSQL_CHECK_LZO ( )
MYSQL_CHECK_LZMA ( )
MYSQL_CHECK_BZIP2 ( )
MYSQL_CHECK_SNAPPY ( )
2017-05-29 07:30:21 +02:00
MYSQL_CHECK_NUMA ( )
MDEV-17958 Make bug-endian innodb_checksum_algorithm=crc32 optional
In MySQL 5.7, it was noticed that files are not portable between
big-endian and little-endian processor architectures
(such as SPARC and x86), because the original implementation of
innodb_checksum_algorithm=crc32 was not byte order agnostic.
A byte order agnostic implementation of innodb_checksum_algorithm=crc32
was only added to MySQL 5.7, not backported to 5.6. Consequently,
MariaDB Server versions 10.0 and 10.1 only contain the CRC-32C
implementation that works incorrectly on big-endian architectures,
and MariaDB Server 10.2.2 got the byte-order agnostic CRC-32C
implementation from MySQL 5.7.
MySQL 5.7 introduced a "legacy crc32" variant that is functionally
equivalent to the big-endian version of the original crc32 implementation.
Thanks to this variant, old data files can be transferred from big-endian
systems to newer versions.
Introducing new variants of checksum algorithms (without introducing
new names for them, or something on the pages themselves to identify
the algorithm) generally is a bad idea, because each checksum algorithm
is like a lottery ticket. The more algorithms you try, the more likely
it will be for the checksum to match on a corrupted page.
So, essentially MySQL 5.7 weakened innodb_checksum_algorithm=crc32,
and MariaDB 10.2.2 inherited this weakening.
We introduce a build option that together with MDEV-17957
makes innodb_checksum_algorithm=strict_crc32 strict again
by only allowing one variant of the checksum to match.
WITH_INNODB_BUG_ENDIAN_CRC32: A new cmake option for enabling the
bug-compatible "legacy crc32" checksum. This is only enabled on
big-endian systems by default, to facilitate an upgrade from
MariaDB 10.0 or 10.1. Checked by #ifdef INNODB_BUG_ENDIAN_CRC32.
ut_crc32_byte_by_byte: Remove (unused function).
legacy_big_endian_checksum: Remove. This variable seems to have
unnecessarily complicated the logic. When the weakening is enabled,
we must always fall back to the buggy checksum.
buf_page_check_crc32(): A helper function to compute one or
two CRC-32C variants.
2018-12-13 16:57:10 +01:00
TEST_BIG_ENDIAN ( IS_BIG_ENDIAN )
2016-09-06 08:43:16 +02:00
2018-04-03 14:14:00 +02:00
INCLUDE ( ${ MYSQL_CMAKE_SCRIPT_DIR } /compile_flags.cmake )
2016-09-06 08:43:16 +02:00
IF ( CMAKE_CROSSCOMPILING )
# Use CHECK_C_SOURCE_COMPILES instead of CHECK_C_SOURCE_RUNS when
# cross-compiling. Not as precise, but usually good enough.
# This only make sense for atomic tests in this file, this trick doesn't
# work in a general case.
MACRO ( CHECK_C_SOURCE SOURCE VAR )
CHECK_C_SOURCE_COMPILES ( "${SOURCE}" "${VAR}" )
ENDMACRO ( )
ELSE ( )
MACRO ( CHECK_C_SOURCE SOURCE VAR )
CHECK_C_SOURCE_RUNS ( "${SOURCE}" "${VAR}" )
ENDMACRO ( )
2016-08-12 10:17:45 +02:00
ENDIF ( )
# OS tests
IF ( UNIX )
IF ( CMAKE_SYSTEM_NAME STREQUAL "Linux" )
ADD_DEFINITIONS ( "-DUNIV_LINUX -D_GNU_SOURCE=1" )
CHECK_INCLUDE_FILES ( libaio.h HAVE_LIBAIO_H )
CHECK_LIBRARY_EXISTS ( aio io_queue_init "" HAVE_LIBAIO )
IF ( HAVE_LIBAIO_H AND HAVE_LIBAIO )
ADD_DEFINITIONS ( -DLINUX_NATIVE_AIO=1 )
LINK_LIBRARIES ( aio )
ENDIF ( )
IF ( HAVE_LIBNUMA )
LINK_LIBRARIES ( numa )
ENDIF ( )
2016-09-06 08:43:16 +02:00
ELSEIF ( CMAKE_SYSTEM_NAME MATCHES "HP*" )
ADD_DEFINITIONS ( "-DUNIV_HPUX" )
ELSEIF ( CMAKE_SYSTEM_NAME STREQUAL "AIX" )
ADD_DEFINITIONS ( "-DUNIV_AIX" )
2016-08-12 10:17:45 +02:00
ELSEIF ( CMAKE_SYSTEM_NAME STREQUAL "SunOS" )
ADD_DEFINITIONS ( "-DUNIV_SOLARIS" )
ENDIF ( )
ENDIF ( )
OPTION ( INNODB_COMPILER_HINTS "Compile InnoDB with compiler hints" ON )
MARK_AS_ADVANCED ( INNODB_COMPILER_HINTS )
IF ( INNODB_COMPILER_HINTS )
ADD_DEFINITIONS ( "-DCOMPILER_HINTS" )
ENDIF ( )
SET ( MUTEXTYPE "event" CACHE STRING "Mutex type: event, sys or futex" )
IF ( CMAKE_CXX_COMPILER_ID MATCHES "GNU" )
# After: WL#5825 Using C++ Standard Library with MySQL code
# we no longer use -fno-exceptions
# SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions")
# Add -Wconversion if compiling with GCC
## As of Mar 15 2011 this flag causes 3573+ warnings. If you are reading this
## please fix them and enable the following code:
#SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wconversion")
IF ( CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64" OR
2019-12-20 06:33:31 +01:00
C M A K E _ S Y S T E M _ P R O C E S S O R M A T C H E S " i 3 8 6 " A N D
C M A K E _ C X X _ C O M P I L E R _ V E R S I O N V E R S I O N _ L E S S 4 . 6 )
2016-08-12 10:17:45 +02:00
INCLUDE ( CheckCXXCompilerFlag )
CHECK_CXX_COMPILER_FLAG ( "-fno-builtin-memcmp" HAVE_NO_BUILTIN_MEMCMP )
IF ( HAVE_NO_BUILTIN_MEMCMP )
# Work around http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43052
SET_SOURCE_FILES_PROPERTIES ( ${ CMAKE_CURRENT_SOURCE_DIR } /rem/rem0cmp.cc
P R O P E R T I E S C O M P I L E _ F L A G S - f n o - b u i l t i n - m e m c m p )
ENDIF ( )
ENDIF ( )
ENDIF ( )
# Enable InnoDB's UNIV_DEBUG in debug builds
2017-12-04 10:48:12 +01:00
SET ( CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DUNIV_DEBUG" )
2016-08-12 10:17:45 +02:00
2017-02-23 22:05:12 +01:00
OPTION ( WITH_INNODB_AHI "Include innodb_adaptive_hash_index" ON )
OPTION ( WITH_INNODB_ROOT_GUESS "Cache index root block descriptors" ON )
IF ( WITH_INNODB_AHI )
ADD_DEFINITIONS ( -DBTR_CUR_HASH_ADAPT -DBTR_CUR_ADAPT )
IF ( NOT WITH_INNODB_ROOT_GUESS )
MESSAGE ( WARNING "WITH_INNODB_AHI implies WITH_INNODB_ROOT_GUESS" )
ENDIF ( )
ELSEIF ( WITH_INNODB_ROOT_GUESS )
ADD_DEFINITIONS ( -DBTR_CUR_ADAPT )
ENDIF ( )
MDEV-17958 Make bug-endian innodb_checksum_algorithm=crc32 optional
In MySQL 5.7, it was noticed that files are not portable between
big-endian and little-endian processor architectures
(such as SPARC and x86), because the original implementation of
innodb_checksum_algorithm=crc32 was not byte order agnostic.
A byte order agnostic implementation of innodb_checksum_algorithm=crc32
was only added to MySQL 5.7, not backported to 5.6. Consequently,
MariaDB Server versions 10.0 and 10.1 only contain the CRC-32C
implementation that works incorrectly on big-endian architectures,
and MariaDB Server 10.2.2 got the byte-order agnostic CRC-32C
implementation from MySQL 5.7.
MySQL 5.7 introduced a "legacy crc32" variant that is functionally
equivalent to the big-endian version of the original crc32 implementation.
Thanks to this variant, old data files can be transferred from big-endian
systems to newer versions.
Introducing new variants of checksum algorithms (without introducing
new names for them, or something on the pages themselves to identify
the algorithm) generally is a bad idea, because each checksum algorithm
is like a lottery ticket. The more algorithms you try, the more likely
it will be for the checksum to match on a corrupted page.
So, essentially MySQL 5.7 weakened innodb_checksum_algorithm=crc32,
and MariaDB 10.2.2 inherited this weakening.
We introduce a build option that together with MDEV-17957
makes innodb_checksum_algorithm=strict_crc32 strict again
by only allowing one variant of the checksum to match.
WITH_INNODB_BUG_ENDIAN_CRC32: A new cmake option for enabling the
bug-compatible "legacy crc32" checksum. This is only enabled on
big-endian systems by default, to facilitate an upgrade from
MariaDB 10.0 or 10.1. Checked by #ifdef INNODB_BUG_ENDIAN_CRC32.
ut_crc32_byte_by_byte: Remove (unused function).
legacy_big_endian_checksum: Remove. This variable seems to have
unnecessarily complicated the logic. When the weakening is enabled,
we must always fall back to the buggy checksum.
buf_page_check_crc32(): A helper function to compute one or
two CRC-32C variants.
2018-12-13 16:57:10 +01:00
OPTION ( WITH_INNODB_BUG_ENDIAN_CRC32 "Weaken innodb_checksum_algorithm=crc32 by supporting upgrade from big-endian systems running 5.6/10.0/10.1" ${ IS_BIG_ENDIAN } )
IF ( WITH_INNODB_BUG_ENDIAN_CRC32 )
ADD_DEFINITIONS ( -DINNODB_BUG_ENDIAN_CRC32 )
ENDIF ( )
2016-08-12 10:17:45 +02:00
OPTION ( WITH_INNODB_EXTRA_DEBUG "Enable extra InnoDB debug checks" OFF )
IF ( WITH_INNODB_EXTRA_DEBUG )
2018-04-30 12:45:25 +02:00
ADD_DEFINITIONS ( -DUNIV_ZIP_DEBUG )
2016-08-12 10:17:45 +02:00
ENDIF ( )
CHECK_FUNCTION_EXISTS ( sched_getcpu HAVE_SCHED_GETCPU )
IF ( HAVE_SCHED_GETCPU )
ADD_DEFINITIONS ( -DHAVE_SCHED_GETCPU=1 )
ENDIF ( )
CHECK_FUNCTION_EXISTS ( nanosleep HAVE_NANOSLEEP )
IF ( HAVE_NANOSLEEP )
ADD_DEFINITIONS ( -DHAVE_NANOSLEEP=1 )
ENDIF ( )
IF ( HAVE_FALLOC_PUNCH_HOLE_AND_KEEP_SIZE )
ADD_DEFINITIONS ( -DHAVE_FALLOC_PUNCH_HOLE_AND_KEEP_SIZE=1 )
ENDIF ( )
IF ( NOT MSVC )
2019-03-27 11:26:11 +01:00
# Work around MDEV-18417, MDEV-18656, MDEV-18417
IF ( WITH_ASAN AND CMAKE_COMPILER_IS_GNUCC AND
C M A K E _ C _ C O M P I L E R _ V E R S I O N V E R S I O N _ L E S S " 6 . 0 . 0 " )
SET_SOURCE_FILES_PROPERTIES ( trx/trx0rec.cc PROPERTIES COMPILE_FLAGS -O1 )
ENDIF ( )
2016-08-12 10:17:45 +02:00
# Only use futexes on Linux if GCC atomics are available
IF ( NOT MSVC AND NOT CMAKE_CROSSCOMPILING )
CHECK_C_SOURCE_RUNS (
"
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include <assert.h>
#include <linux/futex.h>
#include <unistd.h>
#include <sys/syscall.h>
i n t futex_wait ( int* futex, int v ) {
return ( syscall(SYS_futex, futex, FUTEX_WAIT_PRIVATE, v, NULL, NULL, 0 ) ) ;
}
i n t futex_signal ( int* futex ) {
return ( syscall(SYS_futex, futex, FUTEX_WAKE, 1, NULL, NULL, 0 ) ) ;
}
i n t main ( ) {
i n t r e t ;
i n t m = 1 ;
/ * I t i s s e t u p t o f a i l a n d r e t u r n E W O U L D B L O C K . * /
r e t = futex_wait ( &m, 0 ) ;
assert ( ret == -1 && errno == EWOULDBLOCK ) ;
/ * S h o u l d n ' t w a k e u p a n y t h r e a d s . * /
assert ( futex_signal(&m ) = = 0 ) ;
return ( 0 ) ;
} "
H A V E _ I B _ L I N U X _ F U T E X )
ENDIF ( )
2016-09-06 08:43:16 +02:00
2016-08-12 10:17:45 +02:00
IF ( HAVE_IB_LINUX_FUTEX )
ADD_DEFINITIONS ( -DHAVE_IB_LINUX_FUTEX=1 )
ENDIF ( )
ENDIF ( NOT MSVC )
CHECK_FUNCTION_EXISTS ( vasprintf HAVE_VASPRINTF )
2016-09-06 08:43:16 +02:00
CHECK_CXX_SOURCE_COMPILES ( "struct t1{ int a; char *b; }; struct t1 c= { .a=1, .b=0 }; main() { }" HAVE_C99_INITIALIZERS )
IF ( HAVE_C99_INITIALIZERS )
ADD_DEFINITIONS ( -DHAVE_C99_INITIALIZERS )
ENDIF ( )
SET ( MUTEXTYPE "event" CACHE STRING "Mutex type: event, sys or futex" )
2016-08-12 10:17:45 +02:00
IF ( MUTEXTYPE MATCHES "event" )
ADD_DEFINITIONS ( -DMUTEX_EVENT )
ELSEIF ( MUTEXTYPE MATCHES "futex" AND DEFINED HAVE_IB_LINUX_FUTEX )
ADD_DEFINITIONS ( -DMUTEX_FUTEX )
ELSE ( )
ADD_DEFINITIONS ( -DMUTEX_SYS )
ENDIF ( )
2017-02-23 22:05:12 +01:00
2018-03-29 23:41:05 +02:00
OPTION ( WITH_INNODB_DISALLOW_WRITES "InnoDB freeze writes patch from Google" ${ WITH_WSREP } )
IF ( WITH_INNODB_DISALLOW_WRITES )
ADD_DEFINITIONS ( -DWITH_INNODB_DISALLOW_WRITES )
ENDIF ( )
2016-09-06 08:43:16 +02:00
# Include directories under innobase
INCLUDE_DIRECTORIES ( ${ CMAKE_SOURCE_DIR } /storage/innobase/include
$ { C M A K E _ S O U R C E _ D I R } / s t o r a g e / i n n o b a s e / h a n d l e r )
# Sun Studio bug with -xO2
IF ( CMAKE_CXX_COMPILER_ID MATCHES "SunPro"
A N D C M A K E _ C X X _ F L A G S _ R E L E A S E M A T C H E S " O 2 "
A N D N O T C M A K E _ B U I L D _ T Y P E S T R E Q U A L " D e b u g " )
# Sun Studio 12 crashes with -xO2 flag, but not with higher optimization
# -xO3
SET_SOURCE_FILES_PROPERTIES ( ${ CMAKE_CURRENT_SOURCE_DIR } /rem/rem0rec.cc
P R O P E R T I E S C O M P I L E _ F L A G S - x O 3 )
ENDIF ( )
2017-03-27 11:03:23 +02:00
# Avoid generating Hardware Capabilities due to crc32 instructions
IF ( CMAKE_SYSTEM_NAME MATCHES "SunOS" AND CMAKE_SYSTEM_PROCESSOR MATCHES "i386" )
2018-04-03 14:14:00 +02:00
MY_CHECK_CXX_COMPILER_FLAG ( "-Wa,-nH" )
IF ( have_CXX__Wa__nH )
2017-03-27 11:03:23 +02:00
ADD_COMPILE_FLAGS (
u t / u t 0 c r c 3 2 . c c
C O M P I L E _ F L A G S " - W a , - n H "
)
ENDIF ( )
ENDIF ( )
2016-09-06 08:43:16 +02:00
IF ( MSVC )
# Avoid "unreferenced label" warning in generated file
GET_FILENAME_COMPONENT ( _SRC_DIR ${ CMAKE_CURRENT_LIST_FILE } PATH )
SET_SOURCE_FILES_PROPERTIES ( ${ _SRC_DIR } /pars/pars0grm.c
P R O P E R T I E S C O M P I L E _ F L A G S " / w d 4 1 0 2 " )
SET_SOURCE_FILES_PROPERTIES ( ${ _SRC_DIR } /pars/lexyy.c
P R O P E R T I E S C O M P I L E _ F L A G S " / w d 4 0 0 3 " )
ENDIF ( )
2016-08-12 10:17:45 +02:00
# Include directories under innobase
INCLUDE_DIRECTORIES ( ${ CMAKE_SOURCE_DIR } /storage/innobase/include
$ { C M A K E _ S O U R C E _ D I R } / s t o r a g e / i n n o b a s e / h a n d l e r
$ { C M A K E _ S O U R C E _ D I R } / l i b b i n l o g e v e n t s / i n c l u d e )