/[gentoo-x86]/eclass/cmake-utils.eclass
Gentoo

Diff of /eclass/cmake-utils.eclass

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.94 Revision 1.102
1# Copyright 1999-2013 Gentoo Foundation 1# Copyright 1999-2014 Gentoo Foundation
2# Distributed under the terms of the GNU General Public License v2 2# Distributed under the terms of the GNU General Public License v2
3# $Header: /var/cvsroot/gentoo-x86/eclass/cmake-utils.eclass,v 1.94 2013/04/07 17:21:11 kensington Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/cmake-utils.eclass,v 1.102 2014/01/25 04:07:04 floppym Exp $
4 4
5# @ECLASS: cmake-utils.eclass 5# @ECLASS: cmake-utils.eclass
6# @MAINTAINER: 6# @MAINTAINER:
7# kde@gentoo.org 7# kde@gentoo.org
8# @AUTHOR: 8# @AUTHOR:
10# Maciej Mrozowski <reavertm@gentoo.org> 10# Maciej Mrozowski <reavertm@gentoo.org>
11# (undisclosed contributors) 11# (undisclosed contributors)
12# Original author: Zephyrus (zephyrus@mirach.it) 12# Original author: Zephyrus (zephyrus@mirach.it)
13# @BLURB: common ebuild functions for cmake-based packages 13# @BLURB: common ebuild functions for cmake-based packages
14# @DESCRIPTION: 14# @DESCRIPTION:
15# The cmake-utils eclass is base.eclass(5) wrapper that makes creating ebuilds for 15# The cmake-utils eclass makes creating ebuilds for cmake-based packages much easier.
16# cmake-based packages much easier.
17# It provides all inherited features (DOCS, HTML_DOCS, PATCHES) along with out-of-source 16# It provides all inherited features (DOCS, HTML_DOCS, PATCHES) along with out-of-source
18# builds (default), in-source builds and an implementation of the well-known use_enable 17# builds (default), in-source builds and an implementation of the well-known use_enable
19# and use_with functions for CMake. 18# and use_with functions for CMake.
20 19
21if [[ ${___ECLASS_ONCE_CMAKE_UTILS} != "recur -_+^+_- spank" ]] ; then 20if [[ ${___ECLASS_ONCE_CMAKE_UTILS} != "recur -_+^+_- spank" ]] ; then
48# @ECLASS-VARIABLE: CMAKE_MAKEFILE_GENERATOR 47# @ECLASS-VARIABLE: CMAKE_MAKEFILE_GENERATOR
49# @DESCRIPTION: 48# @DESCRIPTION:
50# Specify a makefile generator to be used by cmake. 49# Specify a makefile generator to be used by cmake.
51# At this point only "emake" and "ninja" are supported. 50# At this point only "emake" and "ninja" are supported.
52CMAKE_MAKEFILE_GENERATOR="${CMAKE_MAKEFILE_GENERATOR:-emake}" 51CMAKE_MAKEFILE_GENERATOR="${CMAKE_MAKEFILE_GENERATOR:-emake}"
52
53# @ECLASS-VARIABLE: CMAKE_WARN_UNUSED_CLI
54# @DESCRIPTION:
55# Warn about variables that are declared on the command line
56# but not used. Might give false-positives.
57# "no" to disable (default) or anything else to enable.
58CMAKE_WARN_UNUSED_CLI="${CMAKE_WARN_UNUSED_CLI:-no}"
53 59
54CMAKEDEPEND="" 60CMAKEDEPEND=""
55case ${WANT_CMAKE} in 61case ${WANT_CMAKE} in
56 always) 62 always)
57 ;; 63 ;;
58 *) 64 *)
59 IUSE+=" ${WANT_CMAKE}" 65 IUSE+=" ${WANT_CMAKE}"
60 CMAKEDEPEND+="${WANT_CMAKE}? ( " 66 CMAKEDEPEND+="${WANT_CMAKE}? ( "
61 ;; 67 ;;
62esac 68esac
63inherit toolchain-funcs multilib flag-o-matic base 69inherit toolchain-funcs multilib flag-o-matic eutils
64 70
65CMAKE_EXPF="src_compile src_test src_install" 71CMAKE_EXPF="src_compile src_test src_install"
66case ${EAPI:-0} in 72case ${EAPI:-0} in
67 2|3|4|5) CMAKE_EXPF+=" src_prepare src_configure" ;; 73 2|3|4|5) CMAKE_EXPF+=" src_prepare src_configure" ;;
68 1|0) ;; 74 1|0) eerror "cmake-utils no longer supports EAPI 0-1." && die
75 ;;
69 *) die "Unknown EAPI, Bug eclass maintainers." ;; 76 *) die "Unknown EAPI, bug eclass maintainers." ;;
70esac 77esac
71EXPORT_FUNCTIONS ${CMAKE_EXPF} 78EXPORT_FUNCTIONS ${CMAKE_EXPF}
72 79
73case ${CMAKE_MAKEFILE_GENERATOR} in 80case ${CMAKE_MAKEFILE_GENERATOR} in
74 emake) 81 emake)
250# @FUNCTION: cmake-utils_use_find_package 257# @FUNCTION: cmake-utils_use_find_package
251# @USAGE: <USE flag> [flag name] 258# @USAGE: <USE flag> [flag name]
252# @DESCRIPTION: 259# @DESCRIPTION:
253# Based on use_enable. See ebuild(5). 260# Based on use_enable. See ebuild(5).
254# 261#
255# `cmake-utils_use_find_package foo FOO` echoes -DCMAKE_DISABLE_FIND_PACKAGE=OFF 262# `cmake-utils_use_find_package foo LibFoo` echoes -DCMAKE_DISABLE_FIND_PACKAGE_LibFoo=OFF
256# if foo is enabled and -DCMAKE_DISABLE_FIND_PACKAGE=ON if it is disabled. 263# if foo is enabled and -DCMAKE_DISABLE_FIND_PACKAGE_LibFoo=ON if it is disabled.
257# This can be used to make find_package optional (since cmake-2.8.6). 264# This can be used to make find_package optional (since cmake-2.8.6).
258cmake-utils_use_find_package() { _use_me_now_inverted CMAKE_DISABLE_FIND_PACKAGE_ "$@" ; } 265cmake-utils_use_find_package() { _use_me_now_inverted CMAKE_DISABLE_FIND_PACKAGE_ "$@" ; }
259 266
260# @FUNCTION: cmake-utils_use_disable 267# @FUNCTION: cmake-utils_use_disable
261# @USAGE: <USE flag> [flag name] 268# @USAGE: <USE flag> [flag name]
317# Based on use_enable. See ebuild(5). 324# Based on use_enable. See ebuild(5).
318# 325#
319# `cmake-utils_use foo FOO` echoes -DFOO=ON if foo is enabled 326# `cmake-utils_use foo FOO` echoes -DFOO=ON if foo is enabled
320# and -DFOO=OFF if it is disabled. 327# and -DFOO=OFF if it is disabled.
321cmake-utils_use() { _use_me_now "" "$@" ; } 328cmake-utils_use() { _use_me_now "" "$@" ; }
329
330# @FUNCTION: cmake-utils_useno
331# @USAGE: <USE flag> [flag name]
332# @DESCRIPTION:
333# Based on use_enable. See ebuild(5).
334#
335# `cmake-utils_useno foo NOFOO` echoes -DNOFOO=OFF if foo is enabled
336# and -DNOFOO=ON if it is disabled.
337cmake-utils_useno() { _use_me_now_inverted "" "$@" ; }
322 338
323# Internal function for modifying hardcoded definitions. 339# Internal function for modifying hardcoded definitions.
324# Removes dangerous definitions that override Gentoo settings. 340# Removes dangerous definitions that override Gentoo settings.
325_modify-cmakelists() { 341_modify-cmakelists() {
326 debug-print-function ${FUNCNAME} "$@" 342 debug-print-function ${FUNCNAME} "$@"
354} 370}
355 371
356enable_cmake-utils_src_prepare() { 372enable_cmake-utils_src_prepare() {
357 debug-print-function ${FUNCNAME} "$@" 373 debug-print-function ${FUNCNAME} "$@"
358 374
359 base_src_prepare 375 debug-print "$FUNCNAME: PATCHES=$PATCHES"
376
377 pushd "${S}" > /dev/null
378 [[ ${PATCHES[@]} ]] && epatch "${PATCHES[@]}"
379
380 debug-print "$FUNCNAME: applying user patches"
381 epatch_user
382
383 popd > /dev/null
384
360} 385}
386
387# @VARIABLE: mycmakeargs
388# @DEFAULT_UNSET
389# @DESCRIPTION:
390# Optional cmake defines as a bash array. Should be defined before calling
391# src_configure.
392# @CODE
393# src_configure() {
394# local mycmakeargs=(
395# $(cmake-utils_use_with openconnect)
396# )
397# cmake-utils_src_configure
398# }
399
361 400
362enable_cmake-utils_src_configure() { 401enable_cmake-utils_src_configure() {
363 debug-print-function ${FUNCNAME} "$@" 402 debug-print-function ${FUNCNAME} "$@"
364 403
365 [[ "${CMAKE_REMOVE_MODULES}" == "yes" ]] && { 404 [[ "${CMAKE_REMOVE_MODULES}" == "yes" ]] && {
447 local mycmakeargs_local=(${mycmakeargs}) 486 local mycmakeargs_local=(${mycmakeargs})
448 else 487 else
449 local mycmakeargs_local=("${mycmakeargs[@]}") 488 local mycmakeargs_local=("${mycmakeargs[@]}")
450 fi 489 fi
451 490
491 if [[ ${CMAKE_WARN_UNUSED_CLI} == no ]] ; then
492 local warn_unused_cli="--no-warn-unused-cli"
493 else
494 local warn_unused_cli=""
495 fi
496
452 # Common configure parameters (overridable) 497 # Common configure parameters (overridable)
453 # NOTE CMAKE_BUILD_TYPE can be only overriden via CMAKE_BUILD_TYPE eclass variable 498 # NOTE CMAKE_BUILD_TYPE can be only overriden via CMAKE_BUILD_TYPE eclass variable
454 # No -DCMAKE_BUILD_TYPE=xxx definitions will be in effect. 499 # No -DCMAKE_BUILD_TYPE=xxx definitions will be in effect.
455 local cmakeargs=( 500 local cmakeargs=(
456 --no-warn-unused-cli 501 ${warn_unused_cli}
457 -C "${common_config}" 502 -C "${common_config}"
458 -G "$(_generator_to_use)" 503 -G "$(_generator_to_use)"
459 -DCMAKE_INSTALL_PREFIX="${EPREFIX}${PREFIX}" 504 -DCMAKE_INSTALL_PREFIX="${EPREFIX}${PREFIX}"
460 "${mycmakeargs_local[@]}" 505 "${mycmakeargs_local[@]}"
461 -DCMAKE_BUILD_TYPE="${CMAKE_BUILD_TYPE}" 506 -DCMAKE_BUILD_TYPE="${CMAKE_BUILD_TYPE}"
476 521
477 has src_configure ${CMAKE_EXPF} || cmake-utils_src_configure 522 has src_configure ${CMAKE_EXPF} || cmake-utils_src_configure
478 cmake-utils_src_make "$@" 523 cmake-utils_src_make "$@"
479} 524}
480 525
526_ninjaopts_from_makeopts() {
527 if [[ ${NINJAOPTS+set} == set ]]; then
528 return 0
529 fi
530 local ninjaopts=()
531 set -- ${MAKEOPTS}
532 while (( $# )); do
533 case $1 in
534 -j|-l|-k)
535 ninjaopts+=( $1 $2 )
536 shift 2
537 ;;
538 -j*|-l*|-k*)
539 ninjaopts+=( $1 )
540 shift 1
541 ;;
542 *) shift ;;
543 esac
544 done
545 export NINJAOPTS="${ninjaopts[*]}"
546}
547
481# @FUNCTION: ninja_src_make 548# @FUNCTION: ninja_src_make
482# @INTERNAL 549# @INTERNAL
483# @DESCRIPTION: 550# @DESCRIPTION:
484# Build the package using ninja generator 551# Build the package using ninja generator
485ninja_src_make() { 552ninja_src_make() {
486 debug-print-function ${FUNCNAME} "$@" 553 debug-print-function ${FUNCNAME} "$@"
487 554
488 [[ -e build.ninja ]] || die "Makefile not found. Error during configure stage." 555 [[ -e build.ninja ]] || die "build.ninja not found. Error during configure stage."
489 556
557 _ninjaopts_from_makeopts
558
490 if [[ "${CMAKE_VERBOSE}" != "OFF" ]]; then 559 if [[ "${CMAKE_VERBOSE}" != "OFF" ]]; then
491 # TODO: get load average from portage (-l option) 560 set -- ninja ${NINJAOPTS} -v "$@"
492 ninja ${MAKEOPTS} -v "$@" || die
493 else 561 else
562 set -- ninja ${NINJAOPTS} "$@"
563 fi
564
565 echo "$@"
494 ninja "$@" || die 566 "$@" || die
495 fi
496} 567}
497 568
498# @FUNCTION: make_src_make 569# @FUNCTION: emake_src_make
499# @INTERNAL 570# @INTERNAL
500# @DESCRIPTION: 571# @DESCRIPTION:
501# Build the package using make generator 572# Build the package using make generator
502emake_src_make() { 573emake_src_make() {
503 debug-print-function ${FUNCNAME} "$@" 574 debug-print-function ${FUNCNAME} "$@"
504 575
505 [[ -e Makefile ]] || die "Makefile not found. Error during configure stage." 576 [[ -e Makefile ]] || die "Makefile not found. Error during configure stage."
506 577
507 if [[ "${CMAKE_VERBOSE}" != "OFF" ]]; then 578 if [[ "${CMAKE_VERBOSE}" != "OFF" ]]; then
508 emake VERBOSE=1 "$@" || die 579 emake VERBOSE=1 "$@" || die
509 else 580 else
510 emake "$@" || die 581 emake "$@" || die
511 fi 582 fi
512 583
513} 584}
514 585
530enable_cmake-utils_src_install() { 601enable_cmake-utils_src_install() {
531 debug-print-function ${FUNCNAME} "$@" 602 debug-print-function ${FUNCNAME} "$@"
532 603
533 _check_build_dir 604 _check_build_dir
534 pushd "${BUILD_DIR}" > /dev/null 605 pushd "${BUILD_DIR}" > /dev/null
535
536 DESTDIR="${D}" ${CMAKE_MAKEFILE_GENERATOR} install "$@" || die "died running ${CMAKE_MAKEFILE_GENERATOR} install" 606 DESTDIR="${D}" ${CMAKE_MAKEFILE_GENERATOR} install "$@" || die "died running ${CMAKE_MAKEFILE_GENERATOR} install"
537 base_src_install_docs
538
539 popd > /dev/null 607 popd > /dev/null
608
609 pushd "${S}" > /dev/null
610 #Install docs, copied from base_src_install_docs
611 local x
612
613 if [[ "$(declare -p DOCS 2>/dev/null 2>&1)" == "declare -a"* ]]; then
614 for x in "${DOCS[@]}"; do
615 debug-print "$FUNCNAME: docs: creating document from ${x}"
616 dodoc "${x}" || die "dodoc failed"
617 done
618 fi
619 if [[ "$(declare -p HTML_DOCS 2>/dev/null 2>&1)" == "declare -a"* ]]; then
620 for x in "${HTML_DOCS[@]}"; do
621 debug-print "$FUNCNAME: docs: creating html document from ${x}"
622 dohtml -r "${x}" || die "dohtml failed"
623 done
624 fi
540 625
541 # Backward compatibility, for non-array variables 626 # Backward compatibility, for non-array variables
542 if [[ -n "${DOCS}" ]] && [[ "$(declare -p DOCS 2>/dev/null 2>&1)" != "declare -a"* ]]; then 627 if [[ -n "${DOCS}" ]] && [[ "$(declare -p DOCS 2>/dev/null 2>&1)" != "declare -a"* ]]; then
543 dodoc ${DOCS} || die "dodoc failed" 628 dodoc ${DOCS} || die "dodoc failed"
544 fi 629 fi
545 if [[ -n "${HTML_DOCS}" ]] && [[ "$(declare -p HTML_DOCS 2>/dev/null 2>&1)" != "declare -a"* ]]; then 630 if [[ -n "${HTML_DOCS}" ]] && [[ "$(declare -p HTML_DOCS 2>/dev/null 2>&1)" != "declare -a"* ]]; then
546 dohtml -r ${HTML_DOCS} || die "dohtml failed" 631 dohtml -r ${HTML_DOCS} || die "dohtml failed"
547 fi 632 fi
633
634 popd > /dev/null
548} 635}
549 636
550enable_cmake-utils_src_test() { 637enable_cmake-utils_src_test() {
551 debug-print-function ${FUNCNAME} "$@" 638 debug-print-function ${FUNCNAME} "$@"
552 639
578 fi 665 fi
579} 666}
580 667
581# @FUNCTION: cmake-utils_src_prepare 668# @FUNCTION: cmake-utils_src_prepare
582# @DESCRIPTION: 669# @DESCRIPTION:
583# Wrapper function around base_src_prepare, just to expand the eclass API. 670# Apply ebuild and user patches.
584cmake-utils_src_prepare() { 671cmake-utils_src_prepare() {
585 _execute_optionaly "src_prepare" "$@" 672 _execute_optionaly "src_prepare" "$@"
586} 673}
587 674
588# @FUNCTION: cmake-utils_src_configure 675# @FUNCTION: cmake-utils_src_configure

Legend:
Removed from v.1.94  
changed lines
  Added in v.1.102

  ViewVC Help
Powered by ViewVC 1.1.20