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