kde5.eclass: Deprecate kde-apps blockers with 18.08.3
[gentoo.git] / eclass / kde5.eclass
1 # Copyright 1999-2019 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
3
4 # @ECLASS: kde5.eclass
5 # @MAINTAINER:
6 # kde@gentoo.org
7 # @BLURB: Support eclass for packages that follow KDE packaging conventions.
8 # @DESCRIPTION:
9 # This eclass is intended to streamline the creation of ebuilds for packages
10 # that follow KDE upstream packaging conventions. It's primarily intended for
11 # the three upstream release groups (Frameworks, Plasma, Applications) but
12 # is also for any package that follows similar conventions.
13 #
14 # This eclass unconditionally inherits kde5-functions.eclass and all its public
15 # functions and variables may be considered as part of this eclass's API.
16 #
17 # This eclass unconditionally inherits cmake-utils.eclass and all its public
18 # variables and helper functions (not phase functions) may be considered as part
19 # of this eclass's API.
20 #
21 # This eclass's phase functions are not intended to be mixed and matched, so if
22 # any phase functions are overridden the version here should also be called.
23
24 if [[ -z ${_KDE5_ECLASS} ]]; then
25 _KDE5_ECLASS=1
26
27 # @ECLASS-VARIABLE: VIRTUALX_REQUIRED
28 # @DESCRIPTION:
29 # For proper description see virtualx.eclass manpage.
30 # Here we redefine default value to be manual, if your package needs virtualx
31 # for tests you should proceed with setting VIRTUALX_REQUIRED=test.
32 : ${VIRTUALX_REQUIRED:=manual}
33
34 inherit cmake-utils flag-o-matic gnome2-utils kde5-functions virtualx xdg
35
36 case ${EAPI} in
37         6) inherit eapi7-ver eutils ;;
38 esac
39
40 if [[ ${KDE_BUILD_TYPE} = live ]]; then
41         inherit git-r3
42 fi
43
44 if [[ -v KDE_GCC_MINIMAL ]]; then
45         EXPORT_FUNCTIONS pkg_pretend
46 fi
47
48 EXPORT_FUNCTIONS pkg_setup pkg_nofetch src_unpack src_prepare src_configure src_compile src_test src_install pkg_preinst pkg_postinst pkg_postrm
49
50 # @ECLASS-VARIABLE: ECM_KDEINSTALLDIRS
51 # @DESCRIPTION:
52 # If set to "false", do nothing.
53 # For any other value, assume the package is using KDEInstallDirs macro and switch
54 # KDE_INSTALL_USE_QT_SYS_PATHS to ON.
55 : ${ECM_KDEINSTALLDIRS:=true}
56
57 # @ECLASS-VARIABLE: KDE_AUTODEPS
58 # @DESCRIPTION:
59 # If set to "false", do nothing.
60 # For any other value, add dependencies on dev-qt/qtcore:5, kde-frameworks/kf-env
61 # and kde-frameworks/extra-cmake-modules:5. Additionally, required blockers may
62 # be set depending on the value of CATEGORY.
63 : ${KDE_AUTODEPS:=true}
64
65 # @ECLASS-VARIABLE: KDE_BLOCK_SLOT4
66 # @DESCRIPTION:
67 # This variable only has any effect when when CATEGORY = "kde-apps" and
68 # KDE_AUTODEPS is also set. If set to "true", add RDEPEND block on kde-apps/${PN}:4
69 : ${KDE_BLOCK_SLOT4:=true}
70
71 # @ECLASS-VARIABLE: KDE_DEBUG
72 # @DESCRIPTION:
73 # If set to "false", add -DNDEBUG (via cmake-utils_src_configure) and -DQT_NO_DEBUG
74 # to CPPFLAGS.
75 # Otherwise, add debug to IUSE.
76 : ${KDE_DEBUG:=true}
77
78 # @ECLASS-VARIABLE: KDE_DESIGNERPLUGIN
79 # @DESCRIPTION:
80 # If set to "false", do nothing.
81 # Otherwise, add "designer" to IUSE to toggle build of designer plugins
82 # and add the necessary DEPENDs.
83 : ${KDE_DESIGNERPLUGIN:=false}
84
85 # @ECLASS-VARIABLE: KDE_EXAMPLES
86 # @DESCRIPTION:
87 # If set to "false", unconditionally ignore a top-level examples subdirectory.
88 # Otherwise, add "examples" to IUSE to toggle adding that subdirectory.
89 : ${KDE_EXAMPLES:=false}
90
91 # @ECLASS-VARIABLE: KDE_HANDBOOK
92 # @DESCRIPTION:
93 # If set to "false", do nothing.
94 # Otherwise, add "+handbook" to IUSE, add the appropriate dependency, and
95 # generate and install KDE handbook.
96 # If set to "optional", config with -DCMAKE_DISABLE_FIND_PACKAGE_KF5DocTools=ON
97 # when USE=!handbook. In case package requires KF5KDELibs4Support, see next:
98 # If set to "forceoptional", remove a KF5DocTools dependency from the root
99 # CMakeLists.txt in addition to the above.
100 : ${KDE_HANDBOOK:=false}
101
102 # @ECLASS-VARIABLE: KDE_DOC_DIR
103 # @DESCRIPTION:
104 # Specifies the location of the KDE handbook if not the default.
105 : ${KDE_DOC_DIR:=doc}
106
107 # @ECLASS-VARIABLE: KDE_PO_DIRS
108 # @DESCRIPTION:
109 # Specifies the possible locations of KDE l10n files if not the default.
110 : ${KDE_PO_DIRS:="po poqm"}
111
112 # @ECLASS-VARIABLE: KDE_QTHELP
113 # @DESCRIPTION:
114 # If set to "false", do nothing.
115 # Otherwise, add "doc" to IUSE, add the appropriate dependency, generate
116 # and install Qt compressed help files with -DBUILD_QCH=ON when USE=doc.
117 if [[ ${CATEGORY} = kde-frameworks ]]; then
118         : ${KDE_QTHELP:=true}
119 fi
120 : ${KDE_QTHELP:=false}
121
122 # @ECLASS-VARIABLE: KDE_TEST
123 # @DESCRIPTION:
124 # If set to "false", do nothing.
125 # For any other value, add test to IUSE and add a dependency on dev-qt/qttest:5.
126 # If set to "optional", configure with -DCMAKE_DISABLE_FIND_PACKAGE_Qt5Test=ON
127 # when USE=!test.
128 # If set to "forceoptional", remove a Qt5Test dependency and comment test
129 # subdirs from the root CMakeLists.txt in addition to the above.
130 # If set to "forceoptional-recursive", remove Qt5Test dependencies and make
131 # autotest(s), unittest(s) and test(s) subdirs from *any* CMakeLists.txt in ${S}
132 # and below conditional on BUILD_TESTING. This is always meant as a short-term
133 # fix and creates ${T}/${P}-tests-optional.patch to refine and submit upstream.
134 if [[ ${CATEGORY} = kde-frameworks ]]; then
135         : ${KDE_TEST:=true}
136 fi
137 : ${KDE_TEST:=false}
138
139 # @ECLASS-VARIABLE: KDE_SELINUX_MODULE
140 # @DESCRIPTION:
141 # If set to "none", do nothing.
142 # For any other value, add selinux to IUSE, and depending on that useflag
143 # add a dependency on sec-policy/selinux-${KDE_SELINUX_MODULE} to (R)DEPEND.
144 : ${KDE_SELINUX_MODULE:=none}
145
146 # @ECLASS-VARIABLE: KDE_SUBSLOT
147 # @DESCRIPTION:
148 # If set to "false", do nothing.
149 # If set to "true", add a subslot to the package, where subslot is either
150 # defined as major.minor version for kde-*/ categories or ${PV} if other.
151 # For any other value, that value will be used as subslot.
152 : ${KDE_SUBSLOT:=false}
153
154 # @ECLASS-VARIABLE: KDE_UNRELEASED
155 # @INTERNAL
156 # @DESCRIPTION
157 # An array of $CATEGORY-$PV pairs of packages that are unreleased upstream.
158 # Any package matching this will have fetch restriction enabled, and receive
159 # a proper error message via pkg_nofetch.
160 KDE_UNRELEASED=( )
161
162 if [[ ${KDEBASE} = kdevelop ]]; then
163         HOMEPAGE="https://www.kdevelop.org/"
164 elif [[ ${KMNAME} = kdepim ]]; then
165         HOMEPAGE="https://www.kde.org/applications/office/kontact/"
166 else
167         HOMEPAGE="https://www.kde.org/"
168 fi
169
170 LICENSE="GPL-2"
171
172 SLOT=5
173
174 if [[ ${CATEGORY} = kde-frameworks ]]; then
175         KDE_SUBSLOT=true
176 fi
177
178 case ${KDE_SUBSLOT} in
179         false)  ;;
180         true)
181                 case ${CATEGORY} in
182                         kde-frameworks | \
183                         kde-plasma | \
184                         kde-apps)
185                                 SLOT+="/$(ver_cut 1-2)"
186                                 ;;
187                         *)
188                                 SLOT+="/${PV}"
189                                 ;;
190                 esac
191                 ;;
192         *)
193                 SLOT+="/${KDE_SUBSLOT}"
194                 ;;
195 esac
196
197 case ${KDE_AUTODEPS} in
198         false)  ;;
199         *)
200                 DEPEND+=" $(add_frameworks_dep extra-cmake-modules)"
201                 RDEPEND+=" >=kde-frameworks/kf-env-4"
202                 COMMONDEPEND+=" $(add_qt_dep qtcore)"
203
204                 # all packages need breeze/oxygen icons for basic iconset, bug #564838
205                 if [[ ${PN} != breeze-icons && ${PN} != oxygen-icons ]]; then
206                         RDEPEND+=" || ( $(add_frameworks_dep breeze-icons) kde-frameworks/oxygen-icons:* )"
207                 fi
208
209                 if [[ ${CATEGORY} = kde-apps && ${PV} = 18.08.3 ]]; then
210                         [[ ${KDE_BLOCK_SLOT4} = true ]] && RDEPEND+=" !kde-apps/${PN}:4"
211                         RDEPEND+=" !kde-apps/kde-l10n"
212                 fi
213                 ;;
214 esac
215
216 case ${KDE_DEBUG} in
217         false)  ;;
218         *)
219                 IUSE+=" debug"
220                 ;;
221 esac
222
223 case ${KDE_DESIGNERPLUGIN} in
224         false)  ;;
225         *)
226                 IUSE+=" designer"
227                 DEPEND+=" designer? ( $(add_frameworks_dep kdesignerplugin) )"
228 esac
229
230 case ${KDE_EXAMPLES} in
231         false)  ;;
232         *)
233                 IUSE+=" examples"
234                 ;;
235 esac
236
237 case ${KDE_HANDBOOK} in
238         false)  ;;
239         *)
240                 IUSE+=" +handbook"
241                 DEPEND+=" handbook? ( $(add_frameworks_dep kdoctools) )"
242                 ;;
243 esac
244
245 case ${KDE_QTHELP} in
246         false)  ;;
247         *)
248                 IUSE+=" doc"
249                 COMMONDEPEND+=" doc? ( $(add_qt_dep qt-docs) )"
250                 DEPEND+=" doc? (
251                         $(add_qt_dep qthelp)
252                         >=app-doc/doxygen-1.8.13-r1
253                 )"
254                 ;;
255 esac
256
257 case ${KDE_TEST} in
258         false)  ;;
259         *)
260                 IUSE+=" test"
261                 DEPEND+=" test? ( $(add_qt_dep qttest) )"
262                 ;;
263 esac
264
265 case ${KDE_SELINUX_MODULE} in
266         none)   ;;
267         *)
268                 IUSE+=" selinux"
269                 RDEPEND+=" selinux? ( sec-policy/selinux-${KDE_SELINUX_MODULE} )"
270                 ;;
271 esac
272
273 DEPEND+=" ${COMMONDEPEND} dev-util/desktop-file-utils"
274 RDEPEND+=" ${COMMONDEPEND}"
275 unset COMMONDEPEND
276
277 if [[ -n ${KMNAME} && ${KMNAME} != ${PN} && ${KDE_BUILD_TYPE} = release ]]; then
278         S=${WORKDIR}/${KMNAME}-${PV}
279 fi
280
281 if [[ -n ${KDEBASE} && ${KDEBASE} = kdevelop && ${KDE_BUILD_TYPE} = release ]]; then
282         if [[ -n ${KMNAME} ]]; then
283                 S=${WORKDIR}/${KMNAME}-${PV}
284         else
285                 S=${WORKDIR}/${P}
286         fi
287 fi
288
289 _kde_is_unreleased() {
290         local pair
291         for pair in "${KDE_UNRELEASED[@]}" ; do
292                 if [[ "${pair}" = "${CATEGORY}-${PV}" ]]; then
293                         return 0
294                 fi
295         done
296
297         return 1
298 }
299
300 # Determine fetch location for released tarballs
301 _calculate_src_uri() {
302         debug-print-function ${FUNCNAME} "$@"
303
304         local _kmname
305
306         if [[ -n ${KMNAME} ]]; then
307                 _kmname=${KMNAME}
308         else
309                 _kmname=${PN}
310         fi
311
312         case ${PN} in
313                 kdelibs4support | \
314                 khtml | \
315                 kjs | \
316                 kjsembed | \
317                 kmediaplayer | \
318                 kross)
319                         _kmname="portingAids/${_kmname}"
320                         ;;
321         esac
322
323         DEPEND+=" app-arch/xz-utils"
324
325         case ${CATEGORY} in
326                 kde-apps)
327                         case ${PV} in
328                                 ??.?.[6-9]? | ??.??.[6-9]? )
329                                         SRC_URI="mirror://kde/unstable/applications/${PV}/src/${_kmname}-${PV}.tar.xz"
330                                         RESTRICT+=" mirror"
331                                         ;;
332                                 *)
333                                         SRC_URI="mirror://kde/stable/applications/${PV}/src/${_kmname}-${PV}.tar.xz" ;;
334                         esac
335                         ;;
336                 kde-frameworks)
337                         SRC_URI="mirror://kde/stable/frameworks/${PV%.*}/${_kmname}-${PV}.tar.xz" ;;
338                 kde-plasma)
339                         local plasmapv=$(ver_cut 1-3)
340
341                         case ${PV} in
342                                 5.?.[6-9]? | 5.??.[6-9]? )
343                                         # Plasma 5 beta releases
344                                         SRC_URI="mirror://kde/unstable/plasma/${plasmapv}/${_kmname}-${PV}.tar.xz"
345                                         RESTRICT+=" mirror"
346                                         ;;
347                                 *)
348                                         # Plasma 5 stable releases
349                                         SRC_URI="mirror://kde/stable/plasma/${plasmapv}/${_kmname}-${PV}.tar.xz" ;;
350                         esac
351                         ;;
352         esac
353
354         if [[ -z ${SRC_URI} && -n ${KDEBASE} ]] ; then
355                 local _kdebase
356                 case ${PN} in
357                         kdevelop-pg-qt)
358                                 _kdebase=${PN} ;;
359                         *)
360                                 _kdebase=${KDEBASE} ;;
361                 esac
362                 case ${PV} in
363                         *.*.[6-9]? )
364                                 SRC_URI="mirror://kde/unstable/${_kdebase}/${PV}/src/${_kmname}-${PV}.tar.xz"
365                                 RESTRICT+=" mirror"
366                                 ;;
367                         *)
368                                 SRC_URI="mirror://kde/stable/${_kdebase}/${PV}/src/${_kmname}-${PV}.tar.xz" ;;
369                 esac
370                 unset _kdebase
371         fi
372
373         if _kde_is_unreleased ; then
374                 RESTRICT+=" fetch"
375         fi
376 }
377
378 # Determine fetch location for live sources
379 _calculate_live_repo() {
380         debug-print-function ${FUNCNAME} "$@"
381
382         SRC_URI=""
383
384         # @ECLASS-VARIABLE: EGIT_MIRROR
385         # @DESCRIPTION:
386         # This variable allows easy overriding of default kde mirror service
387         # (anongit) with anything else you might want to use.
388         EGIT_MIRROR=${EGIT_MIRROR:=https://anongit.kde.org}
389
390         local _kmname
391
392         # @ECLASS-VARIABLE: EGIT_REPONAME
393         # @DESCRIPTION:
394         # This variable allows overriding of default repository
395         # name. Specify only if this differ from PN and KMNAME.
396         if [[ -n ${EGIT_REPONAME} ]]; then
397                 # the repository and kmname different
398                 _kmname=${EGIT_REPONAME}
399         elif [[ -n ${KMNAME} ]]; then
400                 _kmname=${KMNAME}
401         else
402                 _kmname=${PN}
403         fi
404
405         if [[ ${PV} == ??.??.49.9999 && ${CATEGORY} = kde-apps ]]; then
406                 EGIT_BRANCH="Applications/$(ver_cut 1-2)"
407         fi
408
409         if [[ ${PV} != 9999 && ${CATEGORY} = kde-plasma ]]; then
410                 EGIT_BRANCH="Plasma/$(ver_cut 1-2)"
411         fi
412
413         EGIT_REPO_URI="${EGIT_MIRROR}/${_kmname}"
414 }
415
416 case ${KDE_BUILD_TYPE} in
417         live) _calculate_live_repo ;;
418         *) _calculate_src_uri ;;
419 esac
420
421 debug-print "${LINENO} ${ECLASS} ${FUNCNAME}: SRC_URI is ${SRC_URI}"
422
423 # @FUNCTION: kde5_pkg_pretend
424 # @DESCRIPTION:
425 # Checks if the active compiler meets the minimum version requirements.
426 # phase function is only exported if KDE_GCC_MINIMAL is defined.
427 kde5_pkg_pretend() {
428         debug-print-function ${FUNCNAME} "$@"
429         _check_gcc_version
430 }
431
432 # @FUNCTION: kde5_pkg_setup
433 # @DESCRIPTION:
434 # Checks if the active compiler meets the minimum version requirements.
435 kde5_pkg_setup() {
436         debug-print-function ${FUNCNAME} "$@"
437         _check_gcc_version
438 }
439
440 # @FUNCTION: kde5_pkg_nofetch
441 # @DESCRIPTION:
442 # Intended for use in the KDE overlay. If this package matches something in
443 # KDE_UNRELEASED, display a giant warning that the package has not yet been
444 # released upstream and should not be used.
445 kde5_pkg_nofetch() {
446         if ! _kde_is_unreleased ; then
447                 return
448         fi
449
450         eerror " _   _ _   _ ____  _____ _     _____    _    ____  _____ ____  "
451         eerror "| | | | \ | |  _ \| ____| |   | ____|  / \  / ___|| ____|  _ \ "
452         eerror "| | | |  \| | |_) |  _| | |   |  _|   / _ \ \___ \|  _| | | | |"
453         eerror "| |_| | |\  |  _ <| |___| |___| |___ / ___ \ ___) | |___| |_| |"
454         eerror " \___/|_| \_|_| \_\_____|_____|_____/_/   \_\____/|_____|____/ "
455         eerror "                                                               "
456         eerror " ____   _    ____ _  __    _    ____ _____ "
457         eerror "|  _ \ / \  / ___| |/ /   / \  / ___| ____|"
458         eerror "| |_) / _ \| |   | ' /   / _ \| |  _|  _|  "
459         eerror "|  __/ ___ \ |___| . \  / ___ \ |_| | |___ "
460         eerror "|_| /_/   \_\____|_|\_\/_/   \_\____|_____|"
461         eerror
462         eerror "${CATEGORY}/${P} has not been released to the public yet"
463         eerror "and is only available to packagers right now."
464         eerror ""
465         eerror "This is not a bug. Please do not file bugs or contact upstream about this."
466         eerror ""
467         eerror "Please consult the upstream release schedule to see when this "
468         eerror "package is scheduled to be released:"
469         eerror "https://community.kde.org/Schedules"
470 }
471
472 # @FUNCTION: kde5_src_unpack
473 # @DESCRIPTION:
474 # Unpack the sources, automatically handling both release and live ebuilds.
475 kde5_src_unpack() {
476         debug-print-function ${FUNCNAME} "$@"
477
478         if [[ ${KDE_BUILD_TYPE} = live ]]; then
479                 git-r3_src_unpack
480         else
481                 default
482         fi
483 }
484
485 # @FUNCTION: kde5_src_prepare
486 # @DESCRIPTION:
487 # Wrapper for cmake-utils_src_prepare with lots of extra logic for magic
488 # handling of linguas, tests, handbook etc.
489 kde5_src_prepare() {
490         debug-print-function ${FUNCNAME} "$@"
491
492         cmake-utils_src_prepare
493
494         # only build examples when required
495         if ! { in_iuse examples && use examples; } ; then
496                 cmake_comment_add_subdirectory examples
497         fi
498
499         # only enable handbook when required
500         if in_iuse handbook && ! use handbook ; then
501                 cmake_comment_add_subdirectory ${KDE_DOC_DIR}
502
503                 if [[ ${KDE_HANDBOOK} = forceoptional ]] ; then
504                         punt_bogus_dep KF5 DocTools
505                         sed -i -e "/kdoctools_install/ s/^/#DONT/" CMakeLists.txt || die
506                 fi
507         fi
508
509         # drop translations when nls is not wanted
510         if in_iuse nls && ! use nls ; then
511                 local po
512                 for po in ${KDE_PO_DIRS}; do
513                         if [[ -d ${po} ]] ; then
514                                 rm -r ${po} || die
515                         fi
516                 done
517         fi
518
519         # enable only the requested translations when required
520         if [[ -v LINGUAS ]] ; then
521                 local po
522                 for po in ${KDE_PO_DIRS}; do
523                 if [[ -d ${po} ]] ; then
524                         pushd ${po} > /dev/null || die
525                         local lang
526                         for lang in *; do
527                                 if [[ -e ${lang} ]] && ! has ${lang/.po/} ${LINGUAS} ; then
528                                         case ${lang} in
529                                                 cmake_modules | \
530                                                 CMakeLists.txt | \
531                                                 ${PN}.pot)      ;;
532                                                 *) rm -r ${lang} || die ;;
533                                         esac
534                                         if [[ -e CMakeLists.txt ]] ; then
535                                                 cmake_comment_add_subdirectory ${lang}
536                                                 sed -e "/add_subdirectory([[:space:]]*${lang}\/.*[[:space:]]*)/d" \
537                                                         -i CMakeLists.txt || die
538                                         fi
539                                 fi
540                         done
541                         popd > /dev/null || die
542                 fi
543                 done
544         fi
545
546         if [[ ${KDE_BUILD_TYPE} = release && ${CATEGORY} != kde-apps ]] ; then
547                 if [[ ${KDE_HANDBOOK} != false && -d ${KDE_DOC_DIR} && -v LINGUAS ]] ; then
548                         pushd ${KDE_DOC_DIR} > /dev/null || die
549                         local lang
550                         for lang in *; do
551                                 if ! has ${lang} ${LINGUAS} ; then
552                                         cmake_comment_add_subdirectory ${lang}
553                                 fi
554                         done
555                         popd > /dev/null || die
556                 fi
557         fi
558
559         # only build unit tests when required
560         if ! { in_iuse test && use test; } ; then
561                 if [[ ${KDE_TEST} = forceoptional ]] ; then
562                         punt_bogus_dep Qt5 Test
563                         # if forceoptional, also cover non-kde categories
564                         cmake_comment_add_subdirectory autotests test tests
565                 elif [[ ${KDE_TEST} = forceoptional-recursive ]] ; then
566                         punt_bogus_dep Qt5 Test
567                         local f pf="${T}/${P}"-tests-optional.patch
568                         touch ${pf} || die "Failed to touch patch file"
569                         for f in $(find . -type f -name "CMakeLists.txt" -exec \
570                                 grep -l "^\s*add_subdirectory\s*\(\s*.*\(auto|unit\)\?tests\?\s*)\s*\)" {} \;); do
571                                 cp ${f} ${f}.old || die "Failed to prepare patch origfile"
572                                 pushd ${f%/*} > /dev/null || die
573                                         punt_bogus_dep Qt5 Test
574                                         sed -i CMakeLists.txt -e \
575                                                 "/^#/! s/add_subdirectory\s*\(\s*.*\(auto|unit\)\?tests\?\s*)\s*\)/if(BUILD_TESTING)\n&\nendif()/" \
576                                                 || die
577                                 popd > /dev/null || die
578                                 diff -Naur ${f}.old ${f} 1>>${pf}
579                                 rm ${f}.old || die "Failed to clean up"
580                         done
581                         einfo "Build system was modified by KDE_TEST=forceoptional-recursive."
582                         einfo "Unified diff file ready for pickup in:"
583                         einfo "  ${pf}"
584                         einfo "Push it upstream to make this message go away."
585                 elif [[ ${CATEGORY} = kde-frameworks || ${CATEGORY} = kde-plasma || ${CATEGORY} = kde-apps ]] ; then
586                         cmake_comment_add_subdirectory autotests test tests
587                 fi
588         fi
589
590         # in frameworks, tests = manual tests so never build them
591         if [[ ${CATEGORY} = kde-frameworks ]] && [[ ${PN} != extra-cmake-modules ]]; then
592                 cmake_comment_add_subdirectory tests
593         fi
594 }
595
596 # @FUNCTION: kde5_src_configure
597 # @DESCRIPTION:
598 # Wrapper for cmake-utils_src_configure with extra logic for magic handling of
599 # handbook, tests etc.
600 kde5_src_configure() {
601         debug-print-function ${FUNCNAME} "$@"
602
603         # we rely on cmake-utils.eclass to append -DNDEBUG too
604         if in_iuse debug && ! use debug; then
605                 append-cppflags -DQT_NO_DEBUG
606         fi
607
608         local cmakeargs
609
610         if in_iuse test && ! use test ; then
611                 cmakeargs+=( -DBUILD_TESTING=OFF )
612
613                 if [[ ${KDE_TEST} = optional ]] ; then
614                         cmakeargs+=( -DCMAKE_DISABLE_FIND_PACKAGE_Qt5Test=ON )
615                 fi
616         fi
617
618         if in_iuse handbook && ! use handbook && [[ ${KDE_HANDBOOK} = optional ]] ; then
619                 cmakeargs+=( -DCMAKE_DISABLE_FIND_PACKAGE_KF5DocTools=ON )
620         fi
621
622         if in_iuse designer && ! use designer && [[ ${KDE_DESIGNERPLUGIN} != false ]] ; then
623                 cmakeargs+=( -DCMAKE_DISABLE_FIND_PACKAGE_KF5DesignerPlugin=ON )
624         fi
625
626         if [[ ${KDE_QTHELP} != false ]]; then
627                 cmakeargs+=( -DBUILD_QCH=$(usex doc) )
628         fi
629
630         if [[ ${ECM_KDEINSTALLDIRS} != false ]] ; then
631                 cmakeargs+=(
632                         # install mkspecs in the same directory as qt stuff
633                         -DKDE_INSTALL_USE_QT_SYS_PATHS=ON
634                 )
635         fi
636
637         # allow the ebuild to override what we set here
638         mycmakeargs=("${cmakeargs[@]}" "${mycmakeargs[@]}")
639
640         cmake-utils_src_configure
641 }
642
643 # @FUNCTION: kde5_src_compile
644 # @DESCRIPTION:
645 # Wrapper for cmake-utils_src_compile. Currently doesn't do anything extra, but
646 # is included as part of the API just in case it's needed in the future.
647 kde5_src_compile() {
648         debug-print-function ${FUNCNAME} "$@"
649
650         cmake-utils_src_compile "$@"
651 }
652
653 # @FUNCTION: kde5_src_test
654 # @DESCRIPTION:
655 # Wrapper for cmake-utils_src_test with extra logic for magic handling of dbus
656 # and virtualx.
657 kde5_src_test() {
658         debug-print-function ${FUNCNAME} "$@"
659
660         _test_runner() {
661                 if [[ -n "${VIRTUALDBUS_TEST}" ]]; then
662                         export $(dbus-launch)
663                 fi
664
665                 cmake-utils_src_test
666         }
667
668         # When run as normal user during ebuild development with the ebuild command, the
669         # kde tests tend to access the session DBUS. This however is not possible in a real
670         # emerge or on the tinderbox.
671         # > make sure it does not happen, so bad tests can be recognized and disabled
672         unset DBUS_SESSION_BUS_ADDRESS DBUS_SESSION_BUS_PID
673
674         if [[ ${VIRTUALX_REQUIRED} = always || ${VIRTUALX_REQUIRED} = test ]]; then
675                 virtx _test_runner
676         else
677                 _test_runner
678         fi
679
680         if [[ -n "${DBUS_SESSION_BUS_PID}" ]] ; then
681                 kill ${DBUS_SESSION_BUS_PID}
682         fi
683 }
684
685 # @FUNCTION: kde5_src_install
686 # @DESCRIPTION:
687 # Wrapper for cmake-utils_src_install with extra logic to avoid compressing
688 # certain types of files. For example, khelpcenter is not able to read
689 # compressed handbooks.
690 kde5_src_install() {
691         debug-print-function ${FUNCNAME} "$@"
692
693         cmake-utils_src_install
694
695         # We don't want QCH and tags files to be compressed, because then
696         # cmake can't find the tags and qthelp viewers can't find the docs
697         local p=$(best_version dev-qt/qtcore:5)
698         local pv=$(echo ${p/%-r[0-9]*/} | rev | cut -d - -f 1 | rev)
699         if [[ -d ${ED%/}/usr/share/doc/qt-${pv} ]]; then
700                 docompress -x /usr/share/doc/qt-${pv}
701         fi
702
703         # We don't want /usr/share/doc/HTML to be compressed,
704         # because then khelpcenter can't find the docs
705         if [[ -d ${ED%/}/usr/share/doc/HTML ]]; then
706                 docompress -x /usr/share/doc/HTML
707         fi
708 }
709
710 # @FUNCTION: kde5_pkg_preinst
711 # @DESCRIPTION:
712 # Sets up environment variables required in kde5_pkg_postinst.
713 kde5_pkg_preinst() {
714         debug-print-function ${FUNCNAME} "$@"
715
716         gnome2_icon_savelist
717         xdg_pkg_preinst
718 }
719
720 # @FUNCTION: kde5_pkg_postinst
721 # @DESCRIPTION:
722 # Updates the various XDG caches (icon, desktop, mime) if necessary.
723 kde5_pkg_postinst() {
724         debug-print-function ${FUNCNAME} "$@"
725
726         if [[ -n ${GNOME2_ECLASS_ICONS} ]]; then
727                 gnome2_icon_cache_update
728         fi
729         xdg_pkg_postinst
730
731         if [[ -z ${I_KNOW_WHAT_I_AM_DOING} ]]; then
732                 if [[ ${KDE_BUILD_TYPE} = live ]]; then
733                         echo
734                         einfo "WARNING! This is an experimental live ebuild of ${CATEGORY}/${PN}"
735                         einfo "Use it at your own risk."
736                         einfo "Do _NOT_ file bugs at bugs.gentoo.org because of this ebuild!"
737                 fi
738         fi
739 }
740
741 # @FUNCTION: kde5_pkg_postrm
742 # @DESCRIPTION:
743 # Updates the various XDG caches (icon, desktop, mime) if necessary.
744 kde5_pkg_postrm() {
745         debug-print-function ${FUNCNAME} "$@"
746
747         if [[ -n ${GNOME2_ECLASS_ICONS} ]]; then
748                 gnome2_icon_cache_update
749         fi
750         xdg_pkg_postrm
751 }
752
753 fi