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.54 2010/06/26 17:55:59 reavertm Exp $ |
3 | # $Header: /var/cvsroot/gentoo-x86/eclass/cmake-utils.eclass,v 1.55 2010/07/09 16:31:27 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 | # |
… | |
… | |
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: PREFIX |
|
|
105 | # @DESCRIPTION: |
|
|
106 | # Eclass respects PREFIX variable, though it's not recommended way to set |
|
|
107 | # install/lib/bin prefixes. |
|
|
108 | # Use -DCMAKE_INSTALL_PREFIX=... CMake variable instead. |
|
|
109 | |
|
|
110 | # @ECLASS-VARIABLE: CMAKE_IN_SOURCE_BUILD |
104 | # @ECLASS-VARIABLE: CMAKE_BUILD_DIR |
111 | # @DESCRIPTION: |
105 | # @DESCRIPTION: |
112 | # Set to enable in-source build. |
106 | # Build directory where all cmake processed files should be generated. |
113 | |
107 | # For in-source build it's fixed to ${CMAKE_USE_DIR}. |
114 | # @ECLASS-VARIABLE: CMAKE_VERBOSE |
108 | # For out-of-source build it can be overriden, by default it uses |
115 | # @DESCRIPTION: |
109 | # ${WORKDIR}/${P}_build. |
116 | # Set to enable verbose messages during compilation. |
|
|
117 | |
110 | |
118 | # @ECLASS-VARIABLE: CMAKE_BUILD_TYPE |
111 | # @ECLASS-VARIABLE: CMAKE_BUILD_TYPE |
119 | # @DESCRIPTION: |
112 | # @DESCRIPTION: |
120 | # Set to override default CMAKE_BUILD_TYPE. Only useful for packages |
113 | # Set to override default CMAKE_BUILD_TYPE. Only useful for packages |
121 | # known to make use of "if (CMAKE_BUILD_TYPE MATCHES xxx)". |
114 | # known to make use of "if (CMAKE_BUILD_TYPE MATCHES xxx)". |
122 | # If about to be set - needs to be set before invoking cmake-utils_src_configure. |
115 | # If about to be set - needs to be set before invoking cmake-utils_src_configure. |
123 | # You usualy do *NOT* want nor need to set it as it pulls CMake default build-type |
116 | # You usualy do *NOT* want nor need to set it as it pulls CMake default build-type |
124 | # specific compiler flags overriding make.conf. |
117 | # specific compiler flags overriding make.conf. |
125 | : ${CMAKE_BUILD_TYPE:=Gentoo} |
118 | : ${CMAKE_BUILD_TYPE:=Gentoo} |
126 | |
119 | |
|
|
120 | # @ECLASS-VARIABLE: CMAKE_IN_SOURCE_BUILD |
|
|
121 | # @DESCRIPTION: |
|
|
122 | # Set to enable in-source build. |
|
|
123 | |
|
|
124 | # @ECLASS-VARIABLE: CMAKE_USE_DIR |
|
|
125 | # @DESCRIPTION: |
|
|
126 | # Sets the directory where we are working with cmake. |
|
|
127 | # For example when application uses autotools and only one |
|
|
128 | # plugin needs to be done by cmake. |
|
|
129 | # By default it uses ${S}. |
|
|
130 | |
|
|
131 | # @ECLASS-VARIABLE: CMAKE_VERBOSE |
|
|
132 | # @DESCRIPTION: |
|
|
133 | # Set to enable verbose messages during compilation. |
|
|
134 | |
|
|
135 | # @ECLASS-VARIABLE: PREFIX |
|
|
136 | # @DESCRIPTION: |
|
|
137 | # Eclass respects PREFIX variable, though it's not recommended way to set |
|
|
138 | # install/lib/bin prefixes. |
|
|
139 | # Use -DCMAKE_INSTALL_PREFIX=... CMake variable instead. |
|
|
140 | |
127 | # Determine using IN or OUT source build |
141 | # Determine using IN or OUT source build |
128 | _check_build_dir() { |
142 | _check_build_dir() { |
129 | # @ECLASS-VARIABLE: CMAKE_USE_DIR |
|
|
130 | # @DESCRIPTION: |
|
|
131 | # Sets the directory where we are working with cmake. |
|
|
132 | # For example when application uses autotools and only one |
|
|
133 | # plugin needs to be done by cmake. |
|
|
134 | # By default it uses ${S}. |
|
|
135 | : ${CMAKE_USE_DIR:=${S}} |
143 | : ${CMAKE_USE_DIR:=${S}} |
136 | |
|
|
137 | # @ECLASS-VARIABLE: CMAKE_BUILD_DIR |
|
|
138 | # @DESCRIPTION: |
|
|
139 | # Specify the build directory where all cmake processed |
|
|
140 | # files should be located. |
|
|
141 | # |
|
|
142 | # For installing binary doins "${CMAKE_BUILD_DIR}/${PN}" |
|
|
143 | if [[ -n ${CMAKE_IN_SOURCE_BUILD} ]]; then |
144 | if [[ -n ${CMAKE_IN_SOURCE_BUILD} ]]; then |
144 | # we build in source dir |
145 | # we build in source dir |
145 | CMAKE_BUILD_DIR="${CMAKE_USE_DIR}" |
146 | CMAKE_BUILD_DIR="${CMAKE_USE_DIR}" |
146 | elif [[ ${CMAKE_USE_DIR} = ${WORKDIR} ]]; then |
147 | elif [[ ${CMAKE_USE_DIR} = ${WORKDIR} ]]; then |
147 | # out of tree build, but with $S=$WORKDIR, see bug #273949 for reason. |
148 | # out of tree build, but with $S=$WORKDIR, see bug #273949 for reason. |
… | |
… | |
232 | |
233 | |
233 | # Comment out all set (<some_should_be_user_defined_variable> value) |
234 | # Comment out all set (<some_should_be_user_defined_variable> value) |
234 | # TODO Add QA checker - inform when variable being checked for below is set in CMakeLists.txt |
235 | # TODO Add QA checker - inform when variable being checked for below is set in CMakeLists.txt |
235 | find "${CMAKE_USE_DIR}" -name CMakeLists.txt \ |
236 | find "${CMAKE_USE_DIR}" -name CMakeLists.txt \ |
236 | -exec sed -i -e '/^[[:space:]]*[sS][eE][tT][[:space:]]*([[:space:]]*CMAKE_BUILD_TYPE.*)/{s/^/#IGNORE /g}' {} + \ |
237 | -exec sed -i -e '/^[[:space:]]*[sS][eE][tT][[:space:]]*([[:space:]]*CMAKE_BUILD_TYPE.*)/{s/^/#IGNORE /g}' {} + \ |
|
|
238 | -exec sed -i -e '/^[[:space:]]*[sS][eE][tT][[:space:]]*([[:space:]]*CMAKE_COLOR_MAKEFILE.*)/{s/^/#IGNORE /g}' {} + \ |
237 | -exec sed -i -e '/^[[:space:]]*[sS][eE][tT][[:space:]]*([[:space:]]*CMAKE_INSTALL_PREFIX.*)/{s/^/#IGNORE /g}' {} + \ |
239 | -exec sed -i -e '/^[[:space:]]*[sS][eE][tT][[:space:]]*([[:space:]]*CMAKE_INSTALL_PREFIX.*)/{s/^/#IGNORE /g}' {} + \ |
|
|
240 | -exec sed -i -e '/^[[:space:]]*[sS][eE][tT][[:space:]]*([[:space:]]*CMAKE_VERBOSE_MAKEFILE.*)/{s/^/#IGNORE /g}' {} + \ |
238 | || die "${LINENO}: failed to disable hardcoded settings" |
241 | || die "${LINENO}: failed to disable hardcoded settings" |
239 | |
242 | |
240 | # NOTE Append some useful summary here |
243 | # NOTE Append some useful summary here |
241 | cat >> CMakeLists.txt <<- _EOF_ |
244 | cat >> CMakeLists.txt <<- _EOF_ |
242 | |
245 | |
… | |
… | |
337 | mkdir -p "${CMAKE_BUILD_DIR}" |
340 | mkdir -p "${CMAKE_BUILD_DIR}" |
338 | pushd "${CMAKE_BUILD_DIR}" > /dev/null |
341 | pushd "${CMAKE_BUILD_DIR}" > /dev/null |
339 | debug-print "${LINENO} ${ECLASS} ${FUNCNAME}: mycmakeargs is ${mycmakeargs_local[*]}" |
342 | debug-print "${LINENO} ${ECLASS} ${FUNCNAME}: mycmakeargs is ${mycmakeargs_local[*]}" |
340 | echo cmake "${cmakeargs[@]}" "${CMAKE_USE_DIR}" |
343 | echo cmake "${cmakeargs[@]}" "${CMAKE_USE_DIR}" |
341 | cmake "${cmakeargs[@]}" "${CMAKE_USE_DIR}" || die "cmake failed" |
344 | cmake "${cmakeargs[@]}" "${CMAKE_USE_DIR}" || die "cmake failed" |
342 | |
|
|
343 | popd > /dev/null |
345 | popd > /dev/null |
344 | } |
346 | } |
345 | |
347 | |
346 | enable_cmake-utils_src_compile() { |
348 | enable_cmake-utils_src_compile() { |
347 | debug-print-function ${FUNCNAME} "$@" |
349 | debug-print-function ${FUNCNAME} "$@" |
… | |
… | |
351 | } |
353 | } |
352 | |
354 | |
353 | # @FUNCTION: cmake-utils_src_make |
355 | # @FUNCTION: cmake-utils_src_make |
354 | # @DESCRIPTION: |
356 | # @DESCRIPTION: |
355 | # Function for building the package. Automatically detects the build type. |
357 | # Function for building the package. Automatically detects the build type. |
356 | # All arguments are passed to emake |
358 | # All arguments are passed to emake. |
357 | cmake-utils_src_make() { |
359 | cmake-utils_src_make() { |
358 | debug-print-function ${FUNCNAME} "$@" |
360 | debug-print-function ${FUNCNAME} "$@" |
359 | |
361 | |
360 | _check_build_dir |
362 | _check_build_dir |
361 | pushd "${CMAKE_BUILD_DIR}" &> /dev/null |
363 | pushd "${CMAKE_BUILD_DIR}" > /dev/null |
362 | # first check if Makefile exist otherwise die |
364 | # first check if Makefile exist otherwise die |
363 | [[ -e Makefile ]] || die "Makefile not found. Error during configure stage." |
365 | [[ -e Makefile ]] || die "Makefile not found. Error during configure stage." |
364 | if [[ -n ${CMAKE_VERBOSE} ]]; then |
366 | if [[ -n ${CMAKE_VERBOSE} ]]; then |
365 | emake VERBOSE=1 "$@" || die "Make failed!" |
367 | emake VERBOSE=1 "$@" || die "Make failed!" |
366 | else |
368 | else |
367 | emake "$@" || die "Make failed!" |
369 | emake "$@" || die "Make failed!" |
368 | fi |
370 | fi |
369 | popd &> /dev/null |
371 | popd > /dev/null |
370 | } |
372 | } |
371 | |
373 | |
372 | enable_cmake-utils_src_install() { |
374 | enable_cmake-utils_src_install() { |
373 | debug-print-function ${FUNCNAME} "$@" |
375 | debug-print-function ${FUNCNAME} "$@" |
374 | |
376 | |
375 | _check_build_dir |
377 | _check_build_dir |
376 | pushd "${CMAKE_BUILD_DIR}" &> /dev/null |
378 | pushd "${CMAKE_BUILD_DIR}" > /dev/null |
377 | base_src_install |
379 | base_src_install |
378 | popd &> /dev/null |
380 | popd > /dev/null |
379 | |
381 | |
380 | # Backward compatibility, for non-array variables |
382 | # Backward compatibility, for non-array variables |
381 | if [[ -n "${DOCS}" ]] && [[ "$(declare -p DOCS 2>/dev/null 2>&1)" != "declare -a"* ]]; then |
383 | if [[ -n "${DOCS}" ]] && [[ "$(declare -p DOCS 2>/dev/null 2>&1)" != "declare -a"* ]]; then |
382 | dodoc ${DOCS} || die "dodoc failed" |
384 | dodoc ${DOCS} || die "dodoc failed" |
383 | fi |
385 | fi |
… | |
… | |
388 | |
390 | |
389 | enable_cmake-utils_src_test() { |
391 | enable_cmake-utils_src_test() { |
390 | debug-print-function ${FUNCNAME} "$@" |
392 | debug-print-function ${FUNCNAME} "$@" |
391 | |
393 | |
392 | _check_build_dir |
394 | _check_build_dir |
393 | pushd "${CMAKE_BUILD_DIR}" &> /dev/null |
395 | pushd "${CMAKE_BUILD_DIR}" > /dev/null |
394 | # Standard implementation of src_test |
396 | local ctestargs |
395 | if emake -j1 check -n &> /dev/null; then |
397 | [[ -n ${TEST_VERBOSE} ]] && ctestargs="--extra-verbose --output-on-failure" |
396 | einfo ">>> Test phase [check]: ${CATEGORY}/${PF}" |
398 | ctest ${ctestargs} || die "Tests failed." |
397 | if ! emake -j1 check; then |
|
|
398 | die "Make check failed. See above for details." |
|
|
399 | fi |
|
|
400 | elif emake -j1 test -n &> /dev/null; then |
|
|
401 | einfo ">>> Test phase [test]: ${CATEGORY}/${PF}" |
|
|
402 | if ! emake -j1 test; then |
|
|
403 | die "Make test failed. See above for details." |
|
|
404 | fi |
|
|
405 | else |
|
|
406 | einfo ">>> Test phase [none]: ${CATEGORY}/${PF}" |
|
|
407 | fi |
|
|
408 | popd &> /dev/null |
399 | popd > /dev/null |
409 | } |
400 | } |
410 | |
401 | |
411 | # @FUNCTION: cmake-utils_src_configure |
402 | # @FUNCTION: cmake-utils_src_configure |
412 | # @DESCRIPTION: |
403 | # @DESCRIPTION: |
413 | # General function for configuring with cmake. Default behaviour is to start an |
404 | # General function for configuring with cmake. Default behaviour is to start an |