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