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