/[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.105
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.105 2014/03/09 18:16:04 kensington 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
360} 384}
385
386# @VARIABLE: mycmakeargs
387# @DEFAULT_UNSET
388# @DESCRIPTION:
389# Optional cmake defines as a bash array. Should be defined before calling
390# src_configure.
391# @CODE
392# src_configure() {
393# local mycmakeargs=(
394# $(cmake-utils_use_with openconnect)
395# )
396# cmake-utils_src_configure
397# }
398
361 399
362enable_cmake-utils_src_configure() { 400enable_cmake-utils_src_configure() {
363 debug-print-function ${FUNCNAME} "$@" 401 debug-print-function ${FUNCNAME} "$@"
364 402
365 [[ "${CMAKE_REMOVE_MODULES}" == "yes" ]] && { 403 [[ "${CMAKE_REMOVE_MODULES}" == "yes" ]] && {
447 local mycmakeargs_local=(${mycmakeargs}) 485 local mycmakeargs_local=(${mycmakeargs})
448 else 486 else
449 local mycmakeargs_local=("${mycmakeargs[@]}") 487 local mycmakeargs_local=("${mycmakeargs[@]}")
450 fi 488 fi
451 489
490 if [[ ${CMAKE_WARN_UNUSED_CLI} == no ]] ; then
491 local warn_unused_cli="--no-warn-unused-cli"
492 else
493 local warn_unused_cli=""
494 fi
495
452 # Common configure parameters (overridable) 496 # Common configure parameters (overridable)
453 # NOTE CMAKE_BUILD_TYPE can be only overriden via CMAKE_BUILD_TYPE eclass variable 497 # 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. 498 # No -DCMAKE_BUILD_TYPE=xxx definitions will be in effect.
455 local cmakeargs=( 499 local cmakeargs=(
456 --no-warn-unused-cli 500 ${warn_unused_cli}
457 -C "${common_config}" 501 -C "${common_config}"
458 -G "$(_generator_to_use)" 502 -G "$(_generator_to_use)"
459 -DCMAKE_INSTALL_PREFIX="${EPREFIX}${PREFIX}" 503 -DCMAKE_INSTALL_PREFIX="${EPREFIX}${PREFIX}"
460 "${mycmakeargs_local[@]}" 504 "${mycmakeargs_local[@]}"
461 -DCMAKE_BUILD_TYPE="${CMAKE_BUILD_TYPE}" 505 -DCMAKE_BUILD_TYPE="${CMAKE_BUILD_TYPE}"
462 -DCMAKE_INSTALL_DO_STRIP=OFF 506 -DCMAKE_INSTALL_DO_STRIP=OFF
463 -DCMAKE_USER_MAKE_RULES_OVERRIDE="${build_rules}" 507 -DCMAKE_USER_MAKE_RULES_OVERRIDE="${build_rules}"
464 "${MYCMAKEARGS}" 508 "${MYCMAKEARGS}"
465 ) 509 )
466 510
467 pushd "${BUILD_DIR}" > /dev/null 511 pushd "${BUILD_DIR}" >/dev/null
468 debug-print "${LINENO} ${ECLASS} ${FUNCNAME}: mycmakeargs is ${mycmakeargs_local[*]}" 512 debug-print "${LINENO} ${ECLASS} ${FUNCNAME}: mycmakeargs is ${mycmakeargs_local[*]}"
469 echo "${CMAKE_BINARY}" "${cmakeargs[@]}" "${CMAKE_USE_DIR}" 513 echo "${CMAKE_BINARY}" "${cmakeargs[@]}" "${CMAKE_USE_DIR}"
470 "${CMAKE_BINARY}" "${cmakeargs[@]}" "${CMAKE_USE_DIR}" || die "cmake failed" 514 "${CMAKE_BINARY}" "${cmakeargs[@]}" "${CMAKE_USE_DIR}" || die "cmake failed"
471 popd > /dev/null 515 popd >/dev/null
472} 516}
473 517
474enable_cmake-utils_src_compile() { 518enable_cmake-utils_src_compile() {
475 debug-print-function ${FUNCNAME} "$@" 519 debug-print-function ${FUNCNAME} "$@"
476 520
477 has src_configure ${CMAKE_EXPF} || cmake-utils_src_configure 521 has src_configure ${CMAKE_EXPF} || cmake-utils_src_configure
478 cmake-utils_src_make "$@" 522 cmake-utils_src_make "$@"
479} 523}
480 524
525_ninjaopts_from_makeopts() {
526 if [[ ${NINJAOPTS+set} == set ]]; then
527 return 0
528 fi
529 local ninjaopts=()
530 set -- ${MAKEOPTS}
531 while (( $# )); do
532 case $1 in
533 -j|-l|-k)
534 ninjaopts+=( $1 $2 )
535 shift 2
536 ;;
537 -j*|-l*|-k*)
538 ninjaopts+=( $1 )
539 shift 1
540 ;;
541 *) shift ;;
542 esac
543 done
544 export NINJAOPTS="${ninjaopts[*]}"
545}
546
481# @FUNCTION: ninja_src_make 547# @FUNCTION: ninja_src_make
482# @INTERNAL 548# @INTERNAL
483# @DESCRIPTION: 549# @DESCRIPTION:
484# Build the package using ninja generator 550# Build the package using ninja generator
485ninja_src_make() { 551ninja_src_make() {
486 debug-print-function ${FUNCNAME} "$@" 552 debug-print-function ${FUNCNAME} "$@"
487 553
488 [[ -e build.ninja ]] || die "Makefile not found. Error during configure stage." 554 [[ -e build.ninja ]] || die "build.ninja not found. Error during configure stage."
489 555
556 _ninjaopts_from_makeopts
557
490 if [[ "${CMAKE_VERBOSE}" != "OFF" ]]; then 558 if [[ "${CMAKE_VERBOSE}" != "OFF" ]]; then
491 # TODO: get load average from portage (-l option) 559 set -- ninja ${NINJAOPTS} -v "$@"
492 ninja ${MAKEOPTS} -v "$@" || die
493 else 560 else
561 set -- ninja ${NINJAOPTS} "$@"
562 fi
563
564 echo "$@"
494 ninja "$@" || die 565 "$@" || die
495 fi
496} 566}
497 567
498# @FUNCTION: make_src_make 568# @FUNCTION: emake_src_make
499# @INTERNAL 569# @INTERNAL
500# @DESCRIPTION: 570# @DESCRIPTION:
501# Build the package using make generator 571# Build the package using make generator
502emake_src_make() { 572emake_src_make() {
503 debug-print-function ${FUNCNAME} "$@" 573 debug-print-function ${FUNCNAME} "$@"
504 574
505 [[ -e Makefile ]] || die "Makefile not found. Error during configure stage." 575 [[ -e Makefile ]] || die "Makefile not found. Error during configure stage."
506 576
507 if [[ "${CMAKE_VERBOSE}" != "OFF" ]]; then 577 if [[ "${CMAKE_VERBOSE}" != "OFF" ]]; then
508 emake VERBOSE=1 "$@" || die 578 emake VERBOSE=1 "$@" || die
509 else 579 else
510 emake "$@" || die 580 emake "$@" || die
511 fi 581 fi
512 582
513} 583}
514 584
518# All arguments are passed to emake. 588# All arguments are passed to emake.
519cmake-utils_src_make() { 589cmake-utils_src_make() {
520 debug-print-function ${FUNCNAME} "$@" 590 debug-print-function ${FUNCNAME} "$@"
521 591
522 _check_build_dir 592 _check_build_dir
523 pushd "${BUILD_DIR}" > /dev/null 593 pushd "${BUILD_DIR}" >/dev/null
524 594
525 ${CMAKE_MAKEFILE_GENERATOR}_src_make $@ 595 ${CMAKE_MAKEFILE_GENERATOR}_src_make "$@"
526 596
527 popd > /dev/null 597 popd >/dev/null
528} 598}
529 599
530enable_cmake-utils_src_install() { 600enable_cmake-utils_src_install() {
531 debug-print-function ${FUNCNAME} "$@" 601 debug-print-function ${FUNCNAME} "$@"
532 602
533 _check_build_dir 603 _check_build_dir
534 pushd "${BUILD_DIR}" > /dev/null 604 pushd "${BUILD_DIR}" >/dev/null
535
536 DESTDIR="${D}" ${CMAKE_MAKEFILE_GENERATOR} install "$@" || die "died running ${CMAKE_MAKEFILE_GENERATOR} install" 605 DESTDIR="${D}" ${CMAKE_MAKEFILE_GENERATOR} install "$@" || die "died running ${CMAKE_MAKEFILE_GENERATOR} install"
537 base_src_install_docs
538
539 popd > /dev/null 606 popd >/dev/null
607
608 pushd "${S}" >/dev/null
609 # Install docs, copied from base_src_install_docs
610 local x
611
612 if [[ "$(declare -p DOCS 2>/dev/null 2>&1)" == "declare -a"* ]]; then
613 for x in "${DOCS[@]}"; do
614 debug-print "$FUNCNAME: docs: creating document from ${x}"
615 dodoc "${x}" || die "dodoc failed"
616 done
617 fi
618 if [[ "$(declare -p HTML_DOCS 2>/dev/null 2>&1)" == "declare -a"* ]]; then
619 for x in "${HTML_DOCS[@]}"; do
620 debug-print "$FUNCNAME: docs: creating html document from ${x}"
621 dohtml -r "${x}" || die "dohtml failed"
622 done
623 fi
540 624
541 # Backward compatibility, for non-array variables 625 # Backward compatibility, for non-array variables
542 if [[ -n "${DOCS}" ]] && [[ "$(declare -p DOCS 2>/dev/null 2>&1)" != "declare -a"* ]]; then 626 if [[ -n "${DOCS}" ]] && [[ "$(declare -p DOCS 2>/dev/null 2>&1)" != "declare -a"* ]]; then
543 dodoc ${DOCS} || die "dodoc failed" 627 dodoc ${DOCS} || die "dodoc failed"
544 fi 628 fi
545 if [[ -n "${HTML_DOCS}" ]] && [[ "$(declare -p HTML_DOCS 2>/dev/null 2>&1)" != "declare -a"* ]]; then 629 if [[ -n "${HTML_DOCS}" ]] && [[ "$(declare -p HTML_DOCS 2>/dev/null 2>&1)" != "declare -a"* ]]; then
546 dohtml -r ${HTML_DOCS} || die "dohtml failed" 630 dohtml -r ${HTML_DOCS} || die "dohtml failed"
547 fi 631 fi
632
633 popd >/dev/null
548} 634}
549 635
550enable_cmake-utils_src_test() { 636enable_cmake-utils_src_test() {
551 debug-print-function ${FUNCNAME} "$@" 637 debug-print-function ${FUNCNAME} "$@"
552 638
553 _check_build_dir 639 _check_build_dir
554 pushd "${BUILD_DIR}" > /dev/null 640 pushd "${BUILD_DIR}" >/dev/null
555 [[ -e CTestTestfile.cmake ]] || { echo "No tests found. Skipping."; return 0 ; } 641 [[ -e CTestTestfile.cmake ]] || { echo "No tests found. Skipping."; return 0 ; }
556 642
557 [[ -n ${TEST_VERBOSE} ]] && myctestargs+=( --extra-verbose --output-on-failure ) 643 [[ -n ${TEST_VERBOSE} ]] && myctestargs+=( --extra-verbose --output-on-failure )
558 644
559 if ctest "${myctestargs[@]}" "$@" ; then 645 if ctest "${myctestargs[@]}" "$@" ; then
560 einfo "Tests succeeded." 646 einfo "Tests succeeded."
561 popd > /dev/null 647 popd >/dev/null
562 return 0 648 return 0
563 else 649 else
564 if [[ -n "${CMAKE_YES_I_WANT_TO_SEE_THE_TEST_LOG}" ]] ; then 650 if [[ -n "${CMAKE_YES_I_WANT_TO_SEE_THE_TEST_LOG}" ]] ; then
565 # on request from Diego 651 # on request from Diego
566 eerror "Tests failed. Test log ${BUILD_DIR}/Testing/Temporary/LastTest.log follows:" 652 eerror "Tests failed. Test log ${BUILD_DIR}/Testing/Temporary/LastTest.log follows:"
571 else 657 else
572 die "Tests failed. When you file a bug, please attach the following file: \n\t${BUILD_DIR}/Testing/Temporary/LastTest.log" 658 die "Tests failed. When you file a bug, please attach the following file: \n\t${BUILD_DIR}/Testing/Temporary/LastTest.log"
573 fi 659 fi
574 660
575 # die might not die due to nonfatal 661 # die might not die due to nonfatal
576 popd > /dev/null 662 popd >/dev/null
577 return 1 663 return 1
578 fi 664 fi
579} 665}
580 666
581# @FUNCTION: cmake-utils_src_prepare 667# @FUNCTION: cmake-utils_src_prepare
582# @DESCRIPTION: 668# @DESCRIPTION:
583# Wrapper function around base_src_prepare, just to expand the eclass API. 669# Apply ebuild and user patches.
584cmake-utils_src_prepare() { 670cmake-utils_src_prepare() {
585 _execute_optionaly "src_prepare" "$@" 671 _execute_optionaly "src_prepare" "$@"
586} 672}
587 673
588# @FUNCTION: cmake-utils_src_configure 674# @FUNCTION: cmake-utils_src_configure

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

  ViewVC Help
Powered by ViewVC 1.1.20