/[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.82 Revision 1.89
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.82 2012/09/27 16:35:41 axs Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/cmake-utils.eclass,v 1.89 2012/12/03 12:05:51 mgorny 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:
112 echo "-D$1$x=$(use $2 && echo OFF || echo ON) " 112 echo "-D$1$x=$(use $2 && echo OFF || echo ON) "
113 done 113 done
114 fi 114 fi
115} 115}
116 116
117# @ECLASS-VARIABLE: CMAKE_BUILD_DIR 117# @ECLASS-VARIABLE: BUILD_DIR
118# @DESCRIPTION: 118# @DESCRIPTION:
119# Build directory where all cmake processed files should be generated. 119# Build directory where all cmake processed files should be generated.
120# For in-source build it's fixed to ${CMAKE_USE_DIR}. 120# For in-source build it's fixed to ${CMAKE_USE_DIR}.
121# For out-of-source build it can be overriden, by default it uses 121# For out-of-source build it can be overriden, by default it uses
122# ${WORKDIR}/${P}_build. 122# ${WORKDIR}/${P}_build.
123#
124# This variable has been called CMAKE_BUILD_DIR formerly.
125# It is set under that name for compatibility.
123 126
124# @ECLASS-VARIABLE: CMAKE_BUILD_TYPE 127# @ECLASS-VARIABLE: CMAKE_BUILD_TYPE
125# @DESCRIPTION: 128# @DESCRIPTION:
126# Set to override default CMAKE_BUILD_TYPE. Only useful for packages 129# Set to override default CMAKE_BUILD_TYPE. Only useful for packages
127# known to make use of "if (CMAKE_BUILD_TYPE MATCHES xxx)". 130# known to make use of "if (CMAKE_BUILD_TYPE MATCHES xxx)".
161# Determine using IN or OUT source build 164# Determine using IN or OUT source build
162_check_build_dir() { 165_check_build_dir() {
163 : ${CMAKE_USE_DIR:=${S}} 166 : ${CMAKE_USE_DIR:=${S}}
164 if [[ -n ${CMAKE_IN_SOURCE_BUILD} ]]; then 167 if [[ -n ${CMAKE_IN_SOURCE_BUILD} ]]; then
165 # we build in source dir 168 # we build in source dir
166 CMAKE_BUILD_DIR="${CMAKE_USE_DIR}" 169 BUILD_DIR="${CMAKE_USE_DIR}"
170 else
171 # Respect both the old variable and the new one, depending
172 # on which one was set by the ebuild.
173 if [[ ! ${BUILD_DIR} && ${CMAKE_BUILD_DIR} ]]; then
174 eqawarn "The CMAKE_BUILD_DIR variable has been renamed to BUILD_DIR."
175 eqawarn "Please migrate the ebuild to use the new one."
176
177 # In the next call, both variables will be set already
178 # and we'd have to know which one takes precedence.
179 _RESPECT_CMAKE_BUILD_DIR=1
180 fi
181
182 if [[ ${_RESPECT_CMAKE_BUILD_DIR} ]]; then
183 BUILD_DIR=${CMAKE_BUILD_DIR:-${WORKDIR}/${P}_build}
167 else 184 else
168 : ${CMAKE_BUILD_DIR:=${WORKDIR}/${P}_build} 185 : ${BUILD_DIR:=${WORKDIR}/${P}_build}
169 fi 186 fi
187 fi
188
189 # Backwards compatibility for getting the value.
190 CMAKE_BUILD_DIR=${BUILD_DIR}
191
170 mkdir -p "${CMAKE_BUILD_DIR}" 192 mkdir -p "${BUILD_DIR}"
171 echo ">>> Working in BUILD_DIR: \"$CMAKE_BUILD_DIR\"" 193 echo ">>> Working in BUILD_DIR: \"$BUILD_DIR\""
172} 194}
173 195
174# Determine which generator to use 196# Determine which generator to use
175_generator_to_use() { 197_generator_to_use() {
176 if [[ ${CMAKE_MAKEFILE_GENERATOR} = "ninja" ]]; then 198 if [[ ${CMAKE_MAKEFILE_GENERATOR} = "ninja" ]]; then
264# Removes dangerous definitions that override Gentoo settings. 286# Removes dangerous definitions that override Gentoo settings.
265_modify-cmakelists() { 287_modify-cmakelists() {
266 debug-print-function ${FUNCNAME} "$@" 288 debug-print-function ${FUNCNAME} "$@"
267 289
268 # Only edit the files once 290 # Only edit the files once
269 grep -qs "<<< Gentoo configuration >>>" CMakeLists.txt && return 0 291 grep -qs "<<< Gentoo configuration >>>" "${CMAKE_USE_DIR}"/CMakeLists.txt && return 0
270 292
271 # Comment out all set (<some_should_be_user_defined_variable> value) 293 # Comment out all set (<some_should_be_user_defined_variable> value)
272 # TODO Add QA checker - inform when variable being checked for below is set in CMakeLists.txt 294 # TODO Add QA checker - inform when variable being checked for below is set in CMakeLists.txt
273 find "${CMAKE_USE_DIR}" -name CMakeLists.txt \ 295 find "${CMAKE_USE_DIR}" -name CMakeLists.txt \
274 -exec sed -i -e '/^[[:space:]]*[sS][eE][tT][[:space:]]*([[:space:]]*CMAKE_BUILD_TYPE.*)/{s/^/#IGNORE /g}' {} + \ 296 -exec sed -i -e '/^[[:space:]]*[sS][eE][tT][[:space:]]*([[:space:]]*CMAKE_BUILD_TYPE.*)/{s/^/#IGNORE /g}' {} + \
325 if ! has debug ${IUSE//+} || ! use debug; then 347 if ! has debug ${IUSE//+} || ! use debug; then
326 append-cppflags -DNDEBUG 348 append-cppflags -DNDEBUG
327 fi 349 fi
328 fi 350 fi
329 351
330 # Prepare Gentoo override rules (set valid compiler, append CPPFLAGS) 352 # Prepare Gentoo override rules (set valid compiler, append CPPFLAGS etc.)
331 local build_rules=${CMAKE_BUILD_DIR}/gentoo_rules.cmake 353 local build_rules=${BUILD_DIR}/gentoo_rules.cmake
332 cat > "${build_rules}" <<- _EOF_ 354 cat > "${build_rules}" <<- _EOF_
355 SET (CMAKE_AR $(type -P $(tc-getAR)) CACHE FILEPATH "Archive manager" FORCE)
333 SET (CMAKE_C_COMPILER $(type -P $(tc-getCC)) CACHE FILEPATH "C compiler" FORCE) 356 SET (CMAKE_C_COMPILER $(type -P $(tc-getCC)) CACHE FILEPATH "C compiler" FORCE)
334 SET (CMAKE_C_COMPILE_OBJECT "<CMAKE_C_COMPILER> <DEFINES> ${CPPFLAGS} <FLAGS> -o <OBJECT> -c <SOURCE>" CACHE STRING "C compile command" FORCE) 357 SET (CMAKE_C_COMPILE_OBJECT "<CMAKE_C_COMPILER> <DEFINES> ${CPPFLAGS} <FLAGS> -o <OBJECT> -c <SOURCE>" CACHE STRING "C compile command" FORCE)
335 SET (CMAKE_CXX_COMPILER $(type -P $(tc-getCXX)) CACHE FILEPATH "C++ compiler" FORCE) 358 SET (CMAKE_CXX_COMPILER $(type -P $(tc-getCXX)) CACHE FILEPATH "C++ compiler" FORCE)
336 SET (CMAKE_CXX_COMPILE_OBJECT "<CMAKE_CXX_COMPILER> <DEFINES> ${CPPFLAGS} <FLAGS> -o <OBJECT> -c <SOURCE>" CACHE STRING "C++ compile command" FORCE) 359 SET (CMAKE_CXX_COMPILE_OBJECT "<CMAKE_CXX_COMPILER> <DEFINES> ${CPPFLAGS} <FLAGS> -o <OBJECT> -c <SOURCE>" CACHE STRING "C++ compile command" FORCE)
360 SET (CMAKE_RANLIB $(type -P $(tc-getRANLIB)) CACHE FILEPATH "Archive index generator" FORCE)
337 _EOF_ 361 _EOF_
338 362
339 has "${EAPI:-0}" 0 1 2 && ! use prefix && EPREFIX= 363 has "${EAPI:-0}" 0 1 2 && ! use prefix && EPREFIX=
340 364
341 if [[ ${EPREFIX} ]]; then 365 if [[ ${EPREFIX} ]]; then
360 ENDIF (NOT APPLE) 384 ENDIF (NOT APPLE)
361 _EOF_ 385 _EOF_
362 fi 386 fi
363 387
364 # Common configure parameters (invariants) 388 # Common configure parameters (invariants)
365 local common_config=${CMAKE_BUILD_DIR}/gentoo_common_config.cmake 389 local common_config=${BUILD_DIR}/gentoo_common_config.cmake
366 local libdir=$(get_libdir) 390 local libdir=$(get_libdir)
367 cat > "${common_config}" <<- _EOF_ 391 cat > "${common_config}" <<- _EOF_
368 SET (LIB_SUFFIX ${libdir/lib} CACHE STRING "library path suffix" FORCE) 392 SET (LIB_SUFFIX ${libdir/lib} CACHE STRING "library path suffix" FORCE)
369 SET (CMAKE_INSTALL_LIBDIR ${libdir} CACHE PATH "Output directory for libraries") 393 SET (CMAKE_INSTALL_LIBDIR ${libdir} CACHE PATH "Output directory for libraries")
370 _EOF_ 394 _EOF_
392 -DCMAKE_INSTALL_DO_STRIP=OFF 416 -DCMAKE_INSTALL_DO_STRIP=OFF
393 -DCMAKE_USER_MAKE_RULES_OVERRIDE="${build_rules}" 417 -DCMAKE_USER_MAKE_RULES_OVERRIDE="${build_rules}"
394 "${MYCMAKEARGS}" 418 "${MYCMAKEARGS}"
395 ) 419 )
396 420
397 pushd "${CMAKE_BUILD_DIR}" > /dev/null 421 pushd "${BUILD_DIR}" > /dev/null
398 debug-print "${LINENO} ${ECLASS} ${FUNCNAME}: mycmakeargs is ${mycmakeargs_local[*]}" 422 debug-print "${LINENO} ${ECLASS} ${FUNCNAME}: mycmakeargs is ${mycmakeargs_local[*]}"
399 echo "${CMAKE_BINARY}" "${cmakeargs[@]}" "${CMAKE_USE_DIR}" 423 echo "${CMAKE_BINARY}" "${cmakeargs[@]}" "${CMAKE_USE_DIR}"
400 "${CMAKE_BINARY}" "${cmakeargs[@]}" "${CMAKE_USE_DIR}" || die "cmake failed" 424 "${CMAKE_BINARY}" "${cmakeargs[@]}" "${CMAKE_USE_DIR}" || die "cmake failed"
401 popd > /dev/null 425 popd > /dev/null
402} 426}
414# All arguments are passed to emake. 438# All arguments are passed to emake.
415cmake-utils_src_make() { 439cmake-utils_src_make() {
416 debug-print-function ${FUNCNAME} "$@" 440 debug-print-function ${FUNCNAME} "$@"
417 441
418 _check_build_dir 442 _check_build_dir
419 pushd "${CMAKE_BUILD_DIR}" > /dev/null 443 pushd "${BUILD_DIR}" > /dev/null
420 if [[ $(_generator_to_use) = Ninja ]]; then 444 if [[ $(_generator_to_use) = Ninja ]]; then
421 # first check if Makefile exist otherwise die 445 # first check if Makefile exist otherwise die
422 [[ -e build.ninja ]] || die "Makefile not found. Error during configure stage." 446 [[ -e build.ninja ]] || die "Makefile not found. Error during configure stage."
423 if [[ "${CMAKE_VERBOSE}" != "OFF" ]]; then 447 if [[ "${CMAKE_VERBOSE}" != "OFF" ]]; then
424 #TODO get load average from portage (-l option) 448 #TODO get load average from portage (-l option)
440 464
441enable_cmake-utils_src_install() { 465enable_cmake-utils_src_install() {
442 debug-print-function ${FUNCNAME} "$@" 466 debug-print-function ${FUNCNAME} "$@"
443 467
444 _check_build_dir 468 _check_build_dir
445 pushd "${CMAKE_BUILD_DIR}" > /dev/null 469 pushd "${BUILD_DIR}" > /dev/null
446 if [[ $(_generator_to_use) = Ninja ]]; then 470 if [[ $(_generator_to_use) = Ninja ]]; then
447 DESTDIR=${D} ninja install "$@" || die "died running ninja install" 471 DESTDIR=${D} ninja install "$@" || die "died running ninja install"
448 base_src_install_docs 472 base_src_install_docs
449 else 473 else
450 base_src_install "$@" 474 base_src_install "$@"
463enable_cmake-utils_src_test() { 487enable_cmake-utils_src_test() {
464 debug-print-function ${FUNCNAME} "$@" 488 debug-print-function ${FUNCNAME} "$@"
465 local ctestargs 489 local ctestargs
466 490
467 _check_build_dir 491 _check_build_dir
468 pushd "${CMAKE_BUILD_DIR}" > /dev/null 492 pushd "${BUILD_DIR}" > /dev/null
469 [[ -e CTestTestfile.cmake ]] || { echo "No tests found. Skipping."; return 0 ; } 493 [[ -e CTestTestfile.cmake ]] || { echo "No tests found. Skipping."; return 0 ; }
470 494
471 [[ -n ${TEST_VERBOSE} ]] && ctestargs="--extra-verbose --output-on-failure" 495 [[ -n ${TEST_VERBOSE} ]] && ctestargs="--extra-verbose --output-on-failure"
472 496
473 if ctest ${ctestargs} "$@" ; then 497 if ctest ${ctestargs} "$@" ; then
474 einfo "Tests succeeded." 498 einfo "Tests succeeded."
499 popd > /dev/null
500 return 0
475 else 501 else
476 if [[ -n "${CMAKE_YES_I_WANT_TO_SEE_THE_TEST_LOG}" ]] ; then 502 if [[ -n "${CMAKE_YES_I_WANT_TO_SEE_THE_TEST_LOG}" ]] ; then
477 # on request from Diego 503 # on request from Diego
478 eerror "Tests failed. Test log ${CMAKE_BUILD_DIR}/Testing/Temporary/LastTest.log follows:" 504 eerror "Tests failed. Test log ${BUILD_DIR}/Testing/Temporary/LastTest.log follows:"
479 eerror "--START TEST LOG--------------------------------------------------------------" 505 eerror "--START TEST LOG--------------------------------------------------------------"
480 cat "${CMAKE_BUILD_DIR}/Testing/Temporary/LastTest.log" 506 cat "${BUILD_DIR}/Testing/Temporary/LastTest.log"
481 eerror "--END TEST LOG----------------------------------------------------------------" 507 eerror "--END TEST LOG----------------------------------------------------------------"
482 die "Tests failed." 508 die "Tests failed."
483 else 509 else
484 die "Tests failed. When you file a bug, please attach the following file: \n\t${CMAKE_BUILD_DIR}/Testing/Temporary/LastTest.log" 510 die "Tests failed. When you file a bug, please attach the following file: \n\t${BUILD_DIR}/Testing/Temporary/LastTest.log"
485 fi 511 fi
486 fi 512
513 # die might not die due to nonfatal
487 popd > /dev/null 514 popd > /dev/null
515 return 1
516 fi
488} 517}
489 518
490# @FUNCTION: cmake-utils_src_configure 519# @FUNCTION: cmake-utils_src_configure
491# @DESCRIPTION: 520# @DESCRIPTION:
492# General function for configuring with cmake. Default behaviour is to start an 521# General function for configuring with cmake. Default behaviour is to start an

Legend:
Removed from v.1.82  
changed lines
  Added in v.1.89

  ViewVC Help
Powered by ViewVC 1.1.20