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