/[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.22 Revision 1.27
1# Copyright 1999-2009 Gentoo Foundation 1# Copyright 1999-2009 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.22 2009/03/19 09:12:41 scarabeus Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/cmake-utils.eclass,v 1.27 2009/05/27 14:34:33 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# @AUTHORS: 8#
9# @CODE
9# Tomáš Chvátal <scarabeus@gentoo.org> 10# Tomáš Chvátal <scarabeus@gentoo.org>
10# Maciej Mrozowski <reavertm@poczta.fm> 11# Maciej Mrozowski <reavertm@poczta.fm>
11# (undisclosed contributors) 12# (undisclosed contributors)
12# Original author: Zephyrus (zephyrus@mirach.it) 13# Original author: Zephyrus (zephyrus@mirach.it)
14# @CODE
13# @BLURB: common ebuild functions for cmake-based packages 15# @BLURB: common ebuild functions for cmake-based packages
14# @DESCRIPTION: 16# @DESCRIPTION:
15# The cmake-utils eclass contains functions that make creating ebuilds for 17# The cmake-utils eclass contains functions that make creating ebuilds for
16# cmake-based packages much easier. 18# cmake-based packages much easier.
17# Its main features are support of out-of-source builds as well as in-source 19# Its main features are support of out-of-source builds as well as in-source
20 22
21inherit toolchain-funcs multilib flag-o-matic base 23inherit toolchain-funcs multilib flag-o-matic base
22 24
23EXPF="src_compile src_test src_install" 25EXPF="src_compile src_test src_install"
24case ${EAPI:-0} in 26case ${EAPI:-0} in
25 2) EXPF="${EXPF} src_configure" 27 2) EXPF="${EXPF} src_configure" ;;
26 ;;
27 1|0) ;; 28 1|0) ;;
28 *) die "Unknown EAPI, Bug eclass maintainers." ;; 29 *) die "Unknown EAPI, Bug eclass maintainers." ;;
29esac 30esac
30EXPORT_FUNCTIONS ${EXPF} 31EXPORT_FUNCTIONS ${EXPF}
31 32
32: ${DESCRIPTION:="Based on the ${ECLASS} eclass"} 33: ${DESCRIPTION:="Based on the ${ECLASS} eclass"}
33 34
34DEPEND=" 35if [[ ${PN} != cmake ]]; then
35 >=dev-util/cmake-2.6.2-r1 36 CMAKEDEPEND=">=dev-util/cmake-2.6.2-r1"
37fi
38
39DEPEND="${CMAKEDEPEND}
36 userland_GNU? ( >=sys-apps/findutils-4.4.0 ) 40 userland_GNU? ( >=sys-apps/findutils-4.4.0 )
37" 41"
38 42
39# Internal functions used by cmake-utils_use_* 43# Internal functions used by cmake-utils_use_*
40_use_me_now() { 44_use_me_now() {
41 debug-print-function ${FUNCNAME} "$@" 45 debug-print-function ${FUNCNAME} "$@"
46
47 local uper capitalised x
42 [[ -z $2 ]] && die "cmake-utils_use-$1 <USE flag> [<flag name>]" 48 [[ -z $2 ]] && die "cmake-utils_use-$1 <USE flag> [<flag name>]"
49 if [[ ! -z $3 ]]; then
50 # user specified the use name so use it
43 echo "-D$1${3:-$2}=$(use $2 && echo ON || echo OFF)" 51 echo "-D$1$3=$(use $2 && echo ON || echo OFF)"
52 else
53 # use all various most used combinations
54 uper=$(echo ${2} | tr '[:lower:]' '[:upper:]')
55 capitalised=$(echo ${2} | sed 's/\<\(.\)\([^ ]*\)/\u\1\L\2/g')
56 for x in $2 $uper $capitalised; do
57 echo "-D$1$x=$(use $2 && echo ON || echo OFF) "
58 done
59 fi
44} 60}
45_use_me_now_inverted() { 61_use_me_now_inverted() {
46 debug-print-function ${FUNCNAME} "$@" 62 debug-print-function ${FUNCNAME} "$@"
63
64 local uper capitalised x
47 [[ -z $2 ]] && die "cmake-utils_use-$1 <USE flag> [<flag name>]" 65 [[ -z $2 ]] && die "cmake-utils_use-$1 <USE flag> [<flag name>]"
66 if [[ ! -z $3 ]]; then
67 # user specified the use name so use it
48 echo "-D$1${3:-$2}=$(use $2 && echo OFF || echo ON)" 68 echo "-D$1$3=$(use $2 && echo OFF || echo ON)"
69 else
70 # use all various most used combinations
71 uper=$(echo ${2} | tr '[:lower:]' '[:upper:]')
72 capitalised=$(echo ${2} | sed 's/\<\(.\)\([^ ]*\)/\u\1\L\2/g')
73 for x in $2 $uper $capitalised; do
74 echo "-D$1$x=$(use $2 && echo OFF || echo ON) "
75 done
76 fi
49} 77}
50 78
51# @ECLASS-VARIABLE: DOCS 79# @ECLASS-VARIABLE: DOCS
52# @DESCRIPTION: 80# @DESCRIPTION:
53# Documents passed to dodoc command. 81# Documents passed to dodoc command.
55# @ECLASS-VARIABLE: HTML_DOCS 83# @ECLASS-VARIABLE: HTML_DOCS
56# @DESCRIPTION: 84# @DESCRIPTION:
57# Documents passed to dohtml command. 85# Documents passed to dohtml command.
58 86
59# @ECLASS-VARIABLE: PREFIX 87# @ECLASS-VARIABLE: PREFIX
60# @DESCRIPTION 88# @DESCRIPTION:
61# Eclass respects PREFIX variable, though it's not recommended way to set 89# Eclass respects PREFIX variable, though it's not recommended way to set
62# install/lib/bin prefixes. 90# install/lib/bin prefixes.
63# Use -DCMAKE_INSTALL_PREFIX=... CMake variable instead. 91# Use -DCMAKE_INSTALL_PREFIX=... CMake variable instead.
64 92
65# @ECLASS-VARIABLE: CMAKE_IN_SOURCE_BUILD 93# @ECLASS-VARIABLE: CMAKE_IN_SOURCE_BUILD
85 113
86# @FUNCTION: _check_build_dir 114# @FUNCTION: _check_build_dir
87# @DESCRIPTION: 115# @DESCRIPTION:
88# Determine using IN or OUT source build 116# Determine using IN or OUT source build
89_check_build_dir() { 117_check_build_dir() {
90 # in/out source build 118 # @ECLASS-VARIABLE: CMAKE_USE_DIR
119 # @DESCRIPTION:
120 # Sets the directory where we are working with cmake.
121 # For example when application uses autotools and only one
122 # plugin needs to be done by cmake.
123 # By default it uses ${S}.
124 : ${CMAKE_USE_DIR:=${S}}
125
126 # @ECLASS-VARIABLE: CMAKE_BUILD_DIR
127 # @DESCRIPTION:
128 # Specify the build directory where all cmake processed
129 # files should be located.
130 #
131 # For installing binary doins "${CMAKE_BUILD_DIR}/${PN}"
91 if [[ -n "${CMAKE_IN_SOURCE_BUILD}" ]]; then 132 if [[ -n "${CMAKE_IN_SOURCE_BUILD}" ]]; then
92 CMAKE_BUILD_DIR="${S}" 133 CMAKE_BUILD_DIR="${CMAKE_USE_DIR}"
93 else 134 else
94 CMAKE_BUILD_DIR="${WORKDIR}/${PN}_build" 135 CMAKE_BUILD_DIR="${CMAKE_USE_DIR}_build"
95 fi 136 fi
96 echo ">>> Working in BUILD_DIR: \"$CMAKE_BUILD_DIR\"" 137 echo ">>> Working in BUILD_DIR: \"$CMAKE_BUILD_DIR\""
97} 138}
98# @FUNCTION: cmake-utils_use_with 139# @FUNCTION: cmake-utils_use_with
99# @USAGE: <USE flag> [flag name] 140# @USAGE: <USE flag> [flag name]
177_modify-cmakelists() { 218_modify-cmakelists() {
178 debug-print-function ${FUNCNAME} "$@" 219 debug-print-function ${FUNCNAME} "$@"
179 220
180 # Comment out all set (<some_should_be_user_defined_variable> value) 221 # Comment out all set (<some_should_be_user_defined_variable> value)
181 # TODO Add QA checker - inform when variable being checked for below is set in CMakeLists.txt 222 # TODO Add QA checker - inform when variable being checked for below is set in CMakeLists.txt
182 find "${S}" -name CMakeLists.txt \ 223 find "${CMAKE_USE_DIR}" -name CMakeLists.txt \
183 -exec sed -i -e '/^[[:space:]]*[sS][eE][tT][[:space:]]*([[:space:]]*CMAKE_BUILD_TYPE.*)/{s/^/#IGNORE /g}' {} + \ 224 -exec sed -i -e '/^[[:space:]]*[sS][eE][tT][[:space:]]*([[:space:]]*CMAKE_BUILD_TYPE.*)/{s/^/#IGNORE /g}' {} + \
184 -exec sed -i -e '/^[[:space:]]*[sS][eE][tT][[:space:]]*([[:space:]]*CMAKE_INSTALL_PREFIX.*)/{s/^/#IGNORE /g}' {} + \ 225 -exec sed -i -e '/^[[:space:]]*[sS][eE][tT][[:space:]]*([[:space:]]*CMAKE_INSTALL_PREFIX.*)/{s/^/#IGNORE /g}' {} + \
185 || die "${LINENO}: failed to disable hardcoded settings" 226 || die "${LINENO}: failed to disable hardcoded settings"
186 227
187 # NOTE Append some useful summary here 228 # NOTE Append some useful summary here
195# @DESCRIPTION: 236# @DESCRIPTION:
196# General function for configuring with cmake. Default behaviour is to start an 237# General function for configuring with cmake. Default behaviour is to start an
197# out-of-source build. 238# out-of-source build.
198cmake-utils_src_configure() { 239cmake-utils_src_configure() {
199 debug-print-function ${FUNCNAME} "$@" 240 debug-print-function ${FUNCNAME} "$@"
241
242 _check_build_dir
243
244 # check if CMakeLists.txt exist and if no then die
245 if [[ ! -e "${CMAKE_USE_DIR}"/CMakeLists.txt ]] ; then
246 eerror "I was unable to locate CMakeLists.txt under:"
247 eerror "\"${CMAKE_USE_DIR}/CMakeLists.txt\""
248 eerror "You should consider not inheriting the cmake eclass."
249 die "FATAL: Unable to find CMakeLists.txt"
250 fi
200 251
201 # Remove dangerous things. 252 # Remove dangerous things.
202 _modify-cmakelists 253 _modify-cmakelists
203 254
204 # @SEE CMAKE_BUILD_TYPE 255 # @SEE CMAKE_BUILD_TYPE
235SET (LIB_SUFFIX ${libdir/lib} CACHE STRING "library path suffix" FORCE) 286SET (LIB_SUFFIX ${libdir/lib} CACHE STRING "library path suffix" FORCE)
236_EOF_ 287_EOF_
237 [[ -n ${CMAKE_NO_COLOR} ]] && echo 'SET (CMAKE_COLOR_MAKEFILE OFF CACHE BOOL "pretty colors during make" FORCE)' >> ${common_config} 288 [[ -n ${CMAKE_NO_COLOR} ]] && echo 'SET (CMAKE_COLOR_MAKEFILE OFF CACHE BOOL "pretty colors during make" FORCE)' >> ${common_config}
238 cmakeargs="-C ${common_config} ${cmakeargs}" 289 cmakeargs="-C ${common_config} ${cmakeargs}"
239 290
240 _check_build_dir
241 mkdir -p "${CMAKE_BUILD_DIR}" 291 mkdir -p "${CMAKE_BUILD_DIR}"
242 pushd "${CMAKE_BUILD_DIR}" > /dev/null 292 pushd "${CMAKE_BUILD_DIR}" > /dev/null
243 debug-print "${LINENO} ${ECLASS} ${FUNCNAME}: mycmakeargs is $cmakeargs" 293 debug-print "${LINENO} ${ECLASS} ${FUNCNAME}: mycmakeargs is $cmakeargs"
244 cmake ${cmakeargs} "${S}" || die "cmake failed" 294 cmake ${cmakeargs} "${CMAKE_USE_DIR}" || die "cmake failed"
245 295
246 popd > /dev/null 296 popd > /dev/null
247} 297}
248 298
249# @FUNCTION: cmake-utils_src_compile 299# @FUNCTION: cmake-utils_src_compile
280cmake-utils_src_make() { 330cmake-utils_src_make() {
281 debug-print-function ${FUNCNAME} "$@" 331 debug-print-function ${FUNCNAME} "$@"
282 332
283 _check_build_dir 333 _check_build_dir
284 pushd "${CMAKE_BUILD_DIR}" > /dev/null 334 pushd "${CMAKE_BUILD_DIR}" > /dev/null
335 # first check if Makefile exist otherwise die
336 [[ -e Makefile ]] || die "Makefile not found. Error during configure stage."
285 if [[ -n ${CMAKE_VERBOSE} ]]; then 337 if [[ -n ${CMAKE_VERBOSE} ]]; then
286 emake VERBOSE=1 "$@" || die "Make failed!" 338 emake VERBOSE=1 "$@" || die "Make failed!"
287 else 339 else
288 emake "$@" || die "Make failed!" 340 emake "$@" || die "Make failed!"
289 fi 341 fi

Legend:
Removed from v.1.22  
changed lines
  Added in v.1.27

  ViewVC Help
Powered by ViewVC 1.1.20