1 # Copyright 1999-2015 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
4 # @ECLASS: mysql-cmake.eclass
7 # - MySQL Team <mysql-bugs@gentoo.org>
8 # - Robin H. Johnson <robbat2@gentoo.org>
9 # - Jorge Manuel B. S. Vicetto <jmbsvicetto@gentoo.org>
10 # - Brian Evans <grknight@gentoo.org>
11 # @BLURB: This eclass provides the support for cmake based mysql releases
13 # The mysql-cmake.eclass provides the support to build the mysql
14 # ebuilds using the cmake build system. This eclass provides
15 # the src_prepare, src_configure, src_compile, and src_install
18 inherit cmake-utils flag-o-matic multilib prefix eutils toolchain-funcs versionator
24 # @FUNCTION: mysql_cmake_disable_test
26 # Helper function to disable specific tests.
27 mysql-cmake_disable_test() {
29 local rawtestname testname testsuite reason mysql_disabled_file mysql_disabled_dir
30 rawtestname="${1}" ; shift
32 ewarn "test '${rawtestname}' disabled: '${reason}'"
34 testsuite="${rawtestname/.*}"
35 testname="${rawtestname/*.}"
36 for mysql_disabled_file in \
37 ${S}/mysql-test/disabled.def \
38 ${S}/mysql-test/t/disabled.def ; do
39 [[ -f ${mysql_disabled_file} ]] && break
41 #mysql_disabled_file="${S}/mysql-test/t/disabled.def"
42 #einfo "rawtestname=${rawtestname} testname=${testname} testsuite=${testsuite}"
43 echo ${testname} : ${reason} >> "${mysql_disabled_file}"
45 if [[ ( -n ${testsuite} ) && ( ${testsuite} != "main" ) ]]; then
46 for mysql_disabled_file in \
47 ${S}/mysql-test/suite/${testsuite}/disabled.def \
48 ${S}/mysql-test/suite/${testsuite}/t/disabled.def \
50 [[ -f ${mysql_disabled_file} ]] && break
52 if [[ ${mysql_disabled_file} != "FAILED" ]]; then
53 echo "${testname} : ${reason}" >> "${mysql_disabled_file}"
55 for mysql_disabled_dir in \
56 ${S}/mysql-test/suite/${testsuite} \
57 ${S}/mysql-test/suite/${testsuite}/t \
59 [[ -d ${mysql_disabled_dir} ]] && break
61 if [[ ${mysql_disabled_dir} != "FAILED" ]]; then
62 echo "${testname} : ${reason}" >> "${mysql_disabled_dir}/disabled.def"
64 ewarn "Could not find testsuite disabled.def location for ${rawtestname}"
70 # @FUNCTION: mysql-cmake_use_plugin
72 # Helper function to enable/disable plugins by use flags
73 # cmake-utils_use_with is not enough as some references check WITH_ (0|1)
74 # and some check WITHOUT_. Also, this can easily extend to non-storage plugins.
75 mysql-cmake_use_plugin() {
76 [[ -z $2 ]] && die "mysql-cmake_use_plugin <USE flag> <flag name>"
77 if use_if_iuse $1 ; then
78 echo "-DWITH_$2=1 -DPLUGIN_$2=YES"
80 echo "-DWITHOUT_$2=1 -DWITH_$2=0 -DPLUGIN_$2=NO"
84 # @FUNCTION: configure_cmake_locale
86 # Helper function to configure locale cmake options
87 configure_cmake_locale() {
89 if use_if_iuse minimal ; then
91 elif ! in_iuse server || use_if_iuse server ; then
92 if [[ ( -n ${MYSQL_DEFAULT_CHARSET} ) && ( -n ${MYSQL_DEFAULT_COLLATION} ) ]]; then
93 ewarn "You are using a custom charset of ${MYSQL_DEFAULT_CHARSET}"
94 ewarn "and a collation of ${MYSQL_DEFAULT_COLLATION}."
95 ewarn "You MUST file bugs without these variables set."
98 -DDEFAULT_CHARSET=${MYSQL_DEFAULT_CHARSET}
99 -DDEFAULT_COLLATION=${MYSQL_DEFAULT_COLLATION}
102 elif ! use latin1 ; then
104 -DDEFAULT_CHARSET=utf8
105 -DDEFAULT_COLLATION=utf8_general_ci
109 -DDEFAULT_CHARSET=latin1
110 -DDEFAULT_COLLATION=latin1_swedish_ci
116 # @FUNCTION: configure_cmake_minimal
118 # Helper function to configure minimal build
119 configure_cmake_minimal() {
123 -DWITHOUT_EMBEDDED_SERVER=1
124 -DEXTRA_CHARSETS=none
125 -DINSTALL_SQLBENCHDIR=
126 -DWITHOUT_ARCHIVE_STORAGE_ENGINE=1
127 -DWITHOUT_BLACKHOLE_STORAGE_ENGINE=1
128 -DWITHOUT_CSV_STORAGE_ENGINE=1
129 -DWITHOUT_FEDERATED_STORAGE_ENGINE=1
130 -DWITHOUT_HEAP_STORAGE_ENGINE=1
131 -DWITHOUT_INNOBASE_STORAGE_ENGINE=1
132 -DWITHOUT_MYISAMMRG_STORAGE_ENGINE=1
133 -DWITHOUT_MYISAM_STORAGE_ENGINE=1
134 -DWITHOUT_PARTITION_STORAGE_ENGINE=1
136 -DPLUGIN_BLACKHOLE=NO
138 -DPLUGIN_FEDERATED=NO
141 -DPLUGIN_MYISAMMRG=NO
143 -DPLUGIN_PARTITION=NO
147 # @FUNCTION: configure_cmake_standard
149 # Helper function to configure standard build
150 configure_cmake_standard() {
155 -DMYSQL_UNIX_ADDR=${EPREFIX}/var/run/mysqld/mysqld.sock
156 $(cmake-utils_use_disable !static SHARED)
157 $(cmake-utils_use_with debug)
158 $(cmake-utils_use_with embedded EMBEDDED_SERVER)
159 $(cmake-utils_use_with profiling)
160 $(cmake-utils_use_enable systemtap DTRACE)
164 mycmakeargs+=( -DWITH_PIC=1 )
167 if use jemalloc; then
168 mycmakeargs+=( -DWITH_SAFEMALLOC=OFF )
171 if use tcmalloc; then
172 mycmakeargs+=( -DWITH_SAFEMALLOC=OFF )
177 -DWITH_ARCHIVE_STORAGE_ENGINE=1
178 -DWITH_BLACKHOLE_STORAGE_ENGINE=1
179 -DWITH_CSV_STORAGE_ENGINE=1
180 -DWITH_HEAP_STORAGE_ENGINE=1
181 -DWITH_INNOBASE_STORAGE_ENGINE=1
182 -DWITH_MYISAMMRG_STORAGE_ENGINE=1
183 -DWITH_MYISAM_STORAGE_ENGINE=1
184 -DWITH_PARTITION_STORAGE_ENGINE=1
187 if in_iuse pbxt ; then
188 mycmakeargs+=( $(cmake-utils_use_with pbxt PBXT_STORAGE_ENGINE) )
191 if [[ ${PN} == "mariadb" || ${PN} == "mariadb-galera" ]]; then
193 # Federated{,X} must be treated special otherwise they will not be built as plugins
194 if ! use extraengine ; then
196 -DWITHOUT_FEDERATED_STORAGE_ENGINE=1
197 -DPLUGIN_FEDERATED=NO
198 -DWITHOUT_FEDERATEDX_STORAGE_ENGINE=1
199 -DPLUGIN_FEDERATEDX=NO )
203 $(mysql-cmake_use_plugin oqgraph OQGRAPH)
204 $(mysql-cmake_use_plugin sphinx SPHINX)
205 $(mysql-cmake_use_plugin tokudb TOKUDB)
206 $(mysql-cmake_use_plugin pam AUTH_PAM)
209 if mysql_version_is_at_least 10.0.5 ; then
210 # CassandraSE needs Apache Thrift which is not in portage
212 -DWITHOUT_CASSANDRA=1 -DWITH_CASSANDRA=0
213 -DPLUGIN_CASSANDRA=NO
214 $(mysql-cmake_use_plugin extraengine SEQUENCE)
215 $(mysql-cmake_use_plugin extraengine SPIDER)
216 $(mysql-cmake_use_plugin extraengine CONNECT)
217 -DCONNECT_WITH_MYSQL=1
218 $(cmake-utils_use xml CONNECT_WITH_LIBXML2)
219 $(cmake-utils_use odbc CONNECT_WITH_ODBC)
223 if in_iuse mroonga ; then
224 use mroonga || mycmakeargs+=( -DWITHOUT_MROONGA=1 )
226 mycmakeargs+=( -DWITHOUT_MROONGA=1 )
229 if in_iuse galera ; then
230 mycmakeargs+=( $(cmake-utils_use_with galera WSREP) )
233 if mysql_version_is_at_least "10.1.1" ; then
234 mycmakeargs+=( $(cmake-utils_use_with innodb-lz4 INNODB_LZ4)
235 $(cmake-utils_use_with innodb-lzo INNODB_LZO) )
238 if in_iuse innodb-snappy ; then
239 mycmakeargs+=( $(cmake-utils_use_with innodb-snappy INNODB_SNAPPY) )
242 if mysql_version_is_at_least "10.1.2" ; then
243 mycmakeargs+=( $(mysql-cmake_use_plugin cracklib CRACKLIB_PASSWORD_CHECK ) )
246 # The build forces this to be defined when cross-compiling. We pass it
247 # all the time for simplicity and to make sure it is actually correct.
248 mycmakeargs+=( -DSTACK_DIRECTION=$(tc-stack-grows-down && echo -1 || echo 1) )
250 mycmakeargs+=( $(cmake-utils_use_with extraengine FEDERATED_STORAGE_ENGINE) )
253 if [[ ${PN} == "percona-server" ]]; then
255 $(cmake-utils_use_with pam PAM)
257 if in_iuse tokudb ; then
258 # TokuDB Backup plugin requires valgrind unconditionally
260 $(mysql-cmake_use_plugin tokudb TOKUDB)
261 $(usex tokudb-backup-plugin "" -DTOKUDB_BACKUP_DISABLED=1)
266 if [[ ${PN} == "mysql-cluster" ]]; then
267 # TODO: This really should include the following options,
268 # but the memcached package doesn't install the files it seeks.
269 # -DWITH_BUNDLED_MEMCACHED=OFF
270 # -DMEMCACHED_HOME=${EPREFIX}/usr
272 -DWITH_BUNDLED_LIBEVENT=OFF
273 $(cmake-utils_use_with java NDB_JAVA)
282 # @FUNCTION: mysql-cmake_src_prepare
284 # Apply patches to the source code and remove unneeded bundled libs.
285 mysql-cmake_src_prepare() {
287 debug-print-function ${FUNCNAME} "$@"
291 if [[ ${MY_EXTRAS_VER} != none ]]; then
293 # Apply the patches for this MySQL version
294 EPATCH_SUFFIX="patch"
295 mkdir -p "${EPATCH_SOURCE}" || die "Unable to create epatch directory"
296 # Clean out old items
297 rm -f "${EPATCH_SOURCE}"/*
298 # Now link in right patches
304 # last -fPIC fixup, per bug #305873
305 i="${S}"/storage/innodb_plugin/plug.in
306 [[ -f ${i} ]] && sed -i -e '/CFLAGS/s,-prefer-non-pic,,g' "${i}"
308 rm -f "scripts/mysqlbug"
309 if use jemalloc && ! ( [[ ${PN} == "mariadb" ]] && mysql_version_is_at_least "5.5.33" ); then
310 echo "TARGET_LINK_LIBRARIES(mysqld jemalloc)" >> "${S}/sql/CMakeLists.txt" || die
313 if use tcmalloc; then
314 echo "TARGET_LINK_LIBRARIES(mysqld tcmalloc)" >> "${S}/sql/CMakeLists.txt"
317 if in_iuse tokudb ; then
318 # Don't build bundled xz-utils
319 if [[ -d "${S}/storage/tokudb/ft-index" ]] ; then
320 rm -f "${S}/storage/tokudb/ft-index/cmake_modules/TokuThirdParty.cmake" || die
321 touch "${S}/storage/tokudb/ft-index/cmake_modules/TokuThirdParty.cmake" || die
322 sed -i 's/ build_lzma//' "${S}/storage/tokudb/ft-index/ft/CMakeLists.txt" || die
323 elif [[ -d "${S}/storage/tokudb/PerconaFT" ]] ; then
324 rm "${S}/storage/tokudb/PerconaFT/cmake_modules/TokuThirdParty.cmake" || die
325 touch "${S}/storage/tokudb/PerconaFT/cmake_modules/TokuThirdParty.cmake" || die
326 sed -i -e 's/ build_lzma//' -e 's/ build_snappy//' "${S}/storage/tokudb/PerconaFT/ft/CMakeLists.txt" || die
327 sed -i -e 's/add_dependencies\(tokuportability_static_conv build_jemalloc\)//' "${S}/storage/tokudb/PerconaFT/portability/CMakeLists.txt" || die
330 if [[ -d "${S}/plugin/tokudb-backup-plugin" ]] && ! use tokudb-backup-plugin ; then
331 rm -r "${S}/plugin/tokudb-backup-plugin/Percona-TokuBackup" || die
335 # Remove the bundled groonga if it exists
336 # There is no CMake flag, it simply checks for existance
337 if [[ -d "${S}"/storage/mroonga/vendor/groonga ]] ; then
338 rm -r "${S}"/storage/mroonga/vendor/groonga || die "could not remove packaged groonga"
341 cmake-utils_src_prepare
344 # @FUNCTION: mysql-cmake_src_configure
346 # Configure mysql to build the code for Gentoo respecting the use flags.
347 mysql-cmake_src_configure() {
349 debug-print-function ${FUNCNAME} "$@"
351 CMAKE_BUILD_TYPE="RelWithDebInfo"
353 # debug hack wrt #497532
355 -DCMAKE_C_FLAGS_RELWITHDEBINFO="$(usex debug "" "-DNDEBUG")"
356 -DCMAKE_CXX_FLAGS_RELWITHDEBINFO="$(usex debug "" "-DNDEBUG")"
357 -DCMAKE_INSTALL_PREFIX=${EPREFIX}/usr
358 -DMYSQL_DATADIR=${EPREFIX}/var/lib/mysql
359 -DSYSCONFDIR=${EPREFIX}/etc/mysql
361 -DINSTALL_DOCDIR=share/doc/${P}
362 -DINSTALL_DOCREADMEDIR=share/doc/${P}
363 -DINSTALL_INCLUDEDIR=include/mysql
364 -DINSTALL_INFODIR=share/info
365 -DINSTALL_LIBDIR=$(get_libdir)
366 -DINSTALL_ELIBDIR=$(get_libdir)/mysql
367 -DINSTALL_MANDIR=share/man
368 -DINSTALL_MYSQLDATADIR=${EPREFIX}/var/lib/mysql
369 -DINSTALL_MYSQLSHAREDIR=share/mysql
370 -DINSTALL_MYSQLTESTDIR=share/mysql/mysql-test
371 -DINSTALL_PLUGINDIR=$(get_libdir)/mysql/plugin
372 -DINSTALL_SBINDIR=sbin
373 -DINSTALL_SCRIPTDIR=share/mysql/scripts
374 -DINSTALL_SQLBENCHDIR=share/mysql
375 -DINSTALL_SUPPORTFILESDIR=${EPREFIX}/usr/share/mysql
376 -DWITH_COMMENT="Gentoo Linux ${PF}"
377 $(cmake-utils_use_with test UNIT_TESTS)
381 -DENABLED_LOCAL_INFILE=1
382 $(cmake-utils_use_enable static-libs STATIC_LIBS)
383 -DWITH_SSL=$(usex ssl system bundled)
384 -DWITH_DEFAULT_COMPILER_OPTIONS=0
385 -DWITH_DEFAULT_FEATURE_SET=0
388 if in_iuse bindist ; then
390 -DWITH_READLINE=$(usex bindist 1 0)
391 -DNOT_FOR_DISTRIBUTION=$(usex bindist 0 1)
392 $(usex bindist -DHAVE_BFD_H=0 '')
396 mycmakeargs+=( -DWITH_EDITLINE=system )
398 if [[ ${PN} == "mariadb" || ${PN} == "mariadb-galera" ]] ; then
400 -DWITH_JEMALLOC=$(usex jemalloc system)
402 mysql_version_is_at_least "10.0.9" && mycmakeargs+=( -DWITH_PCRE=system )
405 configure_cmake_locale
407 if use_if_iuse minimal ; then
408 configure_cmake_minimal
410 configure_cmake_standard
413 # Bug #114895, bug #110149
414 filter-flags "-O" "-O[01]"
416 CXXFLAGS="${CXXFLAGS} -fno-strict-aliasing"
417 CXXFLAGS="${CXXFLAGS} -felide-constructors"
418 # Causes linkage failures. Upstream bug #59607 removes it
419 if ! mysql_version_is_at_least "5.6" ; then
420 CXXFLAGS="${CXXFLAGS} -fno-implicit-templates"
422 # As of 5.7, exceptions and rtti are used!
423 if [[ ${PN} -eq 'percona-server' ]] && mysql_version_is_at_least "5.6.26" ; then
424 CXXFLAGS="${CXXFLAGS} -fno-rtti"
425 elif ! mysql_version_is_at_least "5.7" ; then
426 CXXFLAGS="${CXXFLAGS} -fno-exceptions -fno-rtti"
430 # bug #283926, with GCC4.4, this is required to get correct behavior.
431 append-flags -fno-strict-aliasing
433 cmake-utils_src_configure
436 # @FUNCTION: mysql-cmake_src_compile
438 # Compile the mysql code.
439 mysql-cmake_src_compile() {
441 debug-print-function ${FUNCNAME} "$@"
443 cmake-utils_src_compile
446 # @FUNCTION: mysql-cmake_src_install
449 mysql-cmake_src_install() {
451 debug-print-function ${FUNCNAME} "$@"
453 # Make sure the vars are correctly initialized
456 cmake-utils_src_install
458 if ! in_iuse tools || use_if_iuse tools ; then
460 einfo "Making Convenience links for mysqlcheck multi-call binary"
461 dosym "/usr/bin/mysqlcheck" "/usr/bin/mysqlanalyze"
462 dosym "/usr/bin/mysqlcheck" "/usr/bin/mysqlrepair"
463 dosym "/usr/bin/mysqlcheck" "/usr/bin/mysqloptimize"
466 # Create a mariadb_config symlink
467 [[ ${PN} == "mariadb" || ${PN} == "mariadb-galera" ]] && dosym "/usr/bin/mysql_config" "/usr/bin/mariadb_config"
469 # INSTALL_LAYOUT=STANDALONE causes cmake to create a /usr/data dir
470 rm -Rf "${ED}/usr/data"
472 # Various junk (my-*.cnf moved elsewhere)
473 einfo "Removing duplicate /usr/share/mysql files"
475 # Unless they explicitly specific USE=test, then do not install the
476 # testsuite. It DOES have a use to be installed, esp. when you want to do a
477 # validation of your database configuration after tuning it.
479 rm -rf "${D}"/${MY_SHAREDSTATEDIR}/mysql-test
482 # Configuration stuff
483 case ${MYSQL_PV_MAJOR} in
484 5.[1-4]*) mysql_mycnf_version="5.1" ;;
485 5.5) mysql_mycnf_version="5.5" ;;
486 5.[6-9]|6*|7*|8*|9*|10*) mysql_mycnf_version="5.6" ;;
488 einfo "Building default my.cnf (${mysql_mycnf_version})"
489 insinto "${MY_SYSCONFDIR#${EPREFIX}}"
490 [[ -f "${S}/scripts/mysqlaccess.conf" ]] && doins "${S}"/scripts/mysqlaccess.conf
491 mycnf_src="my.cnf-${mysql_mycnf_version}"
492 sed -e "s!@DATADIR@!${MY_DATADIR}!g" \
493 "${FILESDIR}/${mycnf_src}" \
494 > "${TMPDIR}/my.cnf.ok" || die
495 use prefix && sed -i -r -e '/^user[[:space:]]*=[[:space:]]*mysql$/d' "${TMPDIR}/my.cnf.ok"
498 -e "/character-set/s|utf8|latin1|g" \
499 "${TMPDIR}/my.cnf.ok" || die
501 eprefixify "${TMPDIR}/my.cnf.ok"
502 newins "${TMPDIR}/my.cnf.ok" my.cnf
504 # Minimal builds don't have the MySQL server
505 if use_if_iuse minimal ; then
507 elif ! in_iuse server || use_if_iuse server; then
508 einfo "Including support files and sample configurations"
509 docinto "support-files"
511 "${S}"/support-files/my-*.cnf.sh \
512 "${S}"/support-files/magic \
513 "${S}"/support-files/ndb-config-2-node.ini.sh
515 [[ -f $script ]] && dodoc "${script}"
519 for script in "${S}"/scripts/mysql* ; do
520 [[ ( -f $script ) && ( ${script%.sh} == ${script} ) ]] && dodoc "${script}"
524 #Remove mytop if perl is not selected
525 [[ ${PN} == "mariadb" || ${PN} == "mariadb-galera" ]] && ! use perl \
526 && rm -f "${ED}/usr/bin/mytop"
528 in_iuse client-libs && ! use client-libs && return
530 # Percona has decided to rename libmysqlclient to libperconaserverclient
531 # Use a symlink to preserve linkages for those who don't use mysql_config
532 if [[ ${PN} == "percona-server" ]] && mysql_version_is_at_least "5.5.36" ; then
533 dosym libperconaserverclient.so /usr/$(get_libdir)/libmysqlclient.so
534 dosym libperconaserverclient.so /usr/$(get_libdir)/libmysqlclient_r.so
535 if use static-libs ; then
536 dosym libperconaserverclient.a /usr/$(get_libdir)/libmysqlclient.a
537 dosym libperconaserverclient.a /usr/$(get_libdir)/libmysqlclient_r.a