/[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.78 Revision 1.84
1# Copyright 1999-2012 Gentoo Foundation 1# Copyright 1999-2012 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.78 2012/04/16 10:28:47 scarabeus Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/cmake-utils.eclass,v 1.84 2012/10/17 14:09:10 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:
39 39
40# @ECLASS-VARIABLE: CMAKE_REMOVE_MODULES 40# @ECLASS-VARIABLE: CMAKE_REMOVE_MODULES
41# @DESCRIPTION: 41# @DESCRIPTION:
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
45# @ECLASS-VARIABLE: CMAKE_MAKEFILE_GENERATOR
46# @DESCRIPTION:
47# Specify a makefile generator to be used by cmake. At this point only "make"
48# and "ninja" is supported.
49CMAKE_MAKEFILE_GENERATOR="${CMAKE_MAKEFILE_GENERATOR:-make}"
44 50
45CMAKEDEPEND="" 51CMAKEDEPEND=""
46case ${WANT_CMAKE} in 52case ${WANT_CMAKE} in
47 always) 53 always)
48 ;; 54 ;;
53esac 59esac
54inherit toolchain-funcs multilib flag-o-matic base 60inherit toolchain-funcs multilib flag-o-matic base
55 61
56CMAKE_EXPF="src_compile src_test src_install" 62CMAKE_EXPF="src_compile src_test src_install"
57case ${EAPI:-0} in 63case ${EAPI:-0} in
58 4|3|2) CMAKE_EXPF+=" src_configure" ;; 64 2|3|4|5) CMAKE_EXPF+=" src_configure" ;;
59 1|0) ;; 65 1|0) ;;
60 *) die "Unknown EAPI, Bug eclass maintainers." ;; 66 *) die "Unknown EAPI, Bug eclass maintainers." ;;
61esac 67esac
62EXPORT_FUNCTIONS ${CMAKE_EXPF} 68EXPORT_FUNCTIONS ${CMAKE_EXPF}
63
64: ${DESCRIPTION:="Based on the ${ECLASS} eclass"}
65 69
66if [[ ${PN} != cmake ]]; then 70if [[ ${PN} != cmake ]]; then
67 CMAKEDEPEND+=" >=dev-util/cmake-${CMAKE_MIN_VERSION}" 71 CMAKEDEPEND+=" >=dev-util/cmake-${CMAKE_MIN_VERSION}"
68fi 72fi
69 73
137# plugin needs to be done by cmake. 141# plugin needs to be done by cmake.
138# By default it uses ${S}. 142# By default it uses ${S}.
139 143
140# @ECLASS-VARIABLE: CMAKE_VERBOSE 144# @ECLASS-VARIABLE: CMAKE_VERBOSE
141# @DESCRIPTION: 145# @DESCRIPTION:
142# Set to enable verbose messages during compilation. 146# Set to OFF to disable verbose messages during compilation
147: ${CMAKE_VERBOSE:=ON}
143 148
144# @ECLASS-VARIABLE: PREFIX 149# @ECLASS-VARIABLE: PREFIX
145# @DESCRIPTION: 150# @DESCRIPTION:
146# Eclass respects PREFIX variable, though it's not recommended way to set 151# Eclass respects PREFIX variable, though it's not recommended way to set
147# install/lib/bin prefixes. 152# install/lib/bin prefixes.
148# Use -DCMAKE_INSTALL_PREFIX=... CMake variable instead. 153# Use -DCMAKE_INSTALL_PREFIX=... CMake variable instead.
154: ${PREFIX:=/usr}
149 155
150# @ECLASS-VARIABLE: CMAKE_BINARY 156# @ECLASS-VARIABLE: CMAKE_BINARY
151# @DESCRIPTION: 157# @DESCRIPTION:
152# Eclass can use different cmake binary than the one provided in by system. 158# Eclass can use different cmake binary than the one provided in by system.
153: ${CMAKE_BINARY:=cmake} 159: ${CMAKE_BINARY:=cmake}
162 : ${CMAKE_BUILD_DIR:=${WORKDIR}/${P}_build} 168 : ${CMAKE_BUILD_DIR:=${WORKDIR}/${P}_build}
163 fi 169 fi
164 mkdir -p "${CMAKE_BUILD_DIR}" 170 mkdir -p "${CMAKE_BUILD_DIR}"
165 echo ">>> Working in BUILD_DIR: \"$CMAKE_BUILD_DIR\"" 171 echo ">>> Working in BUILD_DIR: \"$CMAKE_BUILD_DIR\""
166} 172}
173
174# Determine which generator to use
175_generator_to_use() {
176 if [[ ${CMAKE_MAKEFILE_GENERATOR} = "ninja" ]]; then
177 has_version dev-util/ninja && echo "Ninja" && return
178 fi
179 echo "Unix Makefiles"
180}
181
167# @FUNCTION: cmake-utils_use_with 182# @FUNCTION: cmake-utils_use_with
168# @USAGE: <USE flag> [flag name] 183# @USAGE: <USE flag> [flag name]
169# @DESCRIPTION: 184# @DESCRIPTION:
170# Based on use_with. See ebuild(5). 185# Based on use_with. See ebuild(5).
171# 186#
310 if ! has debug ${IUSE//+} || ! use debug; then 325 if ! has debug ${IUSE//+} || ! use debug; then
311 append-cppflags -DNDEBUG 326 append-cppflags -DNDEBUG
312 fi 327 fi
313 fi 328 fi
314 329
315 # Prepare Gentoo override rules (set valid compiler, append CPPFLAGS) 330 # Prepare Gentoo override rules (set valid compiler, append CPPFLAGS etc.)
316 local build_rules=${CMAKE_BUILD_DIR}/gentoo_rules.cmake 331 local build_rules=${CMAKE_BUILD_DIR}/gentoo_rules.cmake
317 cat > "${build_rules}" <<- _EOF_ 332 cat > "${build_rules}" <<- _EOF_
333 SET (CMAKE_AR $(type -P $(tc-getAR)) CACHE FILEPATH "Archive manager" FORCE)
318 SET (CMAKE_C_COMPILER $(type -P $(tc-getCC)) CACHE FILEPATH "C compiler" FORCE) 334 SET (CMAKE_C_COMPILER $(type -P $(tc-getCC)) CACHE FILEPATH "C compiler" FORCE)
319 SET (CMAKE_C_COMPILE_OBJECT "<CMAKE_C_COMPILER> <DEFINES> ${CPPFLAGS} <FLAGS> -o <OBJECT> -c <SOURCE>" CACHE STRING "C compile command" FORCE) 335 SET (CMAKE_C_COMPILE_OBJECT "<CMAKE_C_COMPILER> <DEFINES> ${CPPFLAGS} <FLAGS> -o <OBJECT> -c <SOURCE>" CACHE STRING "C compile command" FORCE)
320 SET (CMAKE_CXX_COMPILER $(type -P $(tc-getCXX)) CACHE FILEPATH "C++ compiler" FORCE) 336 SET (CMAKE_CXX_COMPILER $(type -P $(tc-getCXX)) CACHE FILEPATH "C++ compiler" FORCE)
321 SET (CMAKE_CXX_COMPILE_OBJECT "<CMAKE_CXX_COMPILER> <DEFINES> ${CPPFLAGS} <FLAGS> -o <OBJECT> -c <SOURCE>" CACHE STRING "C++ compile command" FORCE) 337 SET (CMAKE_CXX_COMPILE_OBJECT "<CMAKE_CXX_COMPILER> <DEFINES> ${CPPFLAGS} <FLAGS> -o <OBJECT> -c <SOURCE>" CACHE STRING "C++ compile command" FORCE)
338 SET (CMAKE_RANLIB $(type -P $(tc-getRANLIB)) CACHE FILEPATH "Archive index generator" FORCE)
322 _EOF_ 339 _EOF_
323 340
324 has "${EAPI:-0}" 0 1 2 && ! use prefix && EPREFIX= 341 has "${EAPI:-0}" 0 1 2 && ! use prefix && EPREFIX=
325 342
326 if [[ ${EPREFIX} ]]; then 343 if [[ ${EPREFIX} ]]; then
332 SET (CMAKE_PLATFORM_REQUIRED_RUNTIME_PATH "${EPREFIX}/usr/${CHOST}/lib/gcc;${EPREFIX}/usr/${CHOST}/lib;${EPREFIX}/usr/$(get_libdir);${EPREFIX}/$(get_libdir)" 349 SET (CMAKE_PLATFORM_REQUIRED_RUNTIME_PATH "${EPREFIX}/usr/${CHOST}/lib/gcc;${EPREFIX}/usr/${CHOST}/lib;${EPREFIX}/usr/$(get_libdir);${EPREFIX}/$(get_libdir)"
333 CACHE STRING "" FORCE) 350 CACHE STRING "" FORCE)
334 351
335 ELSE () 352 ELSE ()
336 353
337 SET(CMAKE_PREFIX_PATH "${EPREFIX}${PREFIX:-/usr}" CACHE STRING ""FORCE) 354 SET(CMAKE_PREFIX_PATH "${EPREFIX}${PREFIX}" CACHE STRING ""FORCE)
338 SET(CMAKE_SKIP_BUILD_RPATH OFF CACHE BOOL "" FORCE) 355 SET(CMAKE_SKIP_BUILD_RPATH OFF CACHE BOOL "" FORCE)
339 SET(CMAKE_SKIP_RPATH OFF CACHE BOOL "" FORCE) 356 SET(CMAKE_SKIP_RPATH OFF CACHE BOOL "" FORCE)
340 SET(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE CACHE BOOL "") 357 SET(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE CACHE BOOL "")
341 SET(CMAKE_INSTALL_RPATH "${EPREFIX}${PREFIX:-/usr}/lib;${EPREFIX}/usr/${CHOST}/lib/gcc;${EPREFIX}/usr/${CHOST}/lib;${EPREFIX}/usr/$(get_libdir);${EPREFIX}/$(get_libdir)" CACHE STRING "" FORCE) 358 SET(CMAKE_INSTALL_RPATH "${EPREFIX}${PREFIX}/lib;${EPREFIX}/usr/${CHOST}/lib/gcc;${EPREFIX}/usr/${CHOST}/lib;${EPREFIX}/usr/$(get_libdir);${EPREFIX}/$(get_libdir)" CACHE STRING "" FORCE)
342 SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE CACHE BOOL "" FORCE) 359 SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE CACHE BOOL "" FORCE)
343 SET(CMAKE_INSTALL_NAME_DIR "${EPREFIX}${PREFIX:-/usr}/lib" CACHE STRING "" FORCE) 360 SET(CMAKE_INSTALL_NAME_DIR "${EPREFIX}${PREFIX}/lib" CACHE STRING "" FORCE)
344 361
345 ENDIF (NOT APPLE) 362 ENDIF (NOT APPLE)
346 _EOF_ 363 _EOF_
347 fi 364 fi
348 365
368 # NOTE CMAKE_BUILD_TYPE can be only overriden via CMAKE_BUILD_TYPE eclass variable 385 # NOTE CMAKE_BUILD_TYPE can be only overriden via CMAKE_BUILD_TYPE eclass variable
369 # No -DCMAKE_BUILD_TYPE=xxx definitions will be in effect. 386 # No -DCMAKE_BUILD_TYPE=xxx definitions will be in effect.
370 local cmakeargs=( 387 local cmakeargs=(
371 --no-warn-unused-cli 388 --no-warn-unused-cli
372 -C "${common_config}" 389 -C "${common_config}"
390 -G "$(_generator_to_use)"
373 -DCMAKE_INSTALL_PREFIX="${EPREFIX}${PREFIX:-/usr}" 391 -DCMAKE_INSTALL_PREFIX="${EPREFIX}${PREFIX}"
374 "${mycmakeargs_local[@]}" 392 "${mycmakeargs_local[@]}"
375 -DCMAKE_BUILD_TYPE="${CMAKE_BUILD_TYPE}" 393 -DCMAKE_BUILD_TYPE="${CMAKE_BUILD_TYPE}"
376 -DCMAKE_INSTALL_DO_STRIP=OFF 394 -DCMAKE_INSTALL_DO_STRIP=OFF
377 -DCMAKE_USER_MAKE_RULES_OVERRIDE="${build_rules}" 395 -DCMAKE_USER_MAKE_RULES_OVERRIDE="${build_rules}"
378 "${MYCMAKEARGS}" 396 "${MYCMAKEARGS}"
399cmake-utils_src_make() { 417cmake-utils_src_make() {
400 debug-print-function ${FUNCNAME} "$@" 418 debug-print-function ${FUNCNAME} "$@"
401 419
402 _check_build_dir 420 _check_build_dir
403 pushd "${CMAKE_BUILD_DIR}" > /dev/null 421 pushd "${CMAKE_BUILD_DIR}" > /dev/null
422 if [[ $(_generator_to_use) = Ninja ]]; then
404 # first check if Makefile exist otherwise die 423 # first check if Makefile exist otherwise die
424 [[ -e build.ninja ]] || die "Makefile not found. Error during configure stage."
425 if [[ "${CMAKE_VERBOSE}" != "OFF" ]]; then
426 #TODO get load average from portage (-l option)
427 ninja ${MAKEOPTS} -v "$@"
428 else
429 ninja "$@"
430 fi || die "ninja failed!"
431 else
432 # first check if Makefile exist otherwise die
405 [[ -e Makefile ]] || die "Makefile not found. Error during configure stage." 433 [[ -e Makefile ]] || die "Makefile not found. Error during configure stage."
406 if [[ -n ${CMAKE_VERBOSE} ]]; then 434 if [[ "${CMAKE_VERBOSE}" != "OFF" ]]; then
407 emake VERBOSE=1 "$@" || die "Make failed!" 435 emake VERBOSE=1 "$@" || die "Make failed!"
408 else 436 else
409 emake "$@" || die "Make failed!" 437 emake "$@" || die "Make failed!"
438 fi
410 fi 439 fi
411 popd > /dev/null 440 popd > /dev/null
412} 441}
413 442
414enable_cmake-utils_src_install() { 443enable_cmake-utils_src_install() {
415 debug-print-function ${FUNCNAME} "$@" 444 debug-print-function ${FUNCNAME} "$@"
416 445
417 _check_build_dir 446 _check_build_dir
418 pushd "${CMAKE_BUILD_DIR}" > /dev/null 447 pushd "${CMAKE_BUILD_DIR}" > /dev/null
448 if [[ $(_generator_to_use) = Ninja ]]; then
449 DESTDIR=${D} ninja install "$@" || die "died running ninja install"
450 base_src_install_docs
451 else
419 base_src_install "$@" 452 base_src_install "$@"
453 fi
420 popd > /dev/null 454 popd > /dev/null
421 455
422 # Backward compatibility, for non-array variables 456 # Backward compatibility, for non-array variables
423 if [[ -n "${DOCS}" ]] && [[ "$(declare -p DOCS 2>/dev/null 2>&1)" != "declare -a"* ]]; then 457 if [[ -n "${DOCS}" ]] && [[ "$(declare -p DOCS 2>/dev/null 2>&1)" != "declare -a"* ]]; then
424 dodoc ${DOCS} || die "dodoc failed" 458 dodoc ${DOCS} || die "dodoc failed"
438 472
439 [[ -n ${TEST_VERBOSE} ]] && ctestargs="--extra-verbose --output-on-failure" 473 [[ -n ${TEST_VERBOSE} ]] && ctestargs="--extra-verbose --output-on-failure"
440 474
441 if ctest ${ctestargs} "$@" ; then 475 if ctest ${ctestargs} "$@" ; then
442 einfo "Tests succeeded." 476 einfo "Tests succeeded."
477 popd > /dev/null
478 return 0
443 else 479 else
444 if [[ -n "${CMAKE_YES_I_WANT_TO_SEE_THE_TEST_LOG}" ]] ; then 480 if [[ -n "${CMAKE_YES_I_WANT_TO_SEE_THE_TEST_LOG}" ]] ; then
445 # on request from Diego 481 # on request from Diego
446 eerror "Tests failed. Test log ${CMAKE_BUILD_DIR}/Testing/Temporary/LastTest.log follows:" 482 eerror "Tests failed. Test log ${CMAKE_BUILD_DIR}/Testing/Temporary/LastTest.log follows:"
447 eerror "--START TEST LOG--------------------------------------------------------------" 483 eerror "--START TEST LOG--------------------------------------------------------------"
449 eerror "--END TEST LOG----------------------------------------------------------------" 485 eerror "--END TEST LOG----------------------------------------------------------------"
450 die "Tests failed." 486 die "Tests failed."
451 else 487 else
452 die "Tests failed. When you file a bug, please attach the following file: \n\t${CMAKE_BUILD_DIR}/Testing/Temporary/LastTest.log" 488 die "Tests failed. When you file a bug, please attach the following file: \n\t${CMAKE_BUILD_DIR}/Testing/Temporary/LastTest.log"
453 fi 489 fi
454 fi 490
491 # die might not die due to nonfatal
455 popd > /dev/null 492 popd > /dev/null
493 return 1
494 fi
456} 495}
457 496
458# @FUNCTION: cmake-utils_src_configure 497# @FUNCTION: cmake-utils_src_configure
459# @DESCRIPTION: 498# @DESCRIPTION:
460# General function for configuring with cmake. Default behaviour is to start an 499# General function for configuring with cmake. Default behaviour is to start an

Legend:
Removed from v.1.78  
changed lines
  Added in v.1.84

  ViewVC Help
Powered by ViewVC 1.1.20