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