/[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.109 Revision 1.110
1# Copyright 1999-2014 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.109 2014/08/05 22:59:44 johu Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/cmake-utils.eclass,v 1.110 2014/08/12 14:58:40 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:
18# and use_with functions for CMake. 18# and use_with functions for CMake.
19 19
20if [[ -z ${_CMAKE_UTILS_ECLASS} ]]; then 20if [[ -z ${_CMAKE_UTILS_ECLASS} ]]; then
21_CMAKE_UTILS_ECLASS=1 21_CMAKE_UTILS_ECLASS=1
22 22
23
24# @ECLASS-VARIABLE: BUILD_DIR
25# @DESCRIPTION:
26# Build directory where all cmake processed files should be generated.
27# For in-source build it's fixed to ${CMAKE_USE_DIR}.
28# For out-of-source build it can be overridden, by default it uses
29# ${WORKDIR}/${P}_build.
30#
31# This variable has been called CMAKE_BUILD_DIR formerly.
32# It is set under that name for compatibility.
33
23# @ECLASS-VARIABLE: WANT_CMAKE 34# @ECLASS-VARIABLE: CMAKE_BINARY
24# @DESCRIPTION: 35# @DESCRIPTION:
25# Specify if cmake-utils eclass should depend on cmake optionally or not. 36# Eclass can use different cmake binary than the one provided in by system.
26# This is usefull when only part of aplication is using cmake build system. 37: ${CMAKE_BINARY:=cmake}
27# Valid values are: always [default], optional (where the value is the useflag 38
28# used for optionality) 39# @ECLASS-VARIABLE: CMAKE_BUILD_TYPE
29WANT_CMAKE="${WANT_CMAKE:-always}" 40# @DESCRIPTION:
41# Set to override default CMAKE_BUILD_TYPE. Only useful for packages
42# known to make use of "if (CMAKE_BUILD_TYPE MATCHES xxx)".
43# If about to be set - needs to be set before invoking cmake-utils_src_configure.
44# You usualy do *NOT* want nor need to set it as it pulls CMake default build-type
45# specific compiler flags overriding make.conf.
46: ${CMAKE_BUILD_TYPE:=Gentoo}
47
48# @ECLASS-VARIABLE: CMAKE_IN_SOURCE_BUILD
49# @DESCRIPTION:
50# Set to enable in-source build.
51
52# @ECLASS-VARIABLE: CMAKE_MAKEFILE_GENERATOR
53# @DESCRIPTION:
54# Specify a makefile generator to be used by cmake.
55# At this point only "emake" and "ninja" are supported.
56: ${CMAKE_MAKEFILE_GENERATOR:=emake}
30 57
31# @ECLASS-VARIABLE: CMAKE_MIN_VERSION 58# @ECLASS-VARIABLE: CMAKE_MIN_VERSION
32# @DESCRIPTION: 59# @DESCRIPTION:
33# Specify the minimum required CMake version. 60# Specify the minimum required CMake version.
34CMAKE_MIN_VERSION="${CMAKE_MIN_VERSION:-2.8.12}" 61: ${CMAKE_MIN_VERSION:=2.8.12}
62
63# @ECLASS-VARIABLE: CMAKE_REMOVE_MODULES
64# @DESCRIPTION:
65# Do we want to remove anything? yes or whatever else for no
66: ${CMAKE_REMOVE_MODULES:=yes}
67CMAKE_REMOVE_MODULES="${CMAKE_REMOVE_MODULES:-yes}"
35 68
36# @ECLASS-VARIABLE: CMAKE_REMOVE_MODULES_LIST 69# @ECLASS-VARIABLE: CMAKE_REMOVE_MODULES_LIST
37# @DESCRIPTION: 70# @DESCRIPTION:
38# Space-separated list of CMake modules that will be removed in $S during src_prepare, 71# Space-separated list of CMake modules that will be removed in $S during src_prepare,
39# in order to force packages to use the system version. 72# in order to force packages to use the system version.
40CMAKE_REMOVE_MODULES_LIST="${CMAKE_REMOVE_MODULES_LIST:-FindBLAS FindLAPACK}" 73: ${CMAKE_REMOVE_MODULES_LIST:=FindBLAS FindLAPACK}
41 74
75# @ECLASS-VARIABLE: CMAKE_USE_DIR
76# @DESCRIPTION:
77# Sets the directory where we are working with cmake.
78# For example when application uses autotools and only one
79# plugin needs to be done by cmake.
80# By default it uses ${S}.
81
42# @ECLASS-VARIABLE: CMAKE_REMOVE_MODULES 82# @ECLASS-VARIABLE: CMAKE_VERBOSE
43# @DESCRIPTION: 83# @DESCRIPTION:
44# Do we want to remove anything? yes or whatever else for no 84# Set to OFF to disable verbose messages during compilation
45CMAKE_REMOVE_MODULES="${CMAKE_REMOVE_MODULES:-yes}" 85: ${CMAKE_VERBOSE:=ON}
46
47# @ECLASS-VARIABLE: CMAKE_MAKEFILE_GENERATOR
48# @DESCRIPTION:
49# Specify a makefile generator to be used by cmake.
50# At this point only "emake" and "ninja" are supported.
51CMAKE_MAKEFILE_GENERATOR="${CMAKE_MAKEFILE_GENERATOR:-emake}"
52 86
53# @ECLASS-VARIABLE: CMAKE_WARN_UNUSED_CLI 87# @ECLASS-VARIABLE: CMAKE_WARN_UNUSED_CLI
54# @DESCRIPTION: 88# @DESCRIPTION:
55# Warn about variables that are declared on the command line 89# Warn about variables that are declared on the command line
56# but not used. Might give false-positives. 90# but not used. Might give false-positives.
57# "no" to disable (default) or anything else to enable. 91# "no" to disable (default) or anything else to enable.
58CMAKE_WARN_UNUSED_CLI="${CMAKE_WARN_UNUSED_CLI:-no}" 92: ${CMAKE_WARN_UNUSED_CLI:=no}
93
94# @ECLASS-VARIABLE: PREFIX
95# @DESCRIPTION:
96# Eclass respects PREFIX variable, though it's not recommended way to set
97# install/lib/bin prefixes.
98# Use -DCMAKE_INSTALL_PREFIX=... CMake variable instead.
99: ${PREFIX:=/usr}
100
101# @ECLASS-VARIABLE: WANT_CMAKE
102# @DESCRIPTION:
103# Specify if cmake-utils eclass should depend on cmake optionally or not.
104# This is useful when only part of application is using cmake build system.
105# Valid values are: always [default], optional (where the value is the useflag
106# used for optionality)
107: ${WANT_CMAKE:=always}
108
59 109
60CMAKEDEPEND="" 110CMAKEDEPEND=""
61case ${WANT_CMAKE} in 111case ${WANT_CMAKE} in
62 always) 112 always)
63 ;; 113 ;;
66 CMAKEDEPEND+="${WANT_CMAKE}? ( " 116 CMAKEDEPEND+="${WANT_CMAKE}? ( "
67 ;; 117 ;;
68esac 118esac
69inherit toolchain-funcs multilib flag-o-matic eutils 119inherit toolchain-funcs multilib flag-o-matic eutils
70 120
71CMAKE_EXPF="src_compile src_test src_install"
72case ${EAPI:-0} in 121case ${EAPI:-0} in
73 2|3|4|5) CMAKE_EXPF+=" src_prepare src_configure" ;; 122 2|3|4|5) : ;;
74 1|0) eerror "cmake-utils no longer supports EAPI 0-1." && die 123 *) die "EAPI=${EAPI} is not supported" ;;
75 ;;
76 *) die "Unknown EAPI, bug eclass maintainers." ;;
77esac 124esac
125
126CMAKE_EXPF="src_prepare src_configure src_compile src_test src_install"
78EXPORT_FUNCTIONS ${CMAKE_EXPF} 127EXPORT_FUNCTIONS ${CMAKE_EXPF}
79 128
80case ${CMAKE_MAKEFILE_GENERATOR} in 129case ${CMAKE_MAKEFILE_GENERATOR} in
81 emake) 130 emake)
82 CMAKEDEPEND+=" sys-devel/make" 131 CMAKEDEPEND+=" sys-devel/make"
135 echo "-D$1$x=$(use $2 && echo OFF || echo ON) " 184 echo "-D$1$x=$(use $2 && echo OFF || echo ON) "
136 done 185 done
137 fi 186 fi
138} 187}
139 188
140# @ECLASS-VARIABLE: BUILD_DIR
141# @DESCRIPTION:
142# Build directory where all cmake processed files should be generated.
143# For in-source build it's fixed to ${CMAKE_USE_DIR}.
144# For out-of-source build it can be overriden, by default it uses
145# ${WORKDIR}/${P}_build.
146#
147# This variable has been called CMAKE_BUILD_DIR formerly.
148# It is set under that name for compatibility.
149
150# @ECLASS-VARIABLE: CMAKE_BUILD_TYPE
151# @DESCRIPTION:
152# Set to override default CMAKE_BUILD_TYPE. Only useful for packages
153# known to make use of "if (CMAKE_BUILD_TYPE MATCHES xxx)".
154# If about to be set - needs to be set before invoking cmake-utils_src_configure.
155# You usualy do *NOT* want nor need to set it as it pulls CMake default build-type
156# specific compiler flags overriding make.conf.
157: ${CMAKE_BUILD_TYPE:=Gentoo}
158
159# @ECLASS-VARIABLE: CMAKE_IN_SOURCE_BUILD
160# @DESCRIPTION:
161# Set to enable in-source build.
162
163# @ECLASS-VARIABLE: CMAKE_USE_DIR
164# @DESCRIPTION:
165# Sets the directory where we are working with cmake.
166# For example when application uses autotools and only one
167# plugin needs to be done by cmake.
168# By default it uses ${S}.
169
170# @ECLASS-VARIABLE: CMAKE_VERBOSE
171# @DESCRIPTION:
172# Set to OFF to disable verbose messages during compilation
173: ${CMAKE_VERBOSE:=ON}
174
175# @ECLASS-VARIABLE: PREFIX
176# @DESCRIPTION:
177# Eclass respects PREFIX variable, though it's not recommended way to set
178# install/lib/bin prefixes.
179# Use -DCMAKE_INSTALL_PREFIX=... CMake variable instead.
180: ${PREFIX:=/usr}
181
182# @ECLASS-VARIABLE: CMAKE_BINARY
183# @DESCRIPTION:
184# Eclass can use different cmake binary than the one provided in by system.
185: ${CMAKE_BINARY:=cmake}
186
187# Determine using IN or OUT source build 189# Determine using IN or OUT source build
188_check_build_dir() { 190_check_build_dir() {
189 : ${CMAKE_USE_DIR:=${S}} 191 : ${CMAKE_USE_DIR:=${S}}
190 if [[ -n ${CMAKE_IN_SOURCE_BUILD} ]]; then 192 if [[ -n ${CMAKE_IN_SOURCE_BUILD} ]]; then
191 # we build in source dir 193 # we build in source dir
259# @DESCRIPTION: 261# @DESCRIPTION:
260# Based on use_enable. See ebuild(5). 262# Based on use_enable. See ebuild(5).
261# 263#
262# `cmake-utils_use_find_package foo LibFoo` echoes -DCMAKE_DISABLE_FIND_PACKAGE_LibFoo=OFF 264# `cmake-utils_use_find_package foo LibFoo` echoes -DCMAKE_DISABLE_FIND_PACKAGE_LibFoo=OFF
263# if foo is enabled and -DCMAKE_DISABLE_FIND_PACKAGE_LibFoo=ON if it is disabled. 265# if foo is enabled and -DCMAKE_DISABLE_FIND_PACKAGE_LibFoo=ON if it is disabled.
264# This can be used to make find_package optional (since cmake-2.8.6). 266# This can be used to make find_package optional.
265cmake-utils_use_find_package() { _use_me_now_inverted CMAKE_DISABLE_FIND_PACKAGE_ "$@" ; } 267cmake-utils_use_find_package() { _use_me_now_inverted CMAKE_DISABLE_FIND_PACKAGE_ "$@" ; }
266 268
267# @FUNCTION: cmake-utils_use_disable 269# @FUNCTION: cmake-utils_use_disable
268# @USAGE: <USE flag> [flag name] 270# @USAGE: <USE flag> [flag name]
269# @DESCRIPTION: 271# @DESCRIPTION:
370} 372}
371 373
372enable_cmake-utils_src_prepare() { 374enable_cmake-utils_src_prepare() {
373 debug-print-function ${FUNCNAME} "$@" 375 debug-print-function ${FUNCNAME} "$@"
374 376
377 pushd "${S}" > /dev/null
378
375 debug-print "$FUNCNAME: PATCHES=$PATCHES" 379 debug-print "$FUNCNAME: PATCHES=$PATCHES"
376
377 pushd "${S}" >/dev/null
378 [[ ${PATCHES[@]} ]] && epatch "${PATCHES[@]}" 380 [[ ${PATCHES[@]} ]] && epatch "${PATCHES[@]}"
379 381
380 debug-print "$FUNCNAME: applying user patches" 382 debug-print "$FUNCNAME: applying user patches"
381 epatch_user 383 epatch_user
382 384
383 popd >/dev/null 385 popd > /dev/null
384} 386}
385 387
386# @VARIABLE: mycmakeargs 388# @VARIABLE: mycmakeargs
387# @DEFAULT_UNSET 389# @DEFAULT_UNSET
388# @DESCRIPTION: 390# @DESCRIPTION:
391# @CODE 393# @CODE
392# src_configure() { 394# src_configure() {
393# local mycmakeargs=( 395# local mycmakeargs=(
394# $(cmake-utils_use_with openconnect) 396# $(cmake-utils_use_with openconnect)
395# ) 397# )
398#
396# cmake-utils_src_configure 399# cmake-utils_src_configure
397# } 400# }
398 401# @CODE
399 402
400enable_cmake-utils_src_configure() { 403enable_cmake-utils_src_configure() {
401 debug-print-function ${FUNCNAME} "$@" 404 debug-print-function ${FUNCNAME} "$@"
402 405
403 [[ "${CMAKE_REMOVE_MODULES}" == "yes" ]] && { 406 [[ "${CMAKE_REMOVE_MODULES}" == "yes" ]] && {
506 -DCMAKE_INSTALL_DO_STRIP=OFF 509 -DCMAKE_INSTALL_DO_STRIP=OFF
507 -DCMAKE_USER_MAKE_RULES_OVERRIDE="${build_rules}" 510 -DCMAKE_USER_MAKE_RULES_OVERRIDE="${build_rules}"
508 "${MYCMAKEARGS}" 511 "${MYCMAKEARGS}"
509 ) 512 )
510 513
511 pushd "${BUILD_DIR}" >/dev/null 514 pushd "${BUILD_DIR}" > /dev/null
512 debug-print "${LINENO} ${ECLASS} ${FUNCNAME}: mycmakeargs is ${mycmakeargs_local[*]}" 515 debug-print "${LINENO} ${ECLASS} ${FUNCNAME}: mycmakeargs is ${mycmakeargs_local[*]}"
513 echo "${CMAKE_BINARY}" "${cmakeargs[@]}" "${CMAKE_USE_DIR}" 516 echo "${CMAKE_BINARY}" "${cmakeargs[@]}" "${CMAKE_USE_DIR}"
514 "${CMAKE_BINARY}" "${cmakeargs[@]}" "${CMAKE_USE_DIR}" || die "cmake failed" 517 "${CMAKE_BINARY}" "${cmakeargs[@]}" "${CMAKE_USE_DIR}" || die "cmake failed"
515 popd >/dev/null 518 popd > /dev/null
516} 519}
517 520
518enable_cmake-utils_src_compile() { 521enable_cmake-utils_src_compile() {
519 debug-print-function ${FUNCNAME} "$@" 522 debug-print-function ${FUNCNAME} "$@"
520 523
521 has src_configure ${CMAKE_EXPF} || cmake-utils_src_configure
522 cmake-utils_src_make "$@" 524 cmake-utils_src_make "$@"
523} 525}
524 526
525_ninjaopts_from_makeopts() { 527_ninjaopts_from_makeopts() {
526 if [[ ${NINJAOPTS+set} == set ]]; then 528 if [[ ${NINJAOPTS+set} == set ]]; then
588# All arguments are passed to emake. 590# All arguments are passed to emake.
589cmake-utils_src_make() { 591cmake-utils_src_make() {
590 debug-print-function ${FUNCNAME} "$@" 592 debug-print-function ${FUNCNAME} "$@"
591 593
592 _check_build_dir 594 _check_build_dir
593 pushd "${BUILD_DIR}" >/dev/null 595 pushd "${BUILD_DIR}" > /dev/null
594 596
595 ${CMAKE_MAKEFILE_GENERATOR}_src_make "$@" 597 ${CMAKE_MAKEFILE_GENERATOR}_src_make "$@"
596 598
597 popd >/dev/null 599 popd > /dev/null
598} 600}
599 601
600enable_cmake-utils_src_install() { 602enable_cmake-utils_src_test() {
601 debug-print-function ${FUNCNAME} "$@" 603 debug-print-function ${FUNCNAME} "$@"
602 604
603 _check_build_dir 605 _check_build_dir
604 pushd "${BUILD_DIR}" >/dev/null 606 pushd "${BUILD_DIR}" > /dev/null
605 DESTDIR="${D}" ${CMAKE_MAKEFILE_GENERATOR} install "$@" || die "died running ${CMAKE_MAKEFILE_GENERATOR} install"
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
624
625 # Backward compatibility, for non-array variables
626 if [[ -n "${DOCS}" ]] && [[ "$(declare -p DOCS 2>/dev/null 2>&1)" != "declare -a"* ]]; then
627 dodoc ${DOCS} || die "dodoc failed"
628 fi
629 if [[ -n "${HTML_DOCS}" ]] && [[ "$(declare -p HTML_DOCS 2>/dev/null 2>&1)" != "declare -a"* ]]; then
630 dohtml -r ${HTML_DOCS} || die "dohtml failed"
631 fi
632
633 popd >/dev/null
634}
635
636enable_cmake-utils_src_test() {
637 debug-print-function ${FUNCNAME} "$@"
638
639 _check_build_dir
640 pushd "${BUILD_DIR}" >/dev/null
641 [[ -e CTestTestfile.cmake ]] || { echo "No tests found. Skipping."; return 0 ; } 607 [[ -e CTestTestfile.cmake ]] || { echo "No tests found. Skipping."; return 0 ; }
642 608
643 [[ -n ${TEST_VERBOSE} ]] && myctestargs+=( --extra-verbose --output-on-failure ) 609 [[ -n ${TEST_VERBOSE} ]] && myctestargs+=( --extra-verbose --output-on-failure )
644 610
645 if ctest "${myctestargs[@]}" "$@" ; then 611 if ctest "${myctestargs[@]}" "$@" ; then
646 einfo "Tests succeeded." 612 einfo "Tests succeeded."
647 popd >/dev/null 613 popd > /dev/null
648 return 0 614 return 0
649 else 615 else
650 if [[ -n "${CMAKE_YES_I_WANT_TO_SEE_THE_TEST_LOG}" ]] ; then 616 if [[ -n "${CMAKE_YES_I_WANT_TO_SEE_THE_TEST_LOG}" ]] ; then
651 # on request from Diego 617 # on request from Diego
652 eerror "Tests failed. Test log ${BUILD_DIR}/Testing/Temporary/LastTest.log follows:" 618 eerror "Tests failed. Test log ${BUILD_DIR}/Testing/Temporary/LastTest.log follows:"
657 else 623 else
658 die "Tests failed. When you file a bug, please attach the following file: \n\t${BUILD_DIR}/Testing/Temporary/LastTest.log" 624 die "Tests failed. When you file a bug, please attach the following file: \n\t${BUILD_DIR}/Testing/Temporary/LastTest.log"
659 fi 625 fi
660 626
661 # die might not die due to nonfatal 627 # die might not die due to nonfatal
662 popd >/dev/null 628 popd > /dev/null
663 return 1 629 return 1
664 fi 630 fi
631}
632
633enable_cmake-utils_src_install() {
634 debug-print-function ${FUNCNAME} "$@"
635
636 _check_build_dir
637 pushd "${BUILD_DIR}" > /dev/null
638 DESTDIR="${D}" ${CMAKE_MAKEFILE_GENERATOR} install "$@" || die "died running ${CMAKE_MAKEFILE_GENERATOR} install"
639 popd > /dev/null
640
641 pushd "${S}" > /dev/null
642 einstalldocs
643 popd > /dev/null
665} 644}
666 645
667# @FUNCTION: cmake-utils_src_prepare 646# @FUNCTION: cmake-utils_src_prepare
668# @DESCRIPTION: 647# @DESCRIPTION:
669# Apply ebuild and user patches. 648# Apply ebuild and user patches.
679 _execute_optionally "src_configure" "$@" 658 _execute_optionally "src_configure" "$@"
680} 659}
681 660
682# @FUNCTION: cmake-utils_src_compile 661# @FUNCTION: cmake-utils_src_compile
683# @DESCRIPTION: 662# @DESCRIPTION:
684# General function for compiling with cmake. Default behaviour is to check for 663# General function for compiling with cmake.
685# EAPI and respectively to configure as well or just compile.
686# Automatically detects the build type. All arguments are passed to emake. 664# Automatically detects the build type. All arguments are passed to emake.
687cmake-utils_src_compile() { 665cmake-utils_src_compile() {
688 _execute_optionally "src_compile" "$@" 666 _execute_optionally "src_compile" "$@"
689} 667}
690 668
669# @FUNCTION: cmake-utils_src_test
670# @DESCRIPTION:
671# Function for testing the package. Automatically detects the build type.
672cmake-utils_src_test() {
673 _execute_optionally "src_test" "$@"
674}
675
691# @FUNCTION: cmake-utils_src_install 676# @FUNCTION: cmake-utils_src_install
692# @DESCRIPTION: 677# @DESCRIPTION:
693# Function for installing the package. Automatically detects the build type. 678# Function for installing the package. Automatically detects the build type.
694cmake-utils_src_install() { 679cmake-utils_src_install() {
695 _execute_optionally "src_install" "$@" 680 _execute_optionally "src_install" "$@"
696}
697
698# @FUNCTION: cmake-utils_src_test
699# @DESCRIPTION:
700# Function for testing the package. Automatically detects the build type.
701cmake-utils_src_test() {
702 _execute_optionally "src_test" "$@"
703} 681}
704 682
705# Optionally executes phases based on WANT_CMAKE variable/USE flag. 683# Optionally executes phases based on WANT_CMAKE variable/USE flag.
706_execute_optionally() { 684_execute_optionally() {
707 local phase="$1" ; shift 685 local phase="$1" ; shift

Legend:
Removed from v.1.109  
changed lines
  Added in v.1.110

  ViewVC Help
Powered by ViewVC 1.1.20