kde5.eclass: Raise frameworks minimal for KDE Apps 16.12
[gentoo.git] / eclass / kde5.eclass
1 # Copyright 1999-2016 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_UNRELEASED
117 # @INTERNAL
118 # @DESCRIPTION
119 # An array of $CATEGORY-$PV pairs of packages that are unreleased upstream.
120 # Any package matching this will have fetch restriction enabled, and receive
121 # a proper error message via pkg_nofetch.
122 KDE_UNRELEASED=( )
123
124 if [[ ${KDEBASE} = kdevelop ]]; then
125         HOMEPAGE="https://www.kdevelop.org/"
126 elif [[ ${KDEBASE} = kdel10n ]]; then
127         HOMEPAGE="http://l10n.kde.org"
128 elif [[ ${KMNAME} = kdepim ]]; then
129         HOMEPAGE="https://www.kde.org/applications/office/kontact/"
130 else
131         HOMEPAGE="https://www.kde.org/"
132 fi
133
134 LICENSE="GPL-2"
135
136 if [[ ${CATEGORY} = kde-frameworks ]]; then
137         SLOT=5/$(get_version_component_range 1-2)
138 else
139         SLOT=5
140 fi
141
142 case ${KDE_AUTODEPS} in
143         false)  ;;
144         *)
145                 if [[ ${KDE_BUILD_TYPE} = live ]]; then
146                         case ${CATEGORY} in
147                                 kde-frameworks)
148                                         FRAMEWORKS_MINIMAL=9999
149                                 ;;
150                                 kde-plasma)
151                                         FRAMEWORKS_MINIMAL=9999
152                                 ;;
153                                 *) ;;
154                         esac
155                 fi
156
157                 if [[ ${CATEGORY} = kde-plasma && ${FRAMEWORKS_MINIMAL} != 9999 ]]; then
158                         if ! [[ $(get_version_component_range 2) -le 8 && $(get_version_component_range 3) -lt 50 ]]; then
159                                 FRAMEWORKS_MINIMAL=5.27.0
160                         fi
161                 fi
162
163                 if [[ ${CATEGORY} = kde-apps ]]; then
164                         local vcr2=$((10#$(get_version_component_range 2)))
165                         if ! [[ $(get_version_component_range 1) -le 16 && ${vcr2} -lt 9 ]]; then
166                                 FRAMEWORKS_MINIMAL=5.28.0
167                         fi
168                         unset vcr2
169                 fi
170
171                 DEPEND+=" $(add_frameworks_dep extra-cmake-modules)"
172                 RDEPEND+=" >=kde-frameworks/kf-env-3"
173                 COMMONDEPEND+=" $(add_qt_dep qtcore)"
174
175                 if [[ ${CATEGORY} = kde-frameworks || ${CATEGORY} = kde-plasma && ${PN} != polkit-kde-agent ]]; then
176                         RDEPEND+=" !<kde-apps/kde4-l10n-15.12.3-r1"
177                 fi
178
179                 if [[ ${KDE_BLOCK_SLOT4} = true && ${CATEGORY} = kde-apps ]]; then
180                         RDEPEND+=" !kde-apps/${PN}:4"
181                 fi
182                 ;;
183 esac
184
185 case ${KDE_DEBUG} in
186         false)  ;;
187         *)
188                 IUSE+=" debug"
189                 ;;
190 esac
191
192 case ${KDE_DESIGNERPLUGIN} in
193         false)  ;;
194         *)
195                 IUSE+=" designer"
196                 DEPEND+=" designer? (
197                         $(add_frameworks_dep kdesignerplugin)
198                         $(add_qt_dep designer)
199                 )"
200                 ;;
201 esac
202
203 case ${KDE_EXAMPLES} in
204         false)  ;;
205         *)
206                 IUSE+=" examples"
207                 ;;
208 esac
209
210 case ${KDE_HANDBOOK} in
211         false)  ;;
212         *)
213                 IUSE+=" +handbook"
214                 DEPEND+=" handbook? ( $(add_frameworks_dep kdoctools) )"
215                 ;;
216 esac
217
218 case ${KDE_TEST} in
219         false)  ;;
220         *)
221                 IUSE+=" test"
222                 DEPEND+=" test? ( $(add_qt_dep qttest) )"
223                 ;;
224 esac
225
226 case ${KDE_SELINUX_MODULE} in
227         none)   ;;
228         *)
229                 IUSE+=" selinux"
230                 RDEPEND+=" selinux? ( sec-policy/selinux-${KDE_SELINUX_MODULE} )"
231                 ;;
232 esac
233
234 DEPEND+=" ${COMMONDEPEND} dev-util/desktop-file-utils"
235 RDEPEND+=" ${COMMONDEPEND}"
236 unset COMMONDEPEND
237
238 if [[ -n ${KMNAME} && ${KMNAME} != ${PN} && ${KDE_BUILD_TYPE} = release ]]; then
239         S=${WORKDIR}/${KMNAME}-${PV}
240 fi
241
242 # FIXME: Drop this when kdepim-16.08.x is no more
243 if [[ -n ${KMNAME} && ${KMNAME} != ${PN} && ${KMNAME} = kdepim ]]; then
244         S="${S}/${PN}"
245 fi
246
247 if [[ -n ${KDEBASE} && ${KDEBASE} = kdevelop && ${KDE_BUILD_TYPE} = release ]]; then
248         if [[ -n ${KMNAME} ]]; then
249                 S=${WORKDIR}/${KMNAME}-${PV%.0} # kdevelop missing trailing .0 in first release
250         else
251                 S=${WORKDIR}/${PN}-${PV%.0}     # kdevelop missing trailing .0 in first release
252         fi
253 fi
254
255 _kde_is_unreleased() {
256         local pair
257         for pair in "${KDE_UNRELEASED[@]}" ; do
258                 if [[ "${pair}" = "${CATEGORY}-${PV}" ]]; then
259                         return 0
260                 fi
261         done
262
263         return 1
264 }
265
266 # Determine fetch location for released tarballs
267 _calculate_src_uri() {
268         debug-print-function ${FUNCNAME} "$@"
269
270         local _kmname
271
272         if [[ -n ${KMNAME} ]]; then
273                 _kmname=${KMNAME}
274         else
275                 _kmname=${PN}
276         fi
277
278         case ${PN} in
279                 kdelibs4support | \
280                 khtml | \
281                 kjs | \
282                 kjsembed | \
283                 kmediaplayer | \
284                 kross)
285                         _kmname="portingAids/${_kmname}"
286                         ;;
287         esac
288
289         DEPEND+=" app-arch/xz-utils"
290
291         case ${CATEGORY} in
292                 kde-apps)
293                         case ${PV} in
294                                 ??.?.[6-9]? | ??.??.[6-9]? )
295                                         SRC_URI="mirror://kde/unstable/applications/${PV}/src/${_kmname}-${PV}.tar.xz"
296                                         RESTRICT+=" mirror"
297                                         ;;
298                                 *)
299                                         SRC_URI="mirror://kde/stable/applications/${PV}/src/${_kmname}-${PV}.tar.xz" ;;
300                         esac
301                         ;;
302                 kde-frameworks)
303                         SRC_URI="mirror://kde/stable/frameworks/${PV%.*}/${_kmname}-${PV}.tar.xz" ;;
304                 kde-plasma)
305                         local plasmapv=$(get_version_component_range 1-3)
306
307                         case ${PV} in
308                                 5.?.[6-9]? )
309                                         # Plasma 5 beta releases
310                                         SRC_URI="mirror://kde/unstable/plasma/${plasmapv}/${_kmname}-${PV}.tar.xz"
311                                         RESTRICT+=" mirror"
312                                         ;;
313                                 *)
314                                         # Plasma 5 stable releases
315                                         SRC_URI="mirror://kde/stable/plasma/${plasmapv}/${_kmname}-${PV}.tar.xz" ;;
316                         esac
317                         ;;
318         esac
319
320         if [[ -z ${SRC_URI} && -n ${KDEBASE} ]] ; then
321                 local _kdebase
322                 case ${PN} in
323                         kdevelop-pg-qt)
324                                 _kdebase=${PN} ;;
325                         *)
326                                 _kdebase=${KDEBASE} ;;
327                 esac
328                 case ${PV} in
329                         *.*.[6-9]? )
330                                 SRC_URI="mirror://kde/unstable/${_kdebase}/${PV}/src/${_kmname}-${PV}.tar.xz"
331                                 RESTRICT+=" mirror"
332                                 ;;
333                         *)
334                                 SRC_URI="mirror://kde/stable/${_kdebase}/${PV}/src/${_kmname}-${PV%.0}.tar.xz" ;;
335                 esac
336                 unset _kdebase
337         fi
338
339         if [[ ${KDEBASE} = kdel10n ]] ; then
340                 local uri_base="${SRC_URI/${_kmname}-${PV}.tar.xz/}kde-l10n/kde-l10n"
341                 SRC_URI=""
342                 for my_l10n in ${KDE_L10N[@]} ; do
343                         case ${my_l10n} in
344                                 sr | sr-ijekavsk | sr-Latn-ijekavsk | sr-Latn)
345                                         SRC_URI="${SRC_URI} l10n_${my_l10n}? ( ${uri_base}-sr-${PV}.tar.xz )"
346                                         ;;
347                                 *)
348                                         SRC_URI="${SRC_URI} l10n_${my_l10n}? ( ${uri_base}-$(kde_l10n2lingua ${my_l10n})-${PV}.tar.xz )"
349                                         ;;
350                         esac
351                 done
352         fi
353
354         if _kde_is_unreleased ; then
355                 RESTRICT+=" fetch"
356         fi
357 }
358
359 # Determine fetch location for live sources
360 _calculate_live_repo() {
361         debug-print-function ${FUNCNAME} "$@"
362
363         SRC_URI=""
364
365         case ${KDE_SCM} in
366                 git)
367                         # @ECLASS-VARIABLE: EGIT_MIRROR
368                         # @DESCRIPTION:
369                         # This variable allows easy overriding of default kde mirror service
370                         # (anongit) with anything else you might want to use.
371                         EGIT_MIRROR=${EGIT_MIRROR:=https://anongit.kde.org}
372
373                         local _kmname
374
375                         # @ECLASS-VARIABLE: EGIT_REPONAME
376                         # @DESCRIPTION:
377                         # This variable allows overriding of default repository
378                         # name. Specify only if this differ from PN and KMNAME.
379                         if [[ -n ${EGIT_REPONAME} ]]; then
380                                 # the repository and kmname different
381                                 _kmname=${EGIT_REPONAME}
382                         elif [[ -n ${KMNAME} ]]; then
383                                 _kmname=${KMNAME}
384                         else
385                                 _kmname=${PN}
386                         fi
387
388                         if [[ ${PV} == ??.??.49.9999 && ${CATEGORY} = kde-apps ]]; then
389                                 EGIT_BRANCH="Applications/$(get_version_component_range 1-2)"
390                         fi
391
392                         if [[ ${PV} != 9999 && ${CATEGORY} = kde-plasma ]]; then
393                                 EGIT_BRANCH="Plasma/$(get_version_component_range 1-2)"
394                         fi
395
396                         EGIT_REPO_URI="${EGIT_MIRROR}/${_kmname}"
397                         ;;
398         esac
399 }
400
401 case ${KDE_BUILD_TYPE} in
402         live) _calculate_live_repo ;;
403         *) _calculate_src_uri ;;
404 esac
405
406 debug-print "${LINENO} ${ECLASS} ${FUNCNAME}: SRC_URI is ${SRC_URI}"
407
408 # @FUNCTION: kde5_pkg_pretend
409 # @DESCRIPTION:
410 # Do some basic settings
411 kde5_pkg_pretend() {
412         debug-print-function ${FUNCNAME} "$@"
413         _check_gcc_version
414 }
415
416 # @FUNCTION: kde5_pkg_setup
417 # @DESCRIPTION:
418 # Do some basic settings
419 kde5_pkg_setup() {
420         debug-print-function ${FUNCNAME} "$@"
421         _check_gcc_version
422 }
423
424 # @FUNCTION: kde5_pkg_nofetch
425 # @DESCRIPTION:
426 # Display package publication status
427 kde5_pkg_nofetch() {
428         if ! _kde_is_unreleased ; then
429                 return
430         fi
431
432         eerror " _   _ _   _ ____  _____ _     _____    _    ____  _____ ____  "
433         eerror "| | | | \ | |  _ \| ____| |   | ____|  / \  / ___|| ____|  _ \ "
434         eerror "| | | |  \| | |_) |  _| | |   |  _|   / _ \ \___ \|  _| | | | |"
435         eerror "| |_| | |\  |  _ <| |___| |___| |___ / ___ \ ___) | |___| |_| |"
436         eerror " \___/|_| \_|_| \_\_____|_____|_____/_/   \_\____/|_____|____/ "
437         eerror "                                                               "
438         eerror " ____   _    ____ _  __    _    ____ _____ "
439         eerror "|  _ \ / \  / ___| |/ /   / \  / ___| ____|"
440         eerror "| |_) / _ \| |   | ' /   / _ \| |  _|  _|  "
441         eerror "|  __/ ___ \ |___| . \  / ___ \ |_| | |___ "
442         eerror "|_| /_/   \_\____|_|\_\/_/   \_\____|_____|"
443         eerror
444         eerror "${CATEGORY}/${P} has not been released to the public yet"
445         eerror "and is only available to packagers right now."
446         eerror ""
447         eerror "This is not a bug. Please do not file bugs or contact upstream about this."
448         eerror ""
449         eerror "Please consult the upstream release schedule to see when this "
450         eerror "package is scheduled to be released:"
451         eerror "https://community.kde.org/Schedules"
452 }
453
454 # @FUNCTION: kde5_src_unpack
455 # @DESCRIPTION:
456 # Function for unpacking KDE 5.
457 kde5_src_unpack() {
458         debug-print-function ${FUNCNAME} "$@"
459
460         if [[ ${KDE_BUILD_TYPE} = live ]]; then
461                 case ${KDE_SCM} in
462                         git)
463                                 git-r3_src_unpack
464                                 ;;
465                 esac
466         elif [[ ${KDEBASE} = kdel10n ]]; then
467                 local l10npart=5
468                 [[ ${PN} = kde4-l10n ]] && l10npart=4
469                 mkdir -p "${S}" || die "Failed to create source dir ${S}"
470                 cd "${S}"
471                 for my_tar in ${A}; do
472                         tar -xpf "${DISTDIR}/${my_tar}" --xz \
473                                 "${my_tar/.tar.xz/}/CMakeLists.txt" "${my_tar/.tar.xz/}/${l10npart}" 2> /dev/null ||
474                                 elog "${my_tar}: tar extract command failed at least partially - continuing"
475                 done
476         else
477                 default
478         fi
479 }
480
481 # @FUNCTION: kde5_src_prepare
482 # @DESCRIPTION:
483 # Function for preparing the KDE 5 sources.
484 kde5_src_prepare() {
485         debug-print-function ${FUNCNAME} "$@"
486
487         if [[ ${KDEBASE} = kdel10n ]]; then
488                 local l10npart=5
489                 [[ ${PN} = kde4-l10n ]] && l10npart=4
490                 # move known variant subdirs to root dir, currently sr@*
491                 use_if_iuse l10n_sr-ijekavsk && _l10n_variant_subdir2root sr-ijekavsk sr
492                 use_if_iuse l10n_sr-Latn-ijekavsk && _l10n_variant_subdir2root sr-Latn-ijekavsk sr
493                 use_if_iuse l10n_sr-Latn && _l10n_variant_subdir2root sr-Latn sr
494                 if use_if_iuse l10n_sr; then
495                         rm -rf kde-l10n-sr-${PV}/${l10npart}/sr/sr@* || die "Failed to cleanup L10N=sr"
496                         _l10n_variant_subdir_buster sr
497                 elif [[ -d kde-l10n-sr-${PV} ]]; then
498                         # having any variant selected means parent lingua will be unpacked as well
499                         rm -r kde-l10n-sr-${PV} || die "Failed to remove sr parent lingua"
500                 fi
501
502                 # add all l10n directories to cmake
503                 cat <<-EOF > CMakeLists.txt || die
504 project(${PN})
505 cmake_minimum_required(VERSION 2.8.12)
506 $(printf "add_subdirectory( %s )\n" \
507         `find . -mindepth 1 -maxdepth 1 -type d | sed -e "s:^\./::"`)
508 EOF
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-base/plasma-workspace
719                 if [[ ${KDEBASE} != kde-base || ${CATEGORY} = kde-apps ]]  && \
720                                 has_version 'kde-base/plasma-workspace'; then
721                         echo
722                         ewarn "WARNING! Your system configuration still contains \"kde-base/plasma-workspace\","
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                 echo "add_subdirectory(${subdir##*/})" >> ${dir}/CMakeLists.txt
772         done
773 }
774
775 fi