kde5-functions.eclass: Move *_MINIMAL setup here from kde5.eclass
[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                 DEPEND+=" $(add_frameworks_dep extra-cmake-modules)"
146                 RDEPEND+=" >=kde-frameworks/kf-env-3"
147                 COMMONDEPEND+=" $(add_qt_dep qtcore)"
148
149                 if [[ ${CATEGORY} = kde-frameworks || ${CATEGORY} = kde-plasma && ${PN} != polkit-kde-agent ]]; then
150                         RDEPEND+=" !<kde-apps/kde4-l10n-15.12.3-r1"
151                 fi
152
153                 if [[ ${KDE_BLOCK_SLOT4} = true && ${CATEGORY} = kde-apps ]]; then
154                         RDEPEND+=" !kde-apps/${PN}:4"
155                 fi
156                 ;;
157 esac
158
159 case ${KDE_DEBUG} in
160         false)  ;;
161         *)
162                 IUSE+=" debug"
163                 ;;
164 esac
165
166 case ${KDE_DESIGNERPLUGIN} in
167         false)  ;;
168         *)
169                 IUSE+=" designer"
170                 DEPEND+=" designer? (
171                         $(add_frameworks_dep kdesignerplugin)
172                         $(add_qt_dep designer)
173                 )"
174                 ;;
175 esac
176
177 case ${KDE_EXAMPLES} in
178         false)  ;;
179         *)
180                 IUSE+=" examples"
181                 ;;
182 esac
183
184 case ${KDE_HANDBOOK} in
185         false)  ;;
186         *)
187                 IUSE+=" +handbook"
188                 DEPEND+=" handbook? ( $(add_frameworks_dep kdoctools) )"
189                 ;;
190 esac
191
192 case ${KDE_TEST} in
193         false)  ;;
194         *)
195                 IUSE+=" test"
196                 DEPEND+=" test? ( $(add_qt_dep qttest) )"
197                 ;;
198 esac
199
200 case ${KDE_SELINUX_MODULE} in
201         none)   ;;
202         *)
203                 IUSE+=" selinux"
204                 RDEPEND+=" selinux? ( sec-policy/selinux-${KDE_SELINUX_MODULE} )"
205                 ;;
206 esac
207
208 DEPEND+=" ${COMMONDEPEND} dev-util/desktop-file-utils"
209 RDEPEND+=" ${COMMONDEPEND}"
210 unset COMMONDEPEND
211
212 if [[ -n ${KMNAME} && ${KMNAME} != ${PN} && ${KDE_BUILD_TYPE} = release ]]; then
213         S=${WORKDIR}/${KMNAME}-${PV}
214 fi
215
216 # FIXME: Drop this when kdepim-16.08.x is no more
217 if [[ -n ${KMNAME} && ${KMNAME} != ${PN} && ${KMNAME} = kdepim ]]; then
218         S="${S}/${PN}"
219 fi
220
221 if [[ -n ${KDEBASE} && ${KDEBASE} = kdevelop && ${KDE_BUILD_TYPE} = release ]]; then
222         if [[ -n ${KMNAME} ]]; then
223                 S=${WORKDIR}/${KMNAME}-${PV%.0} # kdevelop missing trailing .0 in first release
224         else
225                 S=${WORKDIR}/${PN}-${PV%.0}     # kdevelop missing trailing .0 in first release
226         fi
227 fi
228
229 _kde_is_unreleased() {
230         local pair
231         for pair in "${KDE_UNRELEASED[@]}" ; do
232                 if [[ "${pair}" = "${CATEGORY}-${PV}" ]]; then
233                         return 0
234                 fi
235         done
236
237         return 1
238 }
239
240 # Determine fetch location for released tarballs
241 _calculate_src_uri() {
242         debug-print-function ${FUNCNAME} "$@"
243
244         local _kmname
245
246         if [[ -n ${KMNAME} ]]; then
247                 _kmname=${KMNAME}
248         else
249                 _kmname=${PN}
250         fi
251
252         case ${PN} in
253                 kdelibs4support | \
254                 khtml | \
255                 kjs | \
256                 kjsembed | \
257                 kmediaplayer | \
258                 kross)
259                         _kmname="portingAids/${_kmname}"
260                         ;;
261         esac
262
263         DEPEND+=" app-arch/xz-utils"
264
265         case ${CATEGORY} in
266                 kde-apps)
267                         case ${PV} in
268                                 ??.?.[6-9]? | ??.??.[6-9]? )
269                                         SRC_URI="mirror://kde/unstable/applications/${PV}/src/${_kmname}-${PV}.tar.xz"
270                                         RESTRICT+=" mirror"
271                                         ;;
272                                 *)
273                                         SRC_URI="mirror://kde/stable/applications/${PV}/src/${_kmname}-${PV}.tar.xz" ;;
274                         esac
275                         ;;
276                 kde-frameworks)
277                         SRC_URI="mirror://kde/stable/frameworks/${PV%.*}/${_kmname}-${PV}.tar.xz" ;;
278                 kde-plasma)
279                         local plasmapv=$(get_version_component_range 1-3)
280
281                         case ${PV} in
282                                 5.?.[6-9]? )
283                                         # Plasma 5 beta releases
284                                         SRC_URI="mirror://kde/unstable/plasma/${plasmapv}/${_kmname}-${PV}.tar.xz"
285                                         RESTRICT+=" mirror"
286                                         ;;
287                                 *)
288                                         # Plasma 5 stable releases
289                                         SRC_URI="mirror://kde/stable/plasma/${plasmapv}/${_kmname}-${PV}.tar.xz" ;;
290                         esac
291                         ;;
292         esac
293
294         if [[ -z ${SRC_URI} && -n ${KDEBASE} ]] ; then
295                 local _kdebase
296                 case ${PN} in
297                         kdevelop-pg-qt)
298                                 _kdebase=${PN} ;;
299                         *)
300                                 _kdebase=${KDEBASE} ;;
301                 esac
302                 case ${PV} in
303                         *.*.[6-9]? )
304                                 SRC_URI="mirror://kde/unstable/${_kdebase}/${PV}/src/${_kmname}-${PV}.tar.xz"
305                                 RESTRICT+=" mirror"
306                                 ;;
307                         *)
308                                 SRC_URI="mirror://kde/stable/${_kdebase}/${PV}/src/${_kmname}-${PV%.0}.tar.xz" ;;
309                 esac
310                 unset _kdebase
311         fi
312
313         if [[ ${KDEBASE} = kdel10n ]] ; then
314                 local uri_base="${SRC_URI/${_kmname}-${PV}.tar.xz/}kde-l10n/kde-l10n"
315                 SRC_URI=""
316                 for my_l10n in ${KDE_L10N[@]} ; do
317                         case ${my_l10n} in
318                                 sr | sr-ijekavsk | sr-Latn-ijekavsk | sr-Latn)
319                                         SRC_URI="${SRC_URI} l10n_${my_l10n}? ( ${uri_base}-sr-${PV}.tar.xz )"
320                                         ;;
321                                 *)
322                                         SRC_URI="${SRC_URI} l10n_${my_l10n}? ( ${uri_base}-$(kde_l10n2lingua ${my_l10n})-${PV}.tar.xz )"
323                                         ;;
324                         esac
325                 done
326         fi
327
328         if _kde_is_unreleased ; then
329                 RESTRICT+=" fetch"
330         fi
331 }
332
333 # Determine fetch location for live sources
334 _calculate_live_repo() {
335         debug-print-function ${FUNCNAME} "$@"
336
337         SRC_URI=""
338
339         case ${KDE_SCM} in
340                 git)
341                         # @ECLASS-VARIABLE: EGIT_MIRROR
342                         # @DESCRIPTION:
343                         # This variable allows easy overriding of default kde mirror service
344                         # (anongit) with anything else you might want to use.
345                         EGIT_MIRROR=${EGIT_MIRROR:=https://anongit.kde.org}
346
347                         local _kmname
348
349                         # @ECLASS-VARIABLE: EGIT_REPONAME
350                         # @DESCRIPTION:
351                         # This variable allows overriding of default repository
352                         # name. Specify only if this differ from PN and KMNAME.
353                         if [[ -n ${EGIT_REPONAME} ]]; then
354                                 # the repository and kmname different
355                                 _kmname=${EGIT_REPONAME}
356                         elif [[ -n ${KMNAME} ]]; then
357                                 _kmname=${KMNAME}
358                         else
359                                 _kmname=${PN}
360                         fi
361
362                         if [[ ${PV} == ??.??.49.9999 && ${CATEGORY} = kde-apps ]]; then
363                                 EGIT_BRANCH="Applications/$(get_version_component_range 1-2)"
364                         fi
365
366                         if [[ ${PV} != 9999 && ${CATEGORY} = kde-plasma ]]; then
367                                 EGIT_BRANCH="Plasma/$(get_version_component_range 1-2)"
368                         fi
369
370                         EGIT_REPO_URI="${EGIT_MIRROR}/${_kmname}"
371                         ;;
372         esac
373 }
374
375 case ${KDE_BUILD_TYPE} in
376         live) _calculate_live_repo ;;
377         *) _calculate_src_uri ;;
378 esac
379
380 debug-print "${LINENO} ${ECLASS} ${FUNCNAME}: SRC_URI is ${SRC_URI}"
381
382 # @FUNCTION: kde5_pkg_pretend
383 # @DESCRIPTION:
384 # Do some basic settings
385 kde5_pkg_pretend() {
386         debug-print-function ${FUNCNAME} "$@"
387         _check_gcc_version
388 }
389
390 # @FUNCTION: kde5_pkg_setup
391 # @DESCRIPTION:
392 # Do some basic settings
393 kde5_pkg_setup() {
394         debug-print-function ${FUNCNAME} "$@"
395         _check_gcc_version
396 }
397
398 # @FUNCTION: kde5_pkg_nofetch
399 # @DESCRIPTION:
400 # Display package publication status
401 kde5_pkg_nofetch() {
402         if ! _kde_is_unreleased ; then
403                 return
404         fi
405
406         eerror " _   _ _   _ ____  _____ _     _____    _    ____  _____ ____  "
407         eerror "| | | | \ | |  _ \| ____| |   | ____|  / \  / ___|| ____|  _ \ "
408         eerror "| | | |  \| | |_) |  _| | |   |  _|   / _ \ \___ \|  _| | | | |"
409         eerror "| |_| | |\  |  _ <| |___| |___| |___ / ___ \ ___) | |___| |_| |"
410         eerror " \___/|_| \_|_| \_\_____|_____|_____/_/   \_\____/|_____|____/ "
411         eerror "                                                               "
412         eerror " ____   _    ____ _  __    _    ____ _____ "
413         eerror "|  _ \ / \  / ___| |/ /   / \  / ___| ____|"
414         eerror "| |_) / _ \| |   | ' /   / _ \| |  _|  _|  "
415         eerror "|  __/ ___ \ |___| . \  / ___ \ |_| | |___ "
416         eerror "|_| /_/   \_\____|_|\_\/_/   \_\____|_____|"
417         eerror
418         eerror "${CATEGORY}/${P} has not been released to the public yet"
419         eerror "and is only available to packagers right now."
420         eerror ""
421         eerror "This is not a bug. Please do not file bugs or contact upstream about this."
422         eerror ""
423         eerror "Please consult the upstream release schedule to see when this "
424         eerror "package is scheduled to be released:"
425         eerror "https://community.kde.org/Schedules"
426 }
427
428 # @FUNCTION: kde5_src_unpack
429 # @DESCRIPTION:
430 # Function for unpacking KDE 5.
431 kde5_src_unpack() {
432         debug-print-function ${FUNCNAME} "$@"
433
434         if [[ ${KDE_BUILD_TYPE} = live ]]; then
435                 case ${KDE_SCM} in
436                         git)
437                                 git-r3_src_unpack
438                                 ;;
439                 esac
440         elif [[ ${KDEBASE} = kdel10n ]]; then
441                 local l10npart=5
442                 [[ ${PN} = kde4-l10n ]] && l10npart=4
443                 mkdir -p "${S}" || die "Failed to create source dir ${S}"
444                 cd "${S}"
445                 for my_tar in ${A}; do
446                         tar -xpf "${DISTDIR}/${my_tar}" --xz \
447                                 "${my_tar/.tar.xz/}/CMakeLists.txt" "${my_tar/.tar.xz/}/${l10npart}" 2> /dev/null ||
448                                 elog "${my_tar}: tar extract command failed at least partially - continuing"
449                 done
450         else
451                 default
452         fi
453 }
454
455 # @FUNCTION: kde5_src_prepare
456 # @DESCRIPTION:
457 # Function for preparing the KDE 5 sources.
458 kde5_src_prepare() {
459         debug-print-function ${FUNCNAME} "$@"
460
461         if [[ ${KDEBASE} = kdel10n ]]; then
462                 local l10npart=5
463                 [[ ${PN} = kde4-l10n ]] && l10npart=4
464                 # move known variant subdirs to root dir, currently sr@*
465                 use_if_iuse l10n_sr-ijekavsk && _l10n_variant_subdir2root sr-ijekavsk sr
466                 use_if_iuse l10n_sr-Latn-ijekavsk && _l10n_variant_subdir2root sr-Latn-ijekavsk sr
467                 use_if_iuse l10n_sr-Latn && _l10n_variant_subdir2root sr-Latn sr
468                 if use_if_iuse l10n_sr; then
469                         rm -rf kde-l10n-sr-${PV}/${l10npart}/sr/sr@* || die "Failed to cleanup L10N=sr"
470                         _l10n_variant_subdir_buster sr
471                 elif [[ -d kde-l10n-sr-${PV} ]]; then
472                         # having any variant selected means parent lingua will be unpacked as well
473                         rm -r kde-l10n-sr-${PV} || die "Failed to remove sr parent lingua"
474                 fi
475
476                 # add all l10n directories to cmake
477                 cat <<-EOF > CMakeLists.txt || die
478 project(${PN})
479 cmake_minimum_required(VERSION 2.8.12)
480 $(printf "add_subdirectory( %s )\n" \
481         `find . -mindepth 1 -maxdepth 1 -type d | sed -e "s:^\./::"`)
482 EOF
483
484                 # for KF5: drop KDE4-based part; for KDE4: drop KF5-based part
485                 case ${l10npart} in
486                         5) find -maxdepth 2 -type f -name CMakeLists.txt -exec \
487                                 sed -i -e "/add_subdirectory(4)/ s/^/#DONT/" {} + || die ;;
488                         4) find -maxdepth 2 -type f -name CMakeLists.txt -exec \
489                                 sed -i -e "/add_subdirectory(5)/ s/^/#DONT/" {} + || die ;;
490                 esac
491         fi
492
493         cmake-utils_src_prepare
494
495         # only build examples when required
496         if ! use_if_iuse examples || ! use examples ; then
497                 cmake_comment_add_subdirectory examples
498         fi
499
500         # only enable handbook when required
501         if ! use_if_iuse handbook ; then
502                 cmake_comment_add_subdirectory ${KDE_DOC_DIR}
503
504                 if [[ ${KDE_HANDBOOK} = forceoptional ]] ; then
505                         punt_bogus_dep KF5 DocTools
506                 fi
507         fi
508
509         # drop translations when nls is not wanted
510         if [[ -d po ]] && in_iuse nls && ! use nls ; then
511                 rm -r po || die
512         fi
513
514         # enable only the requested translations
515         # when required
516         if [[ -d po && -v LINGUAS ]] ; then
517                 pushd po > /dev/null || die
518                 local lang
519                 for lang in *; do
520                         if [[ -d ${lang} ]] && ! has ${lang} ${LINGUAS} ; then
521                                 rm -r ${lang} || die
522                                 if [[ -e CMakeLists.txt ]] ; then
523                                         cmake_comment_add_subdirectory ${lang}
524                                 fi
525                         elif [[ -f ${lang} ]] && ! has ${lang/.po/} ${LINGUAS} ; then
526                                 if [[ ${lang} != CMakeLists.txt && ${lang} != ${PN}.pot ]] ; then
527                                         rm ${lang} || die
528                                 fi
529                         fi
530                 done
531                 popd > /dev/null || die
532         fi
533
534         if [[ ${KDE_BUILD_TYPE} = release && ${CATEGORY} != kde-apps ]] ; then
535                 if [[ ${KDE_HANDBOOK} != false && -d ${KDE_DOC_DIR} && -v LINGUAS ]] ; then
536                         pushd ${KDE_DOC_DIR} > /dev/null || die
537                         local lang
538                         for lang in *; do
539                                 if ! has ${lang} ${LINGUAS} ; then
540                                         cmake_comment_add_subdirectory ${lang}
541                                 fi
542                         done
543                         popd > /dev/null || die
544                 fi
545         fi
546
547         # in frameworks, tests = manual tests so never build them
548         if [[ ${CATEGORY} = kde-frameworks ]] && [[ ${PN} != extra-cmake-modules ]]; then
549                 cmake_comment_add_subdirectory tests
550         fi
551
552         # only build unit tests when required
553         if ! use_if_iuse test ; then
554                 if [[ ${KDE_TEST} = forceoptional ]] ; then
555                         punt_bogus_dep Qt5 Test
556                         # if forceoptional, also cover non-kde categories
557                         cmake_comment_add_subdirectory autotests test tests
558                 elif [[ ${KDE_TEST} = forceoptional-recursive ]] ; then
559                         punt_bogus_dep Qt5 Test
560                         local d
561                         for d in $(find . -type d -name "autotests" -or -name "tests" -or -name "test" -or -name "unittests"); do
562                                 pushd ${d%/*} > /dev/null || die
563                                         punt_bogus_dep Qt5 Test
564                                         cmake_comment_add_subdirectory autotests test tests
565                                 popd > /dev/null || die
566                         done
567                 elif [[ ${CATEGORY} = kde-frameworks || ${CATEGORY} = kde-plasma || ${CATEGORY} = kde-apps ]] ; then
568                         cmake_comment_add_subdirectory autotests test tests
569                 fi
570         fi
571 }
572
573 # @FUNCTION: kde5_src_configure
574 # @DESCRIPTION:
575 # Function for configuring the build of KDE 5.
576 kde5_src_configure() {
577         debug-print-function ${FUNCNAME} "$@"
578
579         # we rely on cmake-utils.eclass to append -DNDEBUG too
580         if ! use_if_iuse debug; then
581                 append-cppflags -DQT_NO_DEBUG
582         fi
583
584         local cmakeargs
585
586         if ! use_if_iuse test ; then
587                 cmakeargs+=( -DBUILD_TESTING=OFF )
588
589                 if [[ ${KDE_TEST} = optional ]] ; then
590                         cmakeargs+=( -DCMAKE_DISABLE_FIND_PACKAGE_Qt5Test=ON )
591                 fi
592         fi
593
594         if ! use_if_iuse handbook && [[ ${KDE_HANDBOOK} = optional ]] ; then
595                 cmakeargs+=( -DCMAKE_DISABLE_FIND_PACKAGE_KF5DocTools=ON )
596         fi
597
598         if ! use_if_iuse designer && [[ ${KDE_DESIGNERPLUGIN} != false ]] ; then
599                 cmakeargs+=( -DCMAKE_DISABLE_FIND_PACKAGE_Qt5Designer=ON )
600         fi
601
602         # install mkspecs in the same directory as qt stuff
603         cmakeargs+=(-DKDE_INSTALL_USE_QT_SYS_PATHS=ON)
604
605         # allow the ebuild to override what we set here
606         mycmakeargs=("${cmakeargs[@]}" "${mycmakeargs[@]}")
607
608         cmake-utils_src_configure
609 }
610
611 # @FUNCTION: kde5_src_compile
612 # @DESCRIPTION:
613 # Function for compiling KDE 5.
614 kde5_src_compile() {
615         debug-print-function ${FUNCNAME} "$@"
616
617         cmake-utils_src_compile "$@"
618 }
619
620 # @FUNCTION: kde5_src_test
621 # @DESCRIPTION:
622 # Function for testing KDE 5.
623 kde5_src_test() {
624         debug-print-function ${FUNCNAME} "$@"
625
626         _test_runner() {
627                 if [[ -n "${VIRTUALDBUS_TEST}" ]]; then
628                         export $(dbus-launch)
629                 fi
630
631                 cmake-utils_src_test
632         }
633
634         # When run as normal user during ebuild development with the ebuild command, the
635         # kde tests tend to access the session DBUS. This however is not possible in a real
636         # emerge or on the tinderbox.
637         # > make sure it does not happen, so bad tests can be recognized and disabled
638         unset DBUS_SESSION_BUS_ADDRESS DBUS_SESSION_BUS_PID
639
640         if [[ ${VIRTUALX_REQUIRED} = always || ${VIRTUALX_REQUIRED} = test ]]; then
641                 virtx _test_runner
642         else
643                 _test_runner
644         fi
645
646         if [[ -n "${DBUS_SESSION_BUS_PID}" ]] ; then
647                 kill ${DBUS_SESSION_BUS_PID}
648         fi
649 }
650
651 # @FUNCTION: kde5_src_install
652 # @DESCRIPTION:
653 # Function for installing KDE 5.
654 kde5_src_install() {
655         debug-print-function ${FUNCNAME} "$@"
656
657         cmake-utils_src_install
658
659         # We don't want ${PREFIX}/share/doc/HTML to be compressed,
660         # because then khelpcenter can't find the docs
661         if [[ -d ${ED}/${PREFIX}/share/doc/HTML ]]; then
662                 docompress -x ${PREFIX}/share/doc/HTML
663         fi
664 }
665
666 # @FUNCTION: kde5_pkg_preinst
667 # @DESCRIPTION:
668 # Function storing icon caches
669 kde5_pkg_preinst() {
670         debug-print-function ${FUNCNAME} "$@"
671
672         gnome2_icon_savelist
673         xdg_pkg_preinst
674 }
675
676 # @FUNCTION: kde5_pkg_postinst
677 # @DESCRIPTION:
678 # Function to rebuild the KDE System Configuration Cache after an application has been installed.
679 kde5_pkg_postinst() {
680         debug-print-function ${FUNCNAME} "$@"
681
682         gnome2_icon_cache_update
683         xdg_pkg_postinst
684
685         if [[ -z ${I_KNOW_WHAT_I_AM_DOING} ]]; then
686                 if [[ ${KDE_BUILD_TYPE} = live ]]; then
687                         echo
688                         einfo "WARNING! This is an experimental live ebuild of ${CATEGORY}/${PN}"
689                         einfo "Use it at your own risk."
690                         einfo "Do _NOT_ file bugs at bugs.gentoo.org because of this ebuild!"
691                 fi
692                 # for kf5-based applications tell user that he SHOULD NOT be using kde-base/plasma-workspace
693                 if [[ ${KDEBASE} != kde-base || ${CATEGORY} = kde-apps ]]  && \
694                                 has_version 'kde-base/plasma-workspace'; then
695                         echo
696                         ewarn "WARNING! Your system configuration still contains \"kde-base/plasma-workspace\","
697                         ewarn "indicating a Plasma 4 setup. With this setting you are unsupported by KDE team."
698                         ewarn "Please consider upgrading to Plasma 5."
699                 fi
700         fi
701 }
702
703 # @FUNCTION: kde5_pkg_postrm
704 # @DESCRIPTION:
705 # Function to rebuild the KDE System Configuration Cache after an application has been removed.
706 kde5_pkg_postrm() {
707         debug-print-function ${FUNCNAME} "$@"
708
709         gnome2_icon_cache_update
710         xdg_pkg_postrm
711 }
712
713 _l10n_variant_subdir2root() {
714         local l10npart=5
715         [[ ${PN} = kde4-l10n ]] && l10npart=4
716         local lingua=$(kde_l10n2lingua ${1})
717         local src=kde-l10n-${2}-${PV}
718         local dest=kde-l10n-${lingua}-${PV}/${l10npart}
719
720         # create variant rootdir structure from parent lingua and adapt it
721         mkdir -p ${dest} || die "Failed to create ${dest}"
722         mv ${src}/${l10npart}/${2}/${lingua} ${dest}/${lingua} || die "Failed to create ${dest}/${lingua}"
723         cp -f ${src}/CMakeLists.txt kde-l10n-${lingua}-${PV} || die "Failed to prepare L10N=${1} subdir"
724         echo "add_subdirectory(${lingua})" > ${dest}/CMakeLists.txt ||
725                 die "Failed to prepare ${dest}/CMakeLists.txt"
726         cp -f ${src}/${l10npart}/${2}/CMakeLists.txt ${dest}/${lingua} ||
727                 die "Failed to create ${dest}/${lingua}/CMakeLists.txt"
728         sed -e "s/${2}/${lingua}/" -i ${dest}/${lingua}/CMakeLists.txt ||
729                 die "Failed to prepare ${dest}/${lingua}/CMakeLists.txt"
730
731         _l10n_variant_subdir_buster ${1}
732 }
733
734 _l10n_variant_subdir_buster() {
735         local l10npart=5
736         [[ ${PN} = kde4-l10n ]] && l10npart=4
737         local dir=kde-l10n-$(kde_l10n2lingua ${1})-${PV}/${l10npart}/$(kde_l10n2lingua ${1})
738
739         case ${l10npart} in
740                 5) sed -e "/^add_subdirectory(/d" -i ${dir}/CMakeLists.txt || die "Failed to cleanup ${dir} subdir" ;;
741                 4) sed -e "/^macro.*subdirectory(/d" -i ${dir}/CMakeLists.txt || die "Failed to cleanup ${dir} subdir" ;;
742         esac
743
744         for subdir in $(find ${dir} -mindepth 1 -maxdepth 1 -type d | sed -e "s:^\./::"); do
745                 echo "add_subdirectory(${subdir##*/})" >> ${dir}/CMakeLists.txt
746         done
747 }
748
749 fi