1 # Copyright 1999-2015 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
5 # @ECLASS: mysql-cmake.eclass
8 # - MySQL Team <mysql-bugs@gentoo.org>
9 # - Robin H. Johnson <robbat2@gentoo.org>
10 # - Jorge Manuel B. S. Vicetto <jmbsvicetto@gentoo.org>
11 # - Brian Evans <grknight@gentoo.org>
12 # @BLURB: This eclass provides the support for cmake based mysql releases
14 # The mysql-cmake.eclass provides the support to build the mysql
15 # ebuilds using the cmake build system. This eclass provides
16 # the src_prepare, src_configure, src_compile, and src_install
19 inherit cmake-utils flag-o-matic multilib prefix eutils
25 # @FUNCTION: mysql_cmake_disable_test
27 # Helper function to disable specific tests.
28 mysql-cmake_disable_test() {
30 local rawtestname testname testsuite reason mysql_disabled_file mysql_disabled_dir
31 rawtestname="${1}" ; shift
33 ewarn "test '${rawtestname}' disabled: '${reason}'"
35 testsuite="${rawtestname/.*}"
36 testname="${rawtestname/*.}"
37 for mysql_disabled_file in \
38 ${S}/mysql-test/disabled.def \
39 ${S}/mysql-test/t/disabled.def ; do
40 [[ -f ${mysql_disabled_file} ]] && break
42 #mysql_disabled_file="${S}/mysql-test/t/disabled.def"
43 #einfo "rawtestname=${rawtestname} testname=${testname} testsuite=${testsuite}"
44 echo ${testname} : ${reason} >> "${mysql_disabled_file}"
46 if [[ ( -n ${testsuite} ) && ( ${testsuite} != "main" ) ]]; then
47 for mysql_disabled_file in \
48 ${S}/mysql-test/suite/${testsuite}/disabled.def \
49 ${S}/mysql-test/suite/${testsuite}/t/disabled.def \
51 [[ -f ${mysql_disabled_file} ]] && break
53 if [[ ${mysql_disabled_file} != "FAILED" ]]; then
54 echo "${testname} : ${reason}" >> "${mysql_disabled_file}"
56 for mysql_disabled_dir in \
57 ${S}/mysql-test/suite/${testsuite} \
58 ${S}/mysql-test/suite/${testsuite}/t \
60 [[ -d ${mysql_disabled_dir} ]] && break
62 if [[ ${mysql_disabled_dir} != "FAILED" ]]; then
63 echo "${testname} : ${reason}" >> "${mysql_disabled_dir}/disabled.def"
65 ewarn "Could not find testsuite disabled.def location for ${rawtestname}"
71 # @FUNCTION: mysql-cmake_use_plugin
73 # Helper function to enable/disable plugins by use flags
74 # cmake-utils_use_with is not enough as some references check WITH_ (0|1)
75 # and some check WITHOUT_. Also, this can easily extend to non-storage plugins.
76 mysql-cmake_use_plugin() {
77 [[ -z $2 ]] && die "mysql-cmake_use_plugin <USE flag> <flag name>"
78 if use_if_iuse $1 ; then
79 echo "-DWITH_$2=1 -DPLUGIN_$2=YES"
81 echo "-DWITHOUT_$2=1 -DWITH_$2=0 -DPLUGIN_$2=NO"
85 # @FUNCTION: configure_cmake_locale
87 # Helper function to configure locale cmake options
88 configure_cmake_locale() {
90 if use_if_iuse minimal ; then
92 elif ! in_iuse server || use_if_iuse server ; then
93 if [[ ( -n ${MYSQL_DEFAULT_CHARSET} ) && ( -n ${MYSQL_DEFAULT_COLLATION} ) ]]; then
94 ewarn "You are using a custom charset of ${MYSQL_DEFAULT_CHARSET}"
95 ewarn "and a collation of ${MYSQL_DEFAULT_COLLATION}."
96 ewarn "You MUST file bugs without these variables set."
99 -DDEFAULT_CHARSET=${MYSQL_DEFAULT_CHARSET}
100 -DDEFAULT_COLLATION=${MYSQL_DEFAULT_COLLATION}
103 elif ! use latin1 ; then
105 -DDEFAULT_CHARSET=utf8
106 -DDEFAULT_COLLATION=utf8_general_ci
110 -DDEFAULT_CHARSET=latin1
111 -DDEFAULT_COLLATION=latin1_swedish_ci
117 # @FUNCTION: configure_cmake_minimal
119 # Helper function to configure minimal build
120 configure_cmake_minimal() {
124 -DWITHOUT_EMBEDDED_SERVER=1
125 -DEXTRA_CHARSETS=none
126 -DINSTALL_SQLBENCHDIR=
127 -DWITHOUT_ARCHIVE_STORAGE_ENGINE=1
128 -DWITHOUT_BLACKHOLE_STORAGE_ENGINE=1
129 -DWITHOUT_CSV_STORAGE_ENGINE=1
130 -DWITHOUT_FEDERATED_STORAGE_ENGINE=1
131 -DWITHOUT_HEAP_STORAGE_ENGINE=1
132 -DWITHOUT_INNOBASE_STORAGE_ENGINE=1
133 -DWITHOUT_MYISAMMRG_STORAGE_ENGINE=1
134 -DWITHOUT_MYISAM_STORAGE_ENGINE=1
135 -DWITHOUT_PARTITION_STORAGE_ENGINE=1
137 -DPLUGIN_BLACKHOLE=NO
139 -DPLUGIN_FEDERATED=NO
142 -DPLUGIN_MYISAMMRG=NO
144 -DPLUGIN_PARTITION=NO
148 # @FUNCTION: configure_cmake_standard
150 # Helper function to configure standard build
151 configure_cmake_standard() {
156 -DMYSQL_UNIX_ADDR=${EPREFIX}/var/run/mysqld/mysqld.sock
157 $(cmake-utils_use_disable !static SHARED)
158 $(cmake-utils_use_with debug)
159 $(cmake-utils_use_with embedded EMBEDDED_SERVER)
160 $(cmake-utils_use_with profiling)
161 $(cmake-utils_use_enable systemtap DTRACE)
165 mycmakeargs+=( -DWITH_PIC=1 )
168 if use jemalloc; then
169 mycmakeargs+=( -DWITH_SAFEMALLOC=OFF )
172 if use tcmalloc; then
173 mycmakeargs+=( -DWITH_SAFEMALLOC=OFF )
178 -DWITH_ARCHIVE_STORAGE_ENGINE=1
179 -DWITH_BLACKHOLE_STORAGE_ENGINE=1
180 -DWITH_CSV_STORAGE_ENGINE=1
181 -DWITH_HEAP_STORAGE_ENGINE=1
182 -DWITH_INNOBASE_STORAGE_ENGINE=1
183 -DWITH_MYISAMMRG_STORAGE_ENGINE=1
184 -DWITH_MYISAM_STORAGE_ENGINE=1
185 -DWITH_PARTITION_STORAGE_ENGINE=1
188 if in_iuse pbxt ; then
189 mycmakeargs+=( $(cmake-utils_use_with pbxt PBXT_STORAGE_ENGINE) )
192 if [[ ${PN} == "mariadb" || ${PN} == "mariadb-galera" ]]; then
194 # Federated{,X} must be treated special otherwise they will not be built as plugins
195 if ! use extraengine ; then
197 -DWITHOUT_FEDERATED_STORAGE_ENGINE=1
198 -DPLUGIN_FEDERATED=NO
199 -DWITHOUT_FEDERATEDX_STORAGE_ENGINE=1
200 -DPLUGIN_FEDERATEDX=NO )
204 $(mysql-cmake_use_plugin oqgraph OQGRAPH)
205 $(mysql-cmake_use_plugin sphinx SPHINX)
206 $(mysql-cmake_use_plugin tokudb TOKUDB)
207 $(mysql-cmake_use_plugin pam AUTH_PAM)
210 if mysql_version_is_at_least 10.0.5 ; then
211 # CassandraSE needs Apache Thrift which is not in portage
213 -DWITHOUT_CASSANDRA=1 -DWITH_CASSANDRA=0
214 -DPLUGIN_CASSANDRA=NO
215 $(mysql-cmake_use_plugin extraengine SEQUENCE)
216 $(mysql-cmake_use_plugin extraengine SPIDER)
217 $(mysql-cmake_use_plugin extraengine CONNECT)
218 -DCONNECT_WITH_MYSQL=1
219 $(cmake-utils_use xml CONNECT_WITH_LIBXML2)
220 $(cmake-utils_use odbc CONNECT_WITH_ODBC)
224 if in_iuse mroonga ; then
225 use mroonga || mycmakeargs+=( -DWITHOUT_MROONGA=1 )
227 mycmakeargs+=( -DWITHOUT_MROONGA=1 )
230 if in_iuse galera ; then
231 mycmakeargs+=( $(cmake-utils_use_with galera WSREP) )
234 if mysql_version_is_at_least "10.1.1" ; then
235 mycmakeargs+=( $(cmake-utils_use_with innodb-lz4 INNODB_LZ4)
236 $(cmake-utils_use_with innodb-lzo INNODB_LZO) )
239 if in_iuse innodb-snappy ; then
240 mycmakeargs+=( $(cmake-utils_use_with innodb-snappy INNODB_SNAPPY) )
243 if mysql_version_is_at_least "10.1.2" ; then
244 mycmakeargs+=( $(mysql-cmake_use_plugin cracklib CRACKLIB_PASSWORD_CHECK ) )
247 mycmakeargs+=( $(cmake-utils_use_with extraengine FEDERATED_STORAGE_ENGINE) )
250 if [[ ${PN} == "percona-server" ]]; then
252 $(cmake-utils_use_with pam PAM)
254 if in_iuse tokudb ; then
255 # TokuDB Backup plugin requires valgrind unconditionally
257 $(mysql-cmake_use_plugin tokudb TOKUDB)
258 $(usex tokudb-backup-plugin "" -DTOKUDB_BACKUP_DISABLED=1)
263 if [[ ${PN} == "mysql-cluster" ]]; then
264 # TODO: This really should include the following options,
265 # but the memcached package doesn't install the files it seeks.
266 # -DWITH_BUNDLED_MEMCACHED=OFF
267 # -DMEMCACHED_HOME=${EPREFIX}/usr
269 -DWITH_BUNDLED_LIBEVENT=OFF
270 $(cmake-utils_use_with java NDB_JAVA)
279 # @FUNCTION: mysql-cmake_src_prepare
281 # Apply patches to the source code and remove unneeded bundled libs.
282 mysql-cmake_src_prepare() {
284 debug-print-function ${FUNCNAME} "$@"
288 if [[ ${MY_EXTRAS_VER} != none ]]; then
290 # Apply the patches for this MySQL version
291 EPATCH_SUFFIX="patch"
292 mkdir -p "${EPATCH_SOURCE}" || die "Unable to create epatch directory"
293 # Clean out old items
294 rm -f "${EPATCH_SOURCE}"/*
295 # Now link in right patches
301 # last -fPIC fixup, per bug #305873
302 i="${S}"/storage/innodb_plugin/plug.in
303 [[ -f ${i} ]] && sed -i -e '/CFLAGS/s,-prefer-non-pic,,g' "${i}"
305 rm -f "scripts/mysqlbug"
306 if use jemalloc && ! ( [[ ${PN} == "mariadb" ]] && mysql_version_is_at_least "5.5.33" ); then
307 echo "TARGET_LINK_LIBRARIES(mysqld jemalloc)" >> "${S}/sql/CMakeLists.txt" || die
310 if use tcmalloc; then
311 echo "TARGET_LINK_LIBRARIES(mysqld tcmalloc)" >> "${S}/sql/CMakeLists.txt"
314 if in_iuse tokudb ; then
315 # Don't build bundled xz-utils
316 if [[ -d "${S}/storage/tokudb/ft-index" ]] ; then
317 rm -f "${S}/storage/tokudb/ft-index/cmake_modules/TokuThirdParty.cmake" || die
318 touch "${S}/storage/tokudb/ft-index/cmake_modules/TokuThirdParty.cmake" || die
319 sed -i 's/ build_lzma//' "${S}/storage/tokudb/ft-index/ft/CMakeLists.txt" || die
320 elif [[ -d "${S}/storage/tokudb/PerconaFT" ]] ; then
321 rm "${S}/storage/tokudb/PerconaFT/cmake_modules/TokuThirdParty.cmake" || die
322 touch "${S}/storage/tokudb/PerconaFT/cmake_modules/TokuThirdParty.cmake" || die
323 sed -i -e 's/ build_lzma//' -e 's/ build_snappy//' "${S}/storage/tokudb/PerconaFT/ft/CMakeLists.txt" || die
324 sed -i -e 's/add_dependencies\(tokuportability_static_conv build_jemalloc\)//' "${S}/storage/tokudb/PerconaFT/portability/CMakeLists.txt" || die
327 if [[ -d "${S}/plugin/tokudb-backup-plugin" ]] && ! use tokudb-backup-plugin ; then
328 rm -r "${S}/plugin/tokudb-backup-plugin/Percona-TokuBackup" || die
332 # Remove the bundled groonga if it exists
333 # There is no CMake flag, it simply checks for existance
334 if [[ -d "${S}"/storage/mroonga/vendor/groonga ]] ; then
335 rm -r "${S}"/storage/mroonga/vendor/groonga || die "could not remove packaged groonga"
341 # @FUNCTION: mysql-cmake_src_configure
343 # Configure mysql to build the code for Gentoo respecting the use flags.
344 mysql-cmake_src_configure() {
346 debug-print-function ${FUNCNAME} "$@"
348 CMAKE_BUILD_TYPE="RelWithDebInfo"
350 # debug hack wrt #497532
352 -DCMAKE_C_FLAGS_RELWITHDEBINFO="$(usex debug "" "-DNDEBUG")"
353 -DCMAKE_CXX_FLAGS_RELWITHDEBINFO="$(usex debug "" "-DNDEBUG")"
354 -DCMAKE_INSTALL_PREFIX=${EPREFIX}/usr
355 -DMYSQL_DATADIR=${EPREFIX}/var/lib/mysql
356 -DSYSCONFDIR=${EPREFIX}/etc/mysql
358 -DINSTALL_DOCDIR=share/doc/${P}
359 -DINSTALL_DOCREADMEDIR=share/doc/${P}
360 -DINSTALL_INCLUDEDIR=include/mysql
361 -DINSTALL_INFODIR=share/info
362 -DINSTALL_LIBDIR=$(get_libdir)
363 -DINSTALL_ELIBDIR=$(get_libdir)/mysql
364 -DINSTALL_MANDIR=share/man
365 -DINSTALL_MYSQLDATADIR=${EPREFIX}/var/lib/mysql
366 -DINSTALL_MYSQLSHAREDIR=share/mysql
367 -DINSTALL_MYSQLTESTDIR=share/mysql/mysql-test
368 -DINSTALL_PLUGINDIR=$(get_libdir)/mysql/plugin
369 -DINSTALL_SBINDIR=sbin
370 -DINSTALL_SCRIPTDIR=share/mysql/scripts
371 -DINSTALL_SQLBENCHDIR=share/mysql
372 -DINSTALL_SUPPORTFILESDIR=${EPREFIX}/usr/share/mysql
373 -DWITH_COMMENT="Gentoo Linux ${PF}"
374 $(cmake-utils_use_with test UNIT_TESTS)
378 -DENABLED_LOCAL_INFILE=1
379 $(cmake-utils_use_enable static-libs STATIC_LIBS)
380 -DWITH_SSL=$(usex ssl system bundled)
381 -DWITH_DEFAULT_COMPILER_OPTIONS=0
382 -DWITH_DEFAULT_FEATURE_SET=0
385 if in_iuse bindist ; then
387 -DWITH_READLINE=$(usex bindist 1 0)
388 -DNOT_FOR_DISTRIBUTION=$(usex bindist 0 1)
389 $(usex bindist -DHAVE_BFD_H=0 '')
393 mycmakeargs+=( -DWITH_EDITLINE=system )
395 if [[ ${PN} == "mariadb" || ${PN} == "mariadb-galera" ]] ; then
397 -DWITH_JEMALLOC=$(usex jemalloc system)
399 mysql_version_is_at_least "10.0.9" && mycmakeargs+=( -DWITH_PCRE=system )
402 configure_cmake_locale
404 if use_if_iuse minimal ; then
405 configure_cmake_minimal
407 configure_cmake_standard
410 # Bug #114895, bug #110149
411 filter-flags "-O" "-O[01]"
413 CXXFLAGS="${CXXFLAGS} -fno-strict-aliasing"
414 CXXFLAGS="${CXXFLAGS} -felide-constructors"
415 # Causes linkage failures. Upstream bug #59607 removes it
416 if ! mysql_version_is_at_least "5.6" ; then
417 CXXFLAGS="${CXXFLAGS} -fno-implicit-templates"
419 # As of 5.7, exceptions and rtti are used!
420 if [[ ${PN} -eq 'percona-server' ]] && mysql_version_is_at_least "5.6.26" ; then
421 CXXFLAGS="${CXXFLAGS} -fno-rtti"
422 elif ! mysql_version_is_at_least "5.7" ; then
423 CXXFLAGS="${CXXFLAGS} -fno-exceptions -fno-rtti"
427 # bug #283926, with GCC4.4, this is required to get correct behavior.
428 append-flags -fno-strict-aliasing
430 cmake-utils_src_configure
433 # @FUNCTION: mysql-cmake_src_compile
435 # Compile the mysql code.
436 mysql-cmake_src_compile() {
438 debug-print-function ${FUNCNAME} "$@"
440 cmake-utils_src_compile
443 # @FUNCTION: mysql-cmake_src_install
446 mysql-cmake_src_install() {
448 debug-print-function ${FUNCNAME} "$@"
450 # Make sure the vars are correctly initialized
453 cmake-utils_src_install
455 if ! in_iuse tools || use_if_iuse tools ; then
457 einfo "Making Convenience links for mysqlcheck multi-call binary"
458 dosym "/usr/bin/mysqlcheck" "/usr/bin/mysqlanalyze"
459 dosym "/usr/bin/mysqlcheck" "/usr/bin/mysqlrepair"
460 dosym "/usr/bin/mysqlcheck" "/usr/bin/mysqloptimize"
463 # Create a mariadb_config symlink
464 [[ ${PN} == "mariadb" || ${PN} == "mariadb-galera" ]] && dosym "/usr/bin/mysql_config" "/usr/bin/mariadb_config"
466 # INSTALL_LAYOUT=STANDALONE causes cmake to create a /usr/data dir
467 rm -Rf "${ED}/usr/data"
469 # Various junk (my-*.cnf moved elsewhere)
470 einfo "Removing duplicate /usr/share/mysql files"
472 # Unless they explicitly specific USE=test, then do not install the
473 # testsuite. It DOES have a use to be installed, esp. when you want to do a
474 # validation of your database configuration after tuning it.
476 rm -rf "${D}"/${MY_SHAREDSTATEDIR}/mysql-test
479 # Configuration stuff
480 case ${MYSQL_PV_MAJOR} in
481 5.[1-4]*) mysql_mycnf_version="5.1" ;;
482 5.5) mysql_mycnf_version="5.5" ;;
483 5.[6-9]|6*|7*|8*|9*|10*) mysql_mycnf_version="5.6" ;;
485 einfo "Building default my.cnf (${mysql_mycnf_version})"
486 insinto "${MY_SYSCONFDIR#${EPREFIX}}"
487 [[ -f "${S}/scripts/mysqlaccess.conf" ]] && doins "${S}"/scripts/mysqlaccess.conf
488 mycnf_src="my.cnf-${mysql_mycnf_version}"
489 sed -e "s!@DATADIR@!${MY_DATADIR}!g" \
490 "${FILESDIR}/${mycnf_src}" \
491 > "${TMPDIR}/my.cnf.ok" || die
492 use prefix && sed -i -r -e '/^user[[:space:]]*=[[:space:]]*mysql$/d' "${TMPDIR}/my.cnf.ok"
495 -e "/character-set/s|utf8|latin1|g" \
496 "${TMPDIR}/my.cnf.ok" || die
498 eprefixify "${TMPDIR}/my.cnf.ok"
499 newins "${TMPDIR}/my.cnf.ok" my.cnf
501 # Minimal builds don't have the MySQL server
502 if use_if_iuse minimal ; then
504 elif ! in_iuse server || use_if_iuse server ; then
505 einfo "Creating initial directories"
506 # Empty directories ...
508 if [[ ${PREVIOUS_DATADIR} != "yes" ]] ; then
509 dodir "${MY_DATADIR#${EPREFIX}}"
510 keepdir "${MY_DATADIR#${EPREFIX}}"
511 chown -R mysql:mysql "${D}/${MY_DATADIR}"
515 for folder in "${MY_LOGDIR#${EPREFIX}}" ; do
518 chown -R mysql:mysql "${ED}/${folder}"
522 # Minimal builds don't have the MySQL server
523 if use_if_iuse minimal ; then
525 elif ! in_iuse server || use_if_iuse server; then
526 einfo "Including support files and sample configurations"
527 docinto "support-files"
529 "${S}"/support-files/my-*.cnf.sh \
530 "${S}"/support-files/magic \
531 "${S}"/support-files/ndb-config-2-node.ini.sh
533 [[ -f $script ]] && dodoc "${script}"
537 for script in "${S}"/scripts/mysql* ; do
538 [[ ( -f $script ) && ( ${script%.sh} == ${script} ) ]] && dodoc "${script}"
542 #Remove mytop if perl is not selected
543 [[ ${PN} == "mariadb" || ${PN} == "mariadb-galera" ]] && ! use perl \
544 && rm -f "${ED}/usr/bin/mytop"
546 in_iuse client-libs && ! use client-libs && return
548 # Percona has decided to rename libmysqlclient to libperconaserverclient
549 # Use a symlink to preserve linkages for those who don't use mysql_config
550 if [[ ${PN} == "percona-server" ]] && mysql_version_is_at_least "5.5.36" ; then
551 dosym libperconaserverclient.so /usr/$(get_libdir)/libmysqlclient.so
552 dosym libperconaserverclient.so /usr/$(get_libdir)/libmysqlclient_r.so
553 if use static-libs ; then
554 dosym libperconaserverclient.a /usr/$(get_libdir)/libmysqlclient.a
555 dosym libperconaserverclient.a /usr/$(get_libdir)/libmysqlclient_r.a