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.51 2010/04/30 23:58:47 abcd Exp $ |
3 | # $Header: /var/cvsroot/gentoo-x86/eclass/cmake-utils.eclass,v 1.52 2010/05/27 02:44:14 reavertm 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 | # |
9 | # @CODE |
9 | # @CODE |
10 | # Tomáš Chvátal <scarabeus@gentoo.org> |
10 | # Tomáš Chvátal <scarabeus@gentoo.org> |
11 | # Maciej Mrozowski <reavertm@gmail.com> |
11 | # Maciej Mrozowski <reavertm@gentoo.org> |
12 | # (undisclosed contributors) |
12 | # (undisclosed contributors) |
13 | # Original author: Zephyrus (zephyrus@mirach.it) |
13 | # Original author: Zephyrus (zephyrus@mirach.it) |
14 | # @CODE |
14 | # @CODE |
15 | # @BLURB: common ebuild functions for cmake-based packages |
15 | # @BLURB: common ebuild functions for cmake-based packages |
16 | # @DESCRIPTION: |
16 | # @DESCRIPTION: |
17 | # The cmake-utils eclass contains functions that make creating ebuilds for |
17 | # The cmake-utils eclass is base.eclass(5) wrapper that makes creating ebuilds for |
18 | # cmake-based packages much easier. |
18 | # cmake-based packages much easier. |
19 | # Its main features are support of out-of-source builds as well as in-source |
19 | # It provides all inherited features (DOCS, HTML_DOCS, PATCHES) along with out-of-source |
20 | # builds and an implementation of the well-known use_enable and use_with |
20 | # builds (default), in-source builds and an implementation of the well-known use_enable |
21 | # functions for CMake. |
21 | # and use_with functions for CMake. |
22 | |
22 | |
23 | # @ECLASS-VARIABLE: WANT_CMAKE |
23 | # @ECLASS-VARIABLE: WANT_CMAKE |
24 | # @DESCRIPTION: |
24 | # @DESCRIPTION: |
25 | # Specify if cmake-utils eclass should depend on cmake optionaly or not. |
25 | # Specify if cmake-utils eclass should depend on cmake optionaly or not. |
26 | # This is usefull when only part of aplication is using cmake build system. |
26 | # This is usefull when only part of aplication is using cmake build system. |
… | |
… | |
99 | echo "-D$1$x=$(use $2 && echo OFF || echo ON) " |
99 | echo "-D$1$x=$(use $2 && echo OFF || echo ON) " |
100 | done |
100 | done |
101 | fi |
101 | fi |
102 | } |
102 | } |
103 | |
103 | |
104 | # @ECLASS-VARIABLE: DOCS |
|
|
105 | # @DESCRIPTION: |
|
|
106 | # Documents passed to dodoc command. |
|
|
107 | |
|
|
108 | # @ECLASS-VARIABLE: HTML_DOCS |
|
|
109 | # @DESCRIPTION: |
|
|
110 | # Documents passed to dohtml command. |
|
|
111 | |
|
|
112 | # @ECLASS-VARIABLE: PREFIX |
104 | # @ECLASS-VARIABLE: PREFIX |
113 | # @DESCRIPTION: |
105 | # @DESCRIPTION: |
114 | # Eclass respects PREFIX variable, though it's not recommended way to set |
106 | # Eclass respects PREFIX variable, though it's not recommended way to set |
115 | # install/lib/bin prefixes. |
107 | # install/lib/bin prefixes. |
116 | # Use -DCMAKE_INSTALL_PREFIX=... CMake variable instead. |
108 | # Use -DCMAKE_INSTALL_PREFIX=... CMake variable instead. |
… | |
… | |
130 | # If about to be set - needs to be set before invoking cmake-utils_src_configure. |
122 | # If about to be set - needs to be set before invoking cmake-utils_src_configure. |
131 | # You usualy do *NOT* want nor need to set it as it pulls CMake default build-type |
123 | # You usualy do *NOT* want nor need to set it as it pulls CMake default build-type |
132 | # specific compiler flags overriding make.conf. |
124 | # specific compiler flags overriding make.conf. |
133 | : ${CMAKE_BUILD_TYPE:=Gentoo} |
125 | : ${CMAKE_BUILD_TYPE:=Gentoo} |
134 | |
126 | |
135 | # @FUNCTION: _check_build_dir |
|
|
136 | # @DESCRIPTION: |
|
|
137 | # Determine using IN or OUT source build |
127 | # Determine using IN or OUT source build |
138 | _check_build_dir() { |
128 | _check_build_dir() { |
139 | # @ECLASS-VARIABLE: CMAKE_USE_DIR |
129 | # @ECLASS-VARIABLE: CMAKE_USE_DIR |
140 | # @DESCRIPTION: |
130 | # @DESCRIPTION: |
141 | # Sets the directory where we are working with cmake. |
131 | # Sets the directory where we are working with cmake. |
… | |
… | |
261 | Module \${CMAKE_MODULE_LINKER_FLAGS} |
251 | Module \${CMAKE_MODULE_LINKER_FLAGS} |
262 | Shared \${CMAKE_SHARED_LINKER_FLAGS}\n") |
252 | Shared \${CMAKE_SHARED_LINKER_FLAGS}\n") |
263 | _EOF_ |
253 | _EOF_ |
264 | } |
254 | } |
265 | |
255 | |
266 | # @FUNCTION: enable_cmake-utils_src_configure |
|
|
267 | # @DESCRIPTION: |
|
|
268 | # General function for configuring with cmake. Default behaviour is to start an |
|
|
269 | # out-of-source build. |
|
|
270 | enable_cmake-utils_src_configure() { |
256 | enable_cmake-utils_src_configure() { |
271 | debug-print-function ${FUNCNAME} "$@" |
257 | debug-print-function ${FUNCNAME} "$@" |
272 | |
258 | |
273 | _check_build_dir init |
259 | _check_build_dir init |
274 | |
260 | |
… | |
… | |
355 | cmake "${cmakeargs[@]}" "${CMAKE_USE_DIR}" || die "cmake failed" |
341 | cmake "${cmakeargs[@]}" "${CMAKE_USE_DIR}" || die "cmake failed" |
356 | |
342 | |
357 | popd > /dev/null |
343 | popd > /dev/null |
358 | } |
344 | } |
359 | |
345 | |
360 | # @FUNCTION: enable_cmake-utils_src_compile |
|
|
361 | # @DESCRIPTION: |
|
|
362 | # General function for compiling with cmake. Default behaviour is to check for |
|
|
363 | # EAPI and respectively to configure as well or just compile. |
|
|
364 | enable_cmake-utils_src_compile() { |
346 | enable_cmake-utils_src_compile() { |
365 | debug-print-function ${FUNCNAME} "$@" |
347 | debug-print-function ${FUNCNAME} "$@" |
366 | |
348 | |
367 | has src_configure ${CMAKE_EXPF} || cmake-utils_src_configure |
349 | has src_configure ${CMAKE_EXPF} || cmake-utils_src_configure |
368 | cmake-utils_src_make "$@" |
350 | cmake-utils_src_make "$@" |
… | |
… | |
385 | emake "$@" || die "Make failed!" |
367 | emake "$@" || die "Make failed!" |
386 | fi |
368 | fi |
387 | popd &> /dev/null |
369 | popd &> /dev/null |
388 | } |
370 | } |
389 | |
371 | |
390 | # @FUNCTION: enable_cmake-utils_src_install |
|
|
391 | # @DESCRIPTION: |
|
|
392 | # Function for installing the package. Automatically detects the build type. |
|
|
393 | enable_cmake-utils_src_install() { |
372 | enable_cmake-utils_src_install() { |
394 | debug-print-function ${FUNCNAME} "$@" |
373 | debug-print-function ${FUNCNAME} "$@" |
395 | |
374 | |
396 | _check_build_dir |
375 | _check_build_dir |
397 | pushd "${CMAKE_BUILD_DIR}" &> /dev/null |
376 | pushd "${CMAKE_BUILD_DIR}" &> /dev/null |
398 | emake install DESTDIR="${D}" || die "Make install failed" |
377 | base_src_install |
399 | popd &> /dev/null |
378 | popd &> /dev/null |
400 | |
379 | |
401 | # Manual document installation |
380 | # Backward compatibility, for non-array variables |
402 | [[ -n "${DOCS}" ]] && { dodoc ${DOCS} || die "dodoc failed" ; } |
381 | if [[ -n "${DOCS}" ]] && [[ "$(declare -p DOCS 2>/dev/null 2>&1)" != "declare -a"* ]]; then |
403 | [[ -n "${HTML_DOCS}" ]] && { dohtml -r ${HTML_DOCS} || die "dohtml failed" ; } |
382 | dodoc ${DOCS} || die "dodoc failed" |
|
|
383 | fi |
|
|
384 | if [[ -n "${HTML_DOCS}" ]] && [[ "$(declare -p HTML_DOCS 2>/dev/null 2>&1)" != "declare -a"* ]]; then |
|
|
385 | dohtml -r ${HTML_DOCS} || die "dohtml failed" |
|
|
386 | fi |
404 | } |
387 | } |
405 | |
388 | |
406 | # @FUNCTION: enable_cmake-utils_src_test |
|
|
407 | # @DESCRIPTION: |
|
|
408 | # Function for testing the package. Automatically detects the build type. |
|
|
409 | enable_cmake-utils_src_test() { |
389 | enable_cmake-utils_src_test() { |
410 | debug-print-function ${FUNCNAME} "$@" |
390 | debug-print-function ${FUNCNAME} "$@" |
411 | |
391 | |
412 | _check_build_dir |
392 | _check_build_dir |
413 | pushd "${CMAKE_BUILD_DIR}" &> /dev/null |
393 | pushd "${CMAKE_BUILD_DIR}" &> /dev/null |
… | |
… | |
426 | einfo ">>> Test phase [none]: ${CATEGORY}/${PF}" |
406 | einfo ">>> Test phase [none]: ${CATEGORY}/${PF}" |
427 | fi |
407 | fi |
428 | popd &> /dev/null |
408 | popd &> /dev/null |
429 | } |
409 | } |
430 | |
410 | |
431 | ## Wrappers for calls bellow this line |
|
|
432 | # @FUNCTION: cmake-utils_src_configure |
411 | # @FUNCTION: cmake-utils_src_configure |
433 | # @DESCRIPTION: |
412 | # @DESCRIPTION: |
434 | # Wrapper for detection if we want to run enable_ prefixed function with same name |
413 | # General function for configuring with cmake. Default behaviour is to start an |
435 | # unconditionaly or only when some useflag is enabled. |
414 | # out-of-source build. |
436 | cmake-utils_src_configure() { |
415 | cmake-utils_src_configure() { |
437 | _execute_optionaly "src_configure" "$@" |
416 | _execute_optionaly "src_configure" "$@" |
438 | } |
417 | } |
439 | |
418 | |
440 | # @FUNCTION: cmake-utils_src_compile |
419 | # @FUNCTION: cmake-utils_src_compile |
441 | # @DESCRIPTION: |
420 | # @DESCRIPTION: |
442 | # Wrapper for detection if we want to run enable_ prefixed function with same name |
421 | # General function for compiling with cmake. Default behaviour is to check for |
443 | # unconditionaly or only when some useflag is enabled. |
422 | # EAPI and respectively to configure as well or just compile. |
|
|
423 | # Automatically detects the build type. All arguments are passed to emake. |
444 | cmake-utils_src_compile() { |
424 | cmake-utils_src_compile() { |
445 | _execute_optionaly "src_compile" "$@" |
425 | _execute_optionaly "src_compile" "$@" |
446 | } |
426 | } |
447 | |
427 | |
448 | # @FUNCTION: cmake-utils_src_install |
428 | # @FUNCTION: cmake-utils_src_install |
449 | # @DESCRIPTION: |
429 | # @DESCRIPTION: |
450 | # Wrapper for detection if we want to run enable_ prefixed function with same name |
430 | # Function for installing the package. Automatically detects the build type. |
451 | # unconditionaly or only when some useflag is enabled. |
|
|
452 | cmake-utils_src_install() { |
431 | cmake-utils_src_install() { |
453 | _execute_optionaly "src_install" "$@" |
432 | _execute_optionaly "src_install" "$@" |
454 | } |
433 | } |
455 | |
434 | |
456 | # @FUNCTION: cmake-utils_src_test |
435 | # @FUNCTION: cmake-utils_src_test |
457 | # @DESCRIPTION: |
436 | # @DESCRIPTION: |
458 | # Wrapper for detection if we want to run enable_ prefixed function with same name |
437 | # Function for testing the package. Automatically detects the build type. |
459 | # unconditionaly or only when some useflag is enabled. |
|
|
460 | cmake-utils_src_test() { |
438 | cmake-utils_src_test() { |
461 | _execute_optionaly "src_test" "$@" |
439 | _execute_optionaly "src_test" "$@" |
462 | } |
440 | } |
463 | |
441 | |
464 | |
442 | # Optionally executes phases based on WANT_CMAKE variable/USE flag. |
465 | _execute_optionaly() { |
443 | _execute_optionaly() { |
466 | local phase="$1" ; shift |
444 | local phase="$1" ; shift |
467 | if [[ ${WANT_CMAKE} = always ]]; then |
445 | if [[ ${WANT_CMAKE} = always ]]; then |
468 | enable_cmake-utils_${phase} "$@" |
446 | enable_cmake-utils_${phase} "$@" |
469 | else |
447 | else |