| 1 | # Copyright 1999-2010 Gentoo Foundation |
1 | # Copyright 1999-2010 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.59 2010/09/16 16:04:11 reavertm Exp $ |
3 | # $Header: /var/cvsroot/gentoo-x86/eclass/cmake-utils.eclass,v 1.67 2011/03/18 19:45:49 scarabeus 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 | # |
8 | # |
| … | |
… | |
| 28 | # used for optionality) |
28 | # used for optionality) |
| 29 | WANT_CMAKE="${WANT_CMAKE:-always}" |
29 | WANT_CMAKE="${WANT_CMAKE:-always}" |
| 30 | |
30 | |
| 31 | # @ECLASS-VARIABLE: CMAKE_MIN_VERSION |
31 | # @ECLASS-VARIABLE: CMAKE_MIN_VERSION |
| 32 | # @DESCRIPTION: |
32 | # @DESCRIPTION: |
| 33 | # Specify the minimum required CMake version. Default is 2.6.2-r1 |
33 | # Specify the minimum required CMake version. Default is 2.8.1 |
| 34 | CMAKE_MIN_VERSION="${CMAKE_MIN_VERSION:-2.6.2-r1}" |
34 | CMAKE_MIN_VERSION="${CMAKE_MIN_VERSION:-2.8.1}" |
| 35 | |
35 | |
| 36 | CMAKEDEPEND="" |
36 | CMAKEDEPEND="" |
| 37 | case ${WANT_CMAKE} in |
37 | case ${WANT_CMAKE} in |
| 38 | always) |
38 | always) |
| 39 | ;; |
39 | ;; |
| … | |
… | |
| 44 | esac |
44 | esac |
| 45 | inherit toolchain-funcs multilib flag-o-matic base |
45 | inherit toolchain-funcs multilib flag-o-matic base |
| 46 | |
46 | |
| 47 | CMAKE_EXPF="src_compile src_test src_install" |
47 | CMAKE_EXPF="src_compile src_test src_install" |
| 48 | case ${EAPI:-0} in |
48 | case ${EAPI:-0} in |
| 49 | 3|2) CMAKE_EXPF+=" src_configure" ;; |
49 | 4|3|2) CMAKE_EXPF+=" src_configure" ;; |
| 50 | 1|0) ;; |
50 | 1|0) ;; |
| 51 | *) die "Unknown EAPI, Bug eclass maintainers." ;; |
51 | *) die "Unknown EAPI, Bug eclass maintainers." ;; |
| 52 | esac |
52 | esac |
| 53 | EXPORT_FUNCTIONS ${CMAKE_EXPF} |
53 | EXPORT_FUNCTIONS ${CMAKE_EXPF} |
| 54 | |
54 | |
| … | |
… | |
| 135 | # @ECLASS-VARIABLE: PREFIX |
135 | # @ECLASS-VARIABLE: PREFIX |
| 136 | # @DESCRIPTION: |
136 | # @DESCRIPTION: |
| 137 | # Eclass respects PREFIX variable, though it's not recommended way to set |
137 | # Eclass respects PREFIX variable, though it's not recommended way to set |
| 138 | # install/lib/bin prefixes. |
138 | # install/lib/bin prefixes. |
| 139 | # Use -DCMAKE_INSTALL_PREFIX=... CMake variable instead. |
139 | # Use -DCMAKE_INSTALL_PREFIX=... CMake variable instead. |
|
|
140 | |
|
|
141 | # @ECLASS-VARIABLE: CMAKE_BINARY |
|
|
142 | # @DESCRIPTION: |
|
|
143 | # Eclass can use different cmake binary than the one provided in by system. |
|
|
144 | : ${CMAKE_BINARY:=cmake} |
| 140 | |
145 | |
| 141 | # Determine using IN or OUT source build |
146 | # Determine using IN or OUT source build |
| 142 | _check_build_dir() { |
147 | _check_build_dir() { |
| 143 | : ${CMAKE_USE_DIR:=${S}} |
148 | : ${CMAKE_USE_DIR:=${S}} |
| 144 | if [[ -n ${CMAKE_IN_SOURCE_BUILD} ]]; then |
149 | if [[ -n ${CMAKE_IN_SOURCE_BUILD} ]]; then |
| … | |
… | |
| 261 | } |
266 | } |
| 262 | |
267 | |
| 263 | enable_cmake-utils_src_configure() { |
268 | enable_cmake-utils_src_configure() { |
| 264 | debug-print-function ${FUNCNAME} "$@" |
269 | debug-print-function ${FUNCNAME} "$@" |
| 265 | |
270 | |
| 266 | _check_build_dir init |
271 | _check_build_dir |
| 267 | |
272 | |
| 268 | # check if CMakeLists.txt exist and if no then die |
273 | # check if CMakeLists.txt exist and if no then die |
| 269 | if [[ ! -e ${CMAKE_USE_DIR}/CMakeLists.txt ]] ; then |
274 | if [[ ! -e ${CMAKE_USE_DIR}/CMakeLists.txt ]] ; then |
| 270 | eerror "Unable to locate CMakeLists.txt under:" |
275 | eerror "Unable to locate CMakeLists.txt under:" |
| 271 | eerror "\"${CMAKE_USE_DIR}/CMakeLists.txt\"" |
276 | eerror "\"${CMAKE_USE_DIR}/CMakeLists.txt\"" |
| … | |
… | |
| 302 | # right ... except for Darwin hosts |
307 | # right ... except for Darwin hosts |
| 303 | IF (NOT APPLE) |
308 | IF (NOT APPLE) |
| 304 | SET (CMAKE_SKIP_RPATH OFF CACHE BOOL "" FORCE) |
309 | SET (CMAKE_SKIP_RPATH OFF CACHE BOOL "" FORCE) |
| 305 | SET (CMAKE_PLATFORM_REQUIRED_RUNTIME_PATH "${EPREFIX}/usr/${CHOST}/lib/gcc;${EPREFIX}/usr/${CHOST}/lib;${EPREFIX}/usr/$(get_libdir);${EPREFIX}/$(get_libdir)" |
310 | SET (CMAKE_PLATFORM_REQUIRED_RUNTIME_PATH "${EPREFIX}/usr/${CHOST}/lib/gcc;${EPREFIX}/usr/${CHOST}/lib;${EPREFIX}/usr/$(get_libdir);${EPREFIX}/$(get_libdir)" |
| 306 | CACHE STRING "" FORCE) |
311 | CACHE STRING "" FORCE) |
|
|
312 | |
|
|
313 | ELSE () |
|
|
314 | |
|
|
315 | SET(CMAKE_PREFIX_PATH "${EPREFIX}${PREFIX:-/usr}" CACHE STRING ""FORCE) |
|
|
316 | SET(CMAKE_SKIP_BUILD_RPATH OFF CACHE BOOL "" FORCE) |
|
|
317 | SET(CMAKE_SKIP_RPATH OFF CACHE BOOL "" FORCE) |
|
|
318 | SET(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE CACHE BOOL "" FORCE) |
|
|
319 | 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) |
|
|
320 | SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE CACHE BOOL "" FORCE) |
|
|
321 | SET(CMAKE_INSTALL_NAME_DIR "${EPREFIX}${PREFIX:-/usr}/lib" CACHE STRING "" FORCE) |
|
|
322 | |
| 307 | ENDIF (NOT APPLE) |
323 | ENDIF (NOT APPLE) |
| 308 | _EOF_ |
324 | _EOF_ |
| 309 | fi |
325 | fi |
| 310 | |
326 | |
| 311 | # Common configure parameters (invariants) |
327 | # Common configure parameters (invariants) |
| … | |
… | |
| 330 | |
346 | |
| 331 | # Common configure parameters (overridable) |
347 | # Common configure parameters (overridable) |
| 332 | # NOTE CMAKE_BUILD_TYPE can be only overriden via CMAKE_BUILD_TYPE eclass variable |
348 | # NOTE CMAKE_BUILD_TYPE can be only overriden via CMAKE_BUILD_TYPE eclass variable |
| 333 | # No -DCMAKE_BUILD_TYPE=xxx definitions will be in effect. |
349 | # No -DCMAKE_BUILD_TYPE=xxx definitions will be in effect. |
| 334 | local cmakeargs=( |
350 | local cmakeargs=( |
|
|
351 | --no-warn-unused-cli |
| 335 | -C "${common_config}" |
352 | -C "${common_config}" |
| 336 | -DCMAKE_INSTALL_PREFIX="${EPREFIX}${PREFIX:-/usr}" |
353 | -DCMAKE_INSTALL_PREFIX="${EPREFIX}${PREFIX:-/usr}" |
| 337 | "${mycmakeargs_local[@]}" |
354 | "${mycmakeargs_local[@]}" |
| 338 | -DCMAKE_BUILD_TYPE="${CMAKE_BUILD_TYPE}" |
355 | -DCMAKE_BUILD_TYPE="${CMAKE_BUILD_TYPE}" |
| 339 | -DCMAKE_INSTALL_DO_STRIP=OFF |
356 | -DCMAKE_INSTALL_DO_STRIP=OFF |
| … | |
… | |
| 342 | ) |
359 | ) |
| 343 | |
360 | |
| 344 | mkdir -p "${CMAKE_BUILD_DIR}" |
361 | mkdir -p "${CMAKE_BUILD_DIR}" |
| 345 | pushd "${CMAKE_BUILD_DIR}" > /dev/null |
362 | pushd "${CMAKE_BUILD_DIR}" > /dev/null |
| 346 | debug-print "${LINENO} ${ECLASS} ${FUNCNAME}: mycmakeargs is ${mycmakeargs_local[*]}" |
363 | debug-print "${LINENO} ${ECLASS} ${FUNCNAME}: mycmakeargs is ${mycmakeargs_local[*]}" |
| 347 | echo cmake "${cmakeargs[@]}" "${CMAKE_USE_DIR}" |
364 | echo "${CMAKE_BINARY}" "${cmakeargs[@]}" "${CMAKE_USE_DIR}" |
| 348 | cmake "${cmakeargs[@]}" "${CMAKE_USE_DIR}" || die "cmake failed" |
365 | "${CMAKE_BINARY}" "${cmakeargs[@]}" "${CMAKE_USE_DIR}" || die "cmake failed" |
| 349 | popd > /dev/null |
366 | popd > /dev/null |
| 350 | } |
367 | } |
| 351 | |
368 | |
| 352 | enable_cmake-utils_src_compile() { |
369 | enable_cmake-utils_src_compile() { |
| 353 | debug-print-function ${FUNCNAME} "$@" |
370 | debug-print-function ${FUNCNAME} "$@" |
| … | |
… | |
| 378 | enable_cmake-utils_src_install() { |
395 | enable_cmake-utils_src_install() { |
| 379 | debug-print-function ${FUNCNAME} "$@" |
396 | debug-print-function ${FUNCNAME} "$@" |
| 380 | |
397 | |
| 381 | _check_build_dir |
398 | _check_build_dir |
| 382 | pushd "${CMAKE_BUILD_DIR}" > /dev/null |
399 | pushd "${CMAKE_BUILD_DIR}" > /dev/null |
| 383 | base_src_install |
400 | base_src_install "$@" |
| 384 | popd > /dev/null |
401 | popd > /dev/null |
| 385 | |
402 | |
| 386 | # Backward compatibility, for non-array variables |
403 | # Backward compatibility, for non-array variables |
| 387 | if [[ -n "${DOCS}" ]] && [[ "$(declare -p DOCS 2>/dev/null 2>&1)" != "declare -a"* ]]; then |
404 | if [[ -n "${DOCS}" ]] && [[ "$(declare -p DOCS 2>/dev/null 2>&1)" != "declare -a"* ]]; then |
| 388 | dodoc ${DOCS} || die "dodoc failed" |
405 | dodoc ${DOCS} || die "dodoc failed" |
| … | |
… | |
| 397 | |
414 | |
| 398 | _check_build_dir |
415 | _check_build_dir |
| 399 | pushd "${CMAKE_BUILD_DIR}" > /dev/null |
416 | pushd "${CMAKE_BUILD_DIR}" > /dev/null |
| 400 | local ctestargs |
417 | local ctestargs |
| 401 | [[ -n ${TEST_VERBOSE} ]] && ctestargs="--extra-verbose --output-on-failure" |
418 | [[ -n ${TEST_VERBOSE} ]] && ctestargs="--extra-verbose --output-on-failure" |
| 402 | ctest ${ctestargs} || die "Tests failed." |
419 | ctest ${ctestargs} "$@" || die "Tests failed." |
| 403 | popd > /dev/null |
420 | popd > /dev/null |
| 404 | } |
421 | } |
| 405 | |
422 | |
| 406 | # @FUNCTION: cmake-utils_src_configure |
423 | # @FUNCTION: cmake-utils_src_configure |
| 407 | # @DESCRIPTION: |
424 | # @DESCRIPTION: |