/[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.52 Revision 1.59
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.52 2010/05/27 02:44:14 reavertm Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/cmake-utils.eclass,v 1.59 2010/09/16 16:04:11 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#
28# used for optionality) 28# used for optionality)
29WANT_CMAKE="${WANT_CMAKE:-always}" 29WANT_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 allowable version of cmake. Defaults to 2.6.2-r1 33# Specify the minimum required CMake version. Default is 2.6.2-r1
34CMAKE_MIN_VERSION="${CMAKE_MIN_VERSION:-2.6.2-r1}" 34CMAKE_MIN_VERSION="${CMAKE_MIN_VERSION:-2.6.2-r1}"
35 35
36CMAKEDEPEND="" 36CMAKEDEPEND=""
37case ${WANT_CMAKE} in 37case ${WANT_CMAKE} in
38 always) 38 always)
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 # out of tree build, but with $S=$WORKDIR, see bug #273949 for reason.
148 CMAKE_BUILD_DIR="${CMAKE_USE_DIR}/build"
149 else 147 else
150 # regular out of tree build 148 : ${CMAKE_BUILD_DIR:=${WORKDIR}/${P}_build}
151 [[ ${1} = init || -d ${CMAKE_USE_DIR}_build ]] && SUF="_build" || SUF=""
152 CMAKE_BUILD_DIR="${CMAKE_USE_DIR}${SUF}"
153 fi 149 fi
154 echo ">>> Working in BUILD_DIR: \"$CMAKE_BUILD_DIR\"" 150 echo ">>> Working in BUILD_DIR: \"$CMAKE_BUILD_DIR\""
155} 151}
156# @FUNCTION: cmake-utils_use_with 152# @FUNCTION: cmake-utils_use_with
157# @USAGE: <USE flag> [flag name] 153# @USAGE: <USE flag> [flag name]
213# Based on use_enable. See ebuild(5). 209# Based on use_enable. See ebuild(5).
214# 210#
215# `cmake-utils_use_has foo FOO` echoes -DHAVE_FOO=ON if foo is enabled 211# `cmake-utils_use_has foo FOO` echoes -DHAVE_FOO=ON if foo is enabled
216# and -DHAVE_FOO=OFF if it is disabled. 212# and -DHAVE_FOO=OFF if it is disabled.
217cmake-utils_use_has() { _use_me_now HAVE_ "$@" ; } 213cmake-utils_use_has() { _use_me_now HAVE_ "$@" ; }
214
215# @FUNCTION: cmake-utils_use_use
216# @USAGE: <USE flag> [flag name]
217# @DESCRIPTION:
218# Based on use_enable. See ebuild(5).
219#
220# `cmake-utils_use_use foo FOO` echoes -DUSE_FOO=ON if foo is enabled
221# and -DUSE_FOO=OFF if it is disabled.
222cmake-utils_use_use() { _use_me_now USE_ "$@" ; }
218 223
219# @FUNCTION: cmake-utils_use 224# @FUNCTION: cmake-utils_use
220# @USAGE: <USE flag> [flag name] 225# @USAGE: <USE flag> [flag name]
221# @DESCRIPTION: 226# @DESCRIPTION:
222# Based on use_enable. See ebuild(5). 227# Based on use_enable. See ebuild(5).
232 237
233 # Comment out all set (<some_should_be_user_defined_variable> value) 238 # 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 239 # TODO Add QA checker - inform when variable being checked for below is set in CMakeLists.txt
235 find "${CMAKE_USE_DIR}" -name CMakeLists.txt \ 240 find "${CMAKE_USE_DIR}" -name CMakeLists.txt \
236 -exec sed -i -e '/^[[:space:]]*[sS][eE][tT][[:space:]]*([[:space:]]*CMAKE_BUILD_TYPE.*)/{s/^/#IGNORE /g}' {} + \ 241 -exec sed -i -e '/^[[:space:]]*[sS][eE][tT][[:space:]]*([[:space:]]*CMAKE_BUILD_TYPE.*)/{s/^/#IGNORE /g}' {} + \
242 -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}' {} + \ 243 -exec sed -i -e '/^[[:space:]]*[sS][eE][tT][[:space:]]*([[:space:]]*CMAKE_INSTALL_PREFIX.*)/{s/^/#IGNORE /g}' {} + \
244 -exec sed -i -e '/^[[:space:]]*[sS][eE][tT][[:space:]]*([[:space:]]*CMAKE_VERBOSE_MAKEFILE.*)/{s/^/#IGNORE /g}' {} + \
238 || die "${LINENO}: failed to disable hardcoded settings" 245 || die "${LINENO}: failed to disable hardcoded settings"
239 246
240 # NOTE Append some useful summary here 247 # NOTE Append some useful summary here
241 cat >> CMakeLists.txt <<- _EOF_ 248 cat >> CMakeLists.txt <<- _EOF_
242 249
306 local libdir=$(get_libdir) 313 local libdir=$(get_libdir)
307 cat > "${common_config}" <<- _EOF_ 314 cat > "${common_config}" <<- _EOF_
308 SET (LIB_SUFFIX ${libdir/lib} CACHE STRING "library path suffix" FORCE) 315 SET (LIB_SUFFIX ${libdir/lib} CACHE STRING "library path suffix" FORCE)
309 SET (CMAKE_INSTALL_LIBDIR ${libdir} CACHE PATH "Output directory for libraries") 316 SET (CMAKE_INSTALL_LIBDIR ${libdir} CACHE PATH "Output directory for libraries")
310 _EOF_ 317 _EOF_
311 [[ -n ${NOCOLOR} ]] || echo 'SET (CMAKE_COLOR_MAKEFILE OFF CACHE BOOL "pretty colors during make" FORCE)' >> "${common_config}" 318 [[ "${NOCOLOR}" = true || "${NOCOLOR}" = yes ]] && echo 'SET (CMAKE_COLOR_MAKEFILE OFF CACHE BOOL "pretty colors during make" FORCE)' >> "${common_config}"
312 319
313 # Convert mycmakeargs to an array, for backwards compatibility 320 # Convert mycmakeargs to an array, for backwards compatibility
314 # Make the array a local variable since <=portage-2.1.6.x does not 321 # Make the array a local variable since <=portage-2.1.6.x does not
315 # support global arrays (see bug #297255). 322 # support global arrays (see bug #297255).
316 if [[ $(declare -p mycmakeargs 2>&-) != "declare -a mycmakeargs="* ]]; then 323 if [[ $(declare -p mycmakeargs 2>&-) != "declare -a mycmakeargs="* ]]; then
337 mkdir -p "${CMAKE_BUILD_DIR}" 344 mkdir -p "${CMAKE_BUILD_DIR}"
338 pushd "${CMAKE_BUILD_DIR}" > /dev/null 345 pushd "${CMAKE_BUILD_DIR}" > /dev/null
339 debug-print "${LINENO} ${ECLASS} ${FUNCNAME}: mycmakeargs is ${mycmakeargs_local[*]}" 346 debug-print "${LINENO} ${ECLASS} ${FUNCNAME}: mycmakeargs is ${mycmakeargs_local[*]}"
340 echo cmake "${cmakeargs[@]}" "${CMAKE_USE_DIR}" 347 echo cmake "${cmakeargs[@]}" "${CMAKE_USE_DIR}"
341 cmake "${cmakeargs[@]}" "${CMAKE_USE_DIR}" || die "cmake failed" 348 cmake "${cmakeargs[@]}" "${CMAKE_USE_DIR}" || die "cmake failed"
342
343 popd > /dev/null 349 popd > /dev/null
344} 350}
345 351
346enable_cmake-utils_src_compile() { 352enable_cmake-utils_src_compile() {
347 debug-print-function ${FUNCNAME} "$@" 353 debug-print-function ${FUNCNAME} "$@"
351} 357}
352 358
353# @FUNCTION: cmake-utils_src_make 359# @FUNCTION: cmake-utils_src_make
354# @DESCRIPTION: 360# @DESCRIPTION:
355# Function for building the package. Automatically detects the build type. 361# Function for building the package. Automatically detects the build type.
356# All arguments are passed to emake 362# All arguments are passed to emake.
357cmake-utils_src_make() { 363cmake-utils_src_make() {
358 debug-print-function ${FUNCNAME} "$@" 364 debug-print-function ${FUNCNAME} "$@"
359 365
360 _check_build_dir 366 _check_build_dir
361 pushd "${CMAKE_BUILD_DIR}" &> /dev/null 367 pushd "${CMAKE_BUILD_DIR}" > /dev/null
362 # first check if Makefile exist otherwise die 368 # first check if Makefile exist otherwise die
363 [[ -e Makefile ]] || die "Makefile not found. Error during configure stage." 369 [[ -e Makefile ]] || die "Makefile not found. Error during configure stage."
364 if [[ -n ${CMAKE_VERBOSE} ]]; then 370 if [[ -n ${CMAKE_VERBOSE} ]]; then
365 emake VERBOSE=1 "$@" || die "Make failed!" 371 emake VERBOSE=1 "$@" || die "Make failed!"
366 else 372 else
367 emake "$@" || die "Make failed!" 373 emake "$@" || die "Make failed!"
368 fi 374 fi
369 popd &> /dev/null 375 popd > /dev/null
370} 376}
371 377
372enable_cmake-utils_src_install() { 378enable_cmake-utils_src_install() {
373 debug-print-function ${FUNCNAME} "$@" 379 debug-print-function ${FUNCNAME} "$@"
374 380
375 _check_build_dir 381 _check_build_dir
376 pushd "${CMAKE_BUILD_DIR}" &> /dev/null 382 pushd "${CMAKE_BUILD_DIR}" > /dev/null
377 base_src_install 383 base_src_install
378 popd &> /dev/null 384 popd > /dev/null
379 385
380 # Backward compatibility, for non-array variables 386 # Backward compatibility, for non-array variables
381 if [[ -n "${DOCS}" ]] && [[ "$(declare -p DOCS 2>/dev/null 2>&1)" != "declare -a"* ]]; then 387 if [[ -n "${DOCS}" ]] && [[ "$(declare -p DOCS 2>/dev/null 2>&1)" != "declare -a"* ]]; then
382 dodoc ${DOCS} || die "dodoc failed" 388 dodoc ${DOCS} || die "dodoc failed"
383 fi 389 fi
388 394
389enable_cmake-utils_src_test() { 395enable_cmake-utils_src_test() {
390 debug-print-function ${FUNCNAME} "$@" 396 debug-print-function ${FUNCNAME} "$@"
391 397
392 _check_build_dir 398 _check_build_dir
393 pushd "${CMAKE_BUILD_DIR}" &> /dev/null 399 pushd "${CMAKE_BUILD_DIR}" > /dev/null
394 # Standard implementation of src_test 400 local ctestargs
395 if emake -j1 check -n &> /dev/null; then 401 [[ -n ${TEST_VERBOSE} ]] && ctestargs="--extra-verbose --output-on-failure"
396 einfo ">>> Test phase [check]: ${CATEGORY}/${PF}" 402 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 403 popd > /dev/null
409} 404}
410 405
411# @FUNCTION: cmake-utils_src_configure 406# @FUNCTION: cmake-utils_src_configure
412# @DESCRIPTION: 407# @DESCRIPTION:
413# General function for configuring with cmake. Default behaviour is to start an 408# General function for configuring with cmake. Default behaviour is to start an

Legend:
Removed from v.1.52  
changed lines
  Added in v.1.59

  ViewVC Help
Powered by ViewVC 1.1.20