/[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.91 Revision 1.92
1# Copyright 1999-2012 Gentoo Foundation 1# Copyright 1999-2013 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.91 2013/01/17 20:18:28 creffett Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/cmake-utils.eclass,v 1.92 2013/02/07 15:41:34 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:
26# used for optionality) 26# used for optionality)
27WANT_CMAKE="${WANT_CMAKE:-always}" 27WANT_CMAKE="${WANT_CMAKE:-always}"
28 28
29# @ECLASS-VARIABLE: CMAKE_MIN_VERSION 29# @ECLASS-VARIABLE: CMAKE_MIN_VERSION
30# @DESCRIPTION: 30# @DESCRIPTION:
31# Specify the minimum required CMake version. Default is 2.8.4 31# Specify the minimum required CMake version.
32CMAKE_MIN_VERSION="${CMAKE_MIN_VERSION:-2.8.8}" 32CMAKE_MIN_VERSION="${CMAKE_MIN_VERSION:-2.8.8}"
33 33
34# @ECLASS-VARIABLE: CMAKE_REMOVE_MODULES_LIST 34# @ECLASS-VARIABLE: CMAKE_REMOVE_MODULES_LIST
35# @DESCRIPTION: 35# @DESCRIPTION:
36# Space-separated list of CMake modules that will be removed in $S during src_prepare, 36# Space-separated list of CMake modules that will be removed in $S during src_prepare,
42# Do we want to remove anything? yes or whatever else for no 42# Do we want to remove anything? yes or whatever else for no
43CMAKE_REMOVE_MODULES="${CMAKE_REMOVE_MODULES:-yes}" 43CMAKE_REMOVE_MODULES="${CMAKE_REMOVE_MODULES:-yes}"
44 44
45# @ECLASS-VARIABLE: CMAKE_MAKEFILE_GENERATOR 45# @ECLASS-VARIABLE: CMAKE_MAKEFILE_GENERATOR
46# @DESCRIPTION: 46# @DESCRIPTION:
47# Specify a makefile generator to be used by cmake. At this point only "make" 47# Specify a makefile generator to be used by cmake.
48# and "ninja" is supported. 48# At this point only "emake" and "ninja" are supported.
49CMAKE_MAKEFILE_GENERATOR="${CMAKE_MAKEFILE_GENERATOR:-make}" 49CMAKE_MAKEFILE_GENERATOR="${CMAKE_MAKEFILE_GENERATOR:-emake}"
50 50
51CMAKEDEPEND="" 51CMAKEDEPEND=""
52case ${WANT_CMAKE} in 52case ${WANT_CMAKE} in
53 always) 53 always)
54 ;; 54 ;;
59esac 59esac
60inherit toolchain-funcs multilib flag-o-matic base 60inherit toolchain-funcs multilib flag-o-matic base
61 61
62CMAKE_EXPF="src_compile src_test src_install" 62CMAKE_EXPF="src_compile src_test src_install"
63case ${EAPI:-0} in 63case ${EAPI:-0} in
64 2|3|4|5) CMAKE_EXPF+=" src_configure" ;; 64 2|3|4|5) CMAKE_EXPF+=" src_prepare src_configure" ;;
65 1|0) ;; 65 1|0) ;;
66 *) die "Unknown EAPI, Bug eclass maintainers." ;; 66 *) die "Unknown EAPI, Bug eclass maintainers." ;;
67esac 67esac
68EXPORT_FUNCTIONS ${CMAKE_EXPF} 68EXPORT_FUNCTIONS ${CMAKE_EXPF}
69
70case ${CMAKE_MAKEFILE_GENERATOR} in
71 emake)
72 CMAKEDEPEND+=" sys-devel/make"
73 ;;
74 ninja)
75 CMAKEDEPEND+=" dev-util/ninja"
76 ;;
77 *)
78 eerror "Unknown value for \${CMAKE_MAKEFILE_GENERATOR}"
79 die "Value ${CMAKE_MAKEFILE_GENERATOR} is not supported"
80 ;;
81esac
69 82
70if [[ ${PN} != cmake ]]; then 83if [[ ${PN} != cmake ]]; then
71 CMAKEDEPEND+=" >=dev-util/cmake-${CMAKE_MIN_VERSION}" 84 CMAKEDEPEND+=" >=dev-util/cmake-${CMAKE_MIN_VERSION}"
72fi 85fi
73 86
193 echo ">>> Working in BUILD_DIR: \"$BUILD_DIR\"" 206 echo ">>> Working in BUILD_DIR: \"$BUILD_DIR\""
194} 207}
195 208
196# Determine which generator to use 209# Determine which generator to use
197_generator_to_use() { 210_generator_to_use() {
198 if [[ ${CMAKE_MAKEFILE_GENERATOR} = "ninja" ]]; then 211 local generator_name
199 has_version dev-util/ninja && echo "Ninja" && return 212
200 fi 213 case ${CMAKE_MAKEFILE_GENERATOR} in
201 echo "Unix Makefiles" 214 ninja)
215 generator_name="Ninja"
216 ;;
217 emake)
218 generator_name="Unix Makefiles"
219 ;;
220 *)
221 eerror "Unknown value for \${CMAKE_MAKEFILE_GENERATOR}"
222 die "Value ${CMAKE_MAKEFILE_GENERATOR} is not supported"
223 ;;
224 esac
225
226 echo ${generator_name}
202} 227}
203 228
204# @FUNCTION: cmake-utils_use_with 229# @FUNCTION: cmake-utils_use_with
205# @USAGE: <USE flag> [flag name] 230# @USAGE: <USE flag> [flag name]
206# @DESCRIPTION: 231# @DESCRIPTION:
216# Based on use_enable. See ebuild(5). 241# Based on use_enable. See ebuild(5).
217# 242#
218# `cmake-utils_use_enable foo FOO` echoes -DENABLE_FOO=ON if foo is enabled 243# `cmake-utils_use_enable foo FOO` echoes -DENABLE_FOO=ON if foo is enabled
219# and -DENABLE_FOO=OFF if it is disabled. 244# and -DENABLE_FOO=OFF if it is disabled.
220cmake-utils_use_enable() { _use_me_now ENABLE_ "$@" ; } 245cmake-utils_use_enable() { _use_me_now ENABLE_ "$@" ; }
246
247# @FUNCTION: cmake-utils_use_find_package
248# @USAGE: <USE flag> [flag name]
249# @DESCRIPTION:
250# Based on use_enable. See ebuild(5).
251#
252# `cmake-utils_use_find_package foo FOO` echoes -DCMAKE_DISABLE_FIND_PACKAGE=OFF
253# if foo is enabled and -DCMAKE_DISABLE_FIND_PACKAGE=ON if it is disabled.
254# This can be used to make find_package optional (since cmake-2.8.6).
255cmake-utils_use_find_package() { _use_me_now_inverted CMAKE_DISABLE_FIND_PACKAGE_ "$@" ; }
221 256
222# @FUNCTION: cmake-utils_use_disable 257# @FUNCTION: cmake-utils_use_disable
223# @USAGE: <USE flag> [flag name] 258# @USAGE: <USE flag> [flag name]
224# @DESCRIPTION: 259# @DESCRIPTION:
225# Based on inversion of use_enable. See ebuild(5). 260# Based on inversion of use_enable. See ebuild(5).
311 Linker flags: 346 Linker flags:
312 Executable \${CMAKE_EXE_LINKER_FLAGS} 347 Executable \${CMAKE_EXE_LINKER_FLAGS}
313 Module \${CMAKE_MODULE_LINKER_FLAGS} 348 Module \${CMAKE_MODULE_LINKER_FLAGS}
314 Shared \${CMAKE_SHARED_LINKER_FLAGS}\n") 349 Shared \${CMAKE_SHARED_LINKER_FLAGS}\n")
315 _EOF_ 350 _EOF_
351}
352
353enable_cmake-utils_src_prepare() {
354 debug-print-function ${FUNCNAME} "$@"
355
356 base_src_prepare
316} 357}
317 358
318enable_cmake-utils_src_configure() { 359enable_cmake-utils_src_configure() {
319 debug-print-function ${FUNCNAME} "$@" 360 debug-print-function ${FUNCNAME} "$@"
320 361
431 472
432 has src_configure ${CMAKE_EXPF} || cmake-utils_src_configure 473 has src_configure ${CMAKE_EXPF} || cmake-utils_src_configure
433 cmake-utils_src_make "$@" 474 cmake-utils_src_make "$@"
434} 475}
435 476
477# @FUNCTION: ninja_src_make
478# @INTERNAL
479# @DESCRIPTION:
480# Build the package using ninja generator
481ninja_src_make() {
482 debug-print-function ${FUNCNAME} "$@"
483
484 [[ -e build.ninja ]] || die "Makefile not found. Error during configure stage."
485
486 if [[ "${CMAKE_VERBOSE}" != "OFF" ]]; then
487 # TODO: get load average from portage (-l option)
488 ninja ${MAKEOPTS} -v "$@" || die
489 else
490 ninja "$@" || die
491 fi
492}
493
494# @FUNCTION: make_src_make
495# @INTERNAL
496# @DESCRIPTION:
497# Build the package using make generator
498emake_src_make() {
499 debug-print-function ${FUNCNAME} "$@"
500
501 [[ -e Makefile ]] || die "Makefile not found. Error during configure stage."
502
503 if [[ "${CMAKE_VERBOSE}" != "OFF" ]]; then
504 emake VERBOSE=1 "$@" || die
505 else
506 emake "$@" || die
507 fi
508
509}
510
436# @FUNCTION: cmake-utils_src_make 511# @FUNCTION: cmake-utils_src_make
437# @DESCRIPTION: 512# @DESCRIPTION:
438# Function for building the package. Automatically detects the build type. 513# Function for building the package. Automatically detects the build type.
439# All arguments are passed to emake. 514# All arguments are passed to emake.
440cmake-utils_src_make() { 515cmake-utils_src_make() {
441 debug-print-function ${FUNCNAME} "$@" 516 debug-print-function ${FUNCNAME} "$@"
442 517
443 _check_build_dir 518 _check_build_dir
444 pushd "${BUILD_DIR}" > /dev/null 519 pushd "${BUILD_DIR}" > /dev/null
445 if [[ $(_generator_to_use) = Ninja ]]; then 520
446 # first check if Makefile exist otherwise die 521 ${CMAKE_MAKEFILE_GENERATOR}_src_make $@
447 [[ -e build.ninja ]] || die "Makefile not found. Error during configure stage." 522
448 if [[ "${CMAKE_VERBOSE}" != "OFF" ]]; then
449 #TODO get load average from portage (-l option)
450 ninja ${MAKEOPTS} -v "$@"
451 else
452 ninja "$@"
453 fi || die "ninja failed!"
454 else
455 # first check if Makefile exist otherwise die
456 [[ -e Makefile ]] || die "Makefile not found. Error during configure stage."
457 if [[ "${CMAKE_VERBOSE}" != "OFF" ]]; then
458 emake VERBOSE=1 "$@" || die "Make failed!"
459 else
460 emake "$@" || die "Make failed!"
461 fi
462 fi
463 popd > /dev/null 523 popd > /dev/null
464} 524}
465 525
466enable_cmake-utils_src_install() { 526enable_cmake-utils_src_install() {
467 debug-print-function ${FUNCNAME} "$@" 527 debug-print-function ${FUNCNAME} "$@"
468 528
469 _check_build_dir 529 _check_build_dir
470 pushd "${BUILD_DIR}" > /dev/null 530 pushd "${BUILD_DIR}" > /dev/null
471 if [[ $(_generator_to_use) = Ninja ]]; then 531
472 DESTDIR=${D} ninja install "$@" || die "died running ninja install" 532 DESTDIR="${D}" ${CMAKE_MAKEFILE_GENERATOR} install "$@" || die "died running ${CMAKE_MAKEFILE_GENERATOR} install"
473 base_src_install_docs 533 base_src_install_docs
474 else 534
475 base_src_install "$@"
476 fi
477 popd > /dev/null 535 popd > /dev/null
478 536
479 # Backward compatibility, for non-array variables 537 # Backward compatibility, for non-array variables
480 if [[ -n "${DOCS}" ]] && [[ "$(declare -p DOCS 2>/dev/null 2>&1)" != "declare -a"* ]]; then 538 if [[ -n "${DOCS}" ]] && [[ "$(declare -p DOCS 2>/dev/null 2>&1)" != "declare -a"* ]]; then
481 dodoc ${DOCS} || die "dodoc failed" 539 dodoc ${DOCS} || die "dodoc failed"
514 popd > /dev/null 572 popd > /dev/null
515 return 1 573 return 1
516 fi 574 fi
517} 575}
518 576
577# @FUNCTION: cmake-utils_src_prepare
578# @DESCRIPTION:
579# Wrapper function around base_src_prepare, just to expand the eclass API.
580cmake-utils_src_prepare() {
581 _execute_optionaly "src_prepare" "$@"
582}
583
519# @FUNCTION: cmake-utils_src_configure 584# @FUNCTION: cmake-utils_src_configure
520# @DESCRIPTION: 585# @DESCRIPTION:
521# General function for configuring with cmake. Default behaviour is to start an 586# General function for configuring with cmake. Default behaviour is to start an
522# out-of-source build. 587# out-of-source build.
523cmake-utils_src_configure() { 588cmake-utils_src_configure() {

Legend:
Removed from v.1.91  
changed lines
  Added in v.1.92

  ViewVC Help
Powered by ViewVC 1.1.20