/[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.18 Revision 1.29
1# Copyright 1999-2007 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.18 2009/03/11 16:22:51 scarabeus Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/cmake-utils.eclass,v 1.29 2009/06/17 22:39:01 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
35if [[ ${PN} != cmake ]]; then
34DEPEND=">=dev-util/cmake-2.4.6-r1" 36 CMAKEDEPEND=">=dev-util/cmake-2.6.2-r1"
37fi
38
39DEPEND="${CMAKEDEPEND}
40 userland_GNU? ( >=sys-apps/findutils-4.4.0 )
41"
35 42
36# Internal functions used by cmake-utils_use_* 43# Internal functions used by cmake-utils_use_*
37_use_me_now() { 44_use_me_now() {
38 debug-print-function ${FUNCNAME} "$@" 45 debug-print-function ${FUNCNAME} "$@"
46
47 local uper capitalised x
39 [[ -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
40 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
41} 60}
42_use_me_now_inverted() { 61_use_me_now_inverted() {
43 debug-print-function ${FUNCNAME} "$@" 62 debug-print-function ${FUNCNAME} "$@"
63
64 local uper capitalised x
44 [[ -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
45 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
46} 77}
47 78
48# @ECLASS-VARIABLE: DOCS 79# @ECLASS-VARIABLE: DOCS
49# @DESCRIPTION: 80# @DESCRIPTION:
50# Documents passed to dodoc command. 81# Documents passed to dodoc command.
52# @ECLASS-VARIABLE: HTML_DOCS 83# @ECLASS-VARIABLE: HTML_DOCS
53# @DESCRIPTION: 84# @DESCRIPTION:
54# Documents passed to dohtml command. 85# Documents passed to dohtml command.
55 86
56# @ECLASS-VARIABLE: PREFIX 87# @ECLASS-VARIABLE: PREFIX
57# @DESCRIPTION 88# @DESCRIPTION:
58# 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
59# install/lib/bin prefixes. 90# install/lib/bin prefixes.
60# Use -DCMAKE_INSTALL_PREFIX=... CMake variable instead. 91# Use -DCMAKE_INSTALL_PREFIX=... CMake variable instead.
61 92
62# @ECLASS-VARIABLE: CMAKE_IN_SOURCE_BUILD 93# @ECLASS-VARIABLE: CMAKE_IN_SOURCE_BUILD
82 113
83# @FUNCTION: _check_build_dir 114# @FUNCTION: _check_build_dir
84# @DESCRIPTION: 115# @DESCRIPTION:
85# Determine using IN or OUT source build 116# Determine using IN or OUT source build
86_check_build_dir() { 117_check_build_dir() {
87 # 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}"
88 if [[ -n "${CMAKE_IN_SOURCE_BUILD}" ]]; then 132 if [[ -n "${CMAKE_IN_SOURCE_BUILD}" ]]; then
133 # we build in source dir
89 CMAKE_BUILD_DIR="${S}" 134 CMAKE_BUILD_DIR="${CMAKE_USE_DIR}"
90 else 135 elif [[ ${CMAKE_USE_DIR} = ${WORKDIR} ]]; then
136 # out of tree build, but with $S=$WORKDIR, see bug #273949 for reason.
91 CMAKE_BUILD_DIR="${WORKDIR}/${PN}_build" 137 CMAKE_BUILD_DIR="${CMAKE_USE_DIR}/build"
138 else
139 # regular out of tree build
140 [[ ${1} = init || -d ${CMAKE_USE_DIR}_build ]] && SUF="_build" || SUF=""
141 CMAKE_BUILD_DIR="${CMAKE_USE_DIR}${SUF}"
142
92 fi 143 fi
93 echo ">>> Working in BUILD_DIR: \"$CMAKE_BUILD_DIR\"" 144 echo ">>> Working in BUILD_DIR: \"$CMAKE_BUILD_DIR\""
94} 145}
95# @FUNCTION: cmake-utils_use_with 146# @FUNCTION: cmake-utils_use_with
96# @USAGE: <USE flag> [flag name] 147# @USAGE: <USE flag> [flag name]
97# @DESCRIPTION: 148# @DESCRIPTION:
98# Based on use_with. See ebuild(5). 149# Based on use_with. See ebuild(5).
99# 150#
100# `cmake-utils_use_with foo FOO` echoes -DWITH_FOO=ON if foo is enabled 151# `cmake-utils_use_with foo FOO` echoes -DWITH_FOO=ON if foo is enabled
101# and -DWITH_FOO=OFF if it is disabled. 152# and -DWITH_FOO=OFF if it is disabled.
102cmake-utils_use_with() { _use_me_now WITH "$@" ; } 153cmake-utils_use_with() { _use_me_now WITH_ "$@" ; }
103 154
104# @FUNCTION: cmake-utils_use_enable 155# @FUNCTION: cmake-utils_use_enable
105# @USAGE: <USE flag> [flag name] 156# @USAGE: <USE flag> [flag name]
106# @DESCRIPTION: 157# @DESCRIPTION:
107# Based on use_enable. See ebuild(5). 158# Based on use_enable. See ebuild(5).
108# 159#
109# `cmake-utils_use_enable foo FOO` echoes -DENABLE_FOO=ON if foo is enabled 160# `cmake-utils_use_enable foo FOO` echoes -DENABLE_FOO=ON if foo is enabled
110# and -DENABLE_FOO=OFF if it is disabled. 161# and -DENABLE_FOO=OFF if it is disabled.
111cmake-utils_use_enable() { _use_me_now ENABLE "$@" ; } 162cmake-utils_use_enable() { _use_me_now ENABLE_ "$@" ; }
112 163
113# @FUNCTION: cmake-utils_use_disable 164# @FUNCTION: cmake-utils_use_disable
114# @USAGE: <USE flag> [flag name] 165# @USAGE: <USE flag> [flag name]
115# @DESCRIPTION: 166# @DESCRIPTION:
116# Based on inversion of use_enable. See ebuild(5). 167# Based on inversion of use_enable. See ebuild(5).
117# 168#
118# `cmake-utils_use_enable foo FOO` echoes -DDISABLE_FOO=OFF if foo is enabled 169# `cmake-utils_use_enable foo FOO` echoes -DDISABLE_FOO=OFF if foo is enabled
119# and -DDISABLE_FOO=ON if it is disabled. 170# and -DDISABLE_FOO=ON if it is disabled.
120cmake-utils_use_disable() { _use_me_now_inverted DISABLE "$@" ; } 171cmake-utils_use_disable() { _use_me_now_inverted DISABLE_ "$@" ; }
121 172
122# @FUNCTION: cmake-utils_use_no 173# @FUNCTION: cmake-utils_use_no
123# @USAGE: <USE flag> [flag name] 174# @USAGE: <USE flag> [flag name]
124# @DESCRIPTION: 175# @DESCRIPTION:
125# Based on use_disable. See ebuild(5). 176# Based on use_disable. See ebuild(5).
126# 177#
127# `cmake-utils_use_no foo FOO` echoes -DNO_FOO=OFF if foo is enabled 178# `cmake-utils_use_no foo FOO` echoes -DNO_FOO=OFF if foo is enabled
128# and -DNO_FOO=ON if it is disabled. 179# and -DNO_FOO=ON if it is disabled.
129cmake-utils_use_no() { _use_me_now_inverted NO "$@" ; } 180cmake-utils_use_no() { _use_me_now_inverted NO_ "$@" ; }
130 181
131# @FUNCTION: cmake-utils_use_want 182# @FUNCTION: cmake-utils_use_want
132# @USAGE: <USE flag> [flag name] 183# @USAGE: <USE flag> [flag name]
133# @DESCRIPTION: 184# @DESCRIPTION:
134# Based on use_enable. See ebuild(5). 185# Based on use_enable. See ebuild(5).
135# 186#
136# `cmake-utils_use_want foo FOO` echoes -DWANT_FOO=ON if foo is enabled 187# `cmake-utils_use_want foo FOO` echoes -DWANT_FOO=ON if foo is enabled
137# and -DWANT_FOO=OFF if it is disabled. 188# and -DWANT_FOO=OFF if it is disabled.
138cmake-utils_use_want() { _use_me_now WANT "$@" ; } 189cmake-utils_use_want() { _use_me_now WANT_ "$@" ; }
139 190
140# @FUNCTION: cmake-utils_use_build 191# @FUNCTION: cmake-utils_use_build
141# @USAGE: <USE flag> [flag name] 192# @USAGE: <USE flag> [flag name]
142# @DESCRIPTION: 193# @DESCRIPTION:
143# Based on use_enable. See ebuild(5). 194# Based on use_enable. See ebuild(5).
144# 195#
145# `cmake-utils_use_build foo FOO` echoes -DBUILD_FOO=ON if foo is enabled 196# `cmake-utils_use_build foo FOO` echoes -DBUILD_FOO=ON if foo is enabled
146# and -DBUILD_FOO=OFF if it is disabled. 197# and -DBUILD_FOO=OFF if it is disabled.
147cmake-utils_use_build() { _use_me_now BUILD "$@" ; } 198cmake-utils_use_build() { _use_me_now BUILD_ "$@" ; }
148 199
149# @FUNCTION: cmake-utils_use_has 200# @FUNCTION: cmake-utils_use_has
150# @USAGE: <USE flag> [flag name] 201# @USAGE: <USE flag> [flag name]
151# @DESCRIPTION: 202# @DESCRIPTION:
152# Based on use_enable. See ebuild(5). 203# Based on use_enable. See ebuild(5).
153# 204#
154# `cmake-utils_use_has foo FOO` echoes -DHAVE_FOO=ON if foo is enabled 205# `cmake-utils_use_has foo FOO` echoes -DHAVE_FOO=ON if foo is enabled
155# and -DHAVE_FOO=OFF if it is disabled. 206# and -DHAVE_FOO=OFF if it is disabled.
156cmake-utils_use_has() { _use_me_now HAVE "$@" ; } 207cmake-utils_use_has() { _use_me_now HAVE_ "$@" ; }
157 208
158# @FUNCTION: cmake-utils_has 209# @FUNCTION: cmake-utils_has
159# @DESCRIPTION: 210# @DESCRIPTION:
160# Deprecated, use cmake-utils_use_has, kept now for backcompat. 211# Deprecated, use cmake-utils_use_has, kept now for backcompat.
161cmake-utils_has() { ewarn "QA notice: using deprecated ${FUNCNAME} call, use cmake-utils_use_has instead." ; _use_me_now HAVE "$@" ; } 212cmake-utils_has() { ewarn "QA notice: using deprecated ${FUNCNAME} call, use cmake-utils_use_has instead." ; _use_me_now HAVE_ "$@" ; }
162 213
163# @FUNCTION: cmake-utils_use 214# @FUNCTION: cmake-utils_use
164# @USAGE: <USE flag> [flag name] 215# @USAGE: <USE flag> [flag name]
165# @DESCRIPTION: 216# @DESCRIPTION:
166# Based on use_enable. See ebuild(5). 217# Based on use_enable. See ebuild(5).
174_modify-cmakelists() { 225_modify-cmakelists() {
175 debug-print-function ${FUNCNAME} "$@" 226 debug-print-function ${FUNCNAME} "$@"
176 227
177 # Comment out all set (<some_should_be_user_defined_variable> value) 228 # Comment out all set (<some_should_be_user_defined_variable> value)
178 # TODO Add QA checker - inform when variable being checked for below is set in CMakeLists.txt 229 # TODO Add QA checker - inform when variable being checked for below is set in CMakeLists.txt
179 find "${S}" -name CMakeLists.txt \ 230 find "${CMAKE_USE_DIR}" -name CMakeLists.txt \
180 -exec sed -i -e '/^[[:space:]]*[sS][eE][tT][[:space:]]*([[:space:]]*CMAKE_BUILD_TYPE.*)/{s/^/#IGNORE /g}' {} + \ 231 -exec sed -i -e '/^[[:space:]]*[sS][eE][tT][[:space:]]*([[:space:]]*CMAKE_BUILD_TYPE.*)/{s/^/#IGNORE /g}' {} + \
181 -exec sed -i -e '/^[[:space:]]*[sS][eE][tT][[:space:]]*([[:space:]]*CMAKE_INSTALL_PREFIX.*)/{s/^/#IGNORE /g}' {} + \ 232 -exec sed -i -e '/^[[:space:]]*[sS][eE][tT][[:space:]]*([[:space:]]*CMAKE_INSTALL_PREFIX.*)/{s/^/#IGNORE /g}' {} + \
182 || die "${LINENO}: failed to disable hardcoded settings" 233 || die "${LINENO}: failed to disable hardcoded settings"
183 234
184 # NOTE Append some useful summary here 235 # NOTE Append some useful summary here
192# @DESCRIPTION: 243# @DESCRIPTION:
193# General function for configuring with cmake. Default behaviour is to start an 244# General function for configuring with cmake. Default behaviour is to start an
194# out-of-source build. 245# out-of-source build.
195cmake-utils_src_configure() { 246cmake-utils_src_configure() {
196 debug-print-function ${FUNCNAME} "$@" 247 debug-print-function ${FUNCNAME} "$@"
248
249 _check_build_dir init
250
251 # check if CMakeLists.txt exist and if no then die
252 if [[ ! -e "${CMAKE_USE_DIR}"/CMakeLists.txt ]] ; then
253 eerror "I was unable to locate CMakeLists.txt under:"
254 eerror "\"${CMAKE_USE_DIR}/CMakeLists.txt\""
255 eerror "You should consider not inheriting the cmake eclass."
256 die "FATAL: Unable to find CMakeLists.txt"
257 fi
197 258
198 # Remove dangerous things. 259 # Remove dangerous things.
199 _modify-cmakelists 260 _modify-cmakelists
200 261
201 # @SEE CMAKE_BUILD_TYPE 262 # @SEE CMAKE_BUILD_TYPE
232SET (LIB_SUFFIX ${libdir/lib} CACHE STRING "library path suffix" FORCE) 293SET (LIB_SUFFIX ${libdir/lib} CACHE STRING "library path suffix" FORCE)
233_EOF_ 294_EOF_
234 [[ -n ${CMAKE_NO_COLOR} ]] && echo 'SET (CMAKE_COLOR_MAKEFILE OFF CACHE BOOL "pretty colors during make" FORCE)' >> ${common_config} 295 [[ -n ${CMAKE_NO_COLOR} ]] && echo 'SET (CMAKE_COLOR_MAKEFILE OFF CACHE BOOL "pretty colors during make" FORCE)' >> ${common_config}
235 cmakeargs="-C ${common_config} ${cmakeargs}" 296 cmakeargs="-C ${common_config} ${cmakeargs}"
236 297
237 _check_build_dir
238 mkdir -p "${CMAKE_BUILD_DIR}" 298 mkdir -p "${CMAKE_BUILD_DIR}"
239 pushd "${CMAKE_BUILD_DIR}" > /dev/null 299 pushd "${CMAKE_BUILD_DIR}" > /dev/null
240 debug-print "${LINENO} ${ECLASS} ${FUNCNAME}: mycmakeargs is $cmakeargs" 300 debug-print "${LINENO} ${ECLASS} ${FUNCNAME}: mycmakeargs is $cmakeargs"
241 cmake ${cmakeargs} "${S}" || die "cmake failed" 301 cmake ${cmakeargs} "${CMAKE_USE_DIR}" || die "cmake failed"
242 302
243 popd > /dev/null 303 popd > /dev/null
244} 304}
245 305
246# @FUNCTION: cmake-utils_src_compile 306# @FUNCTION: cmake-utils_src_compile
276# All arguments are passed to emake: 336# All arguments are passed to emake:
277cmake-utils_src_make() { 337cmake-utils_src_make() {
278 debug-print-function ${FUNCNAME} "$@" 338 debug-print-function ${FUNCNAME} "$@"
279 339
280 _check_build_dir 340 _check_build_dir
281 pushd "${CMAKE_BUILD_DIR}" > /dev/null 341 pushd "${CMAKE_BUILD_DIR}" &> /dev/null
342 # first check if Makefile exist otherwise die
343 [[ -e Makefile ]] || die "Makefile not found. Error during configure stage."
282 if [[ -n ${CMAKE_VERBOSE} ]]; then 344 if [[ -n ${CMAKE_VERBOSE} ]]; then
283 emake VERBOSE=1 "$@" || die "Make failed!" 345 emake VERBOSE=1 "$@" || die "Make failed!"
284 else 346 else
285 emake "$@" || die "Make failed!" 347 emake "$@" || die "Make failed!"
286 fi 348 fi
287 popd > /dev/null 349 popd &> /dev/null
288} 350}
289 351
290# @FUNCTION: cmake-utils_src_install 352# @FUNCTION: cmake-utils_src_install
291# @DESCRIPTION: 353# @DESCRIPTION:
292# Function for installing the package. Automatically detects the build type. 354# Function for installing the package. Automatically detects the build type.
293cmake-utils_src_install() { 355cmake-utils_src_install() {
294 debug-print-function ${FUNCNAME} "$@" 356 debug-print-function ${FUNCNAME} "$@"
295 357
296 _check_build_dir 358 _check_build_dir
297 pushd "${CMAKE_BUILD_DIR}" > /dev/null 359 pushd "${CMAKE_BUILD_DIR}" &> /dev/null
298 emake install DESTDIR="${D}" || die "Make install failed" 360 emake install DESTDIR="${D}" || die "Make install failed"
299 popd > /dev/null 361 popd &> /dev/null
300 362
301 # Manual document installation 363 # Manual document installation
302 [[ -n "${DOCS}" ]] && { dodoc ${DOCS} || die "dodoc failed" ; } 364 [[ -n "${DOCS}" ]] && { dodoc ${DOCS} || die "dodoc failed" ; }
303 [[ -n "${HTML_DOCS}" ]] && { dohtml -r ${HTML_DOCS} || die "dohtml failed" ; } 365 [[ -n "${HTML_DOCS}" ]] && { dohtml -r ${HTML_DOCS} || die "dohtml failed" ; }
304} 366}
308# Function for testing the package. Automatically detects the build type. 370# Function for testing the package. Automatically detects the build type.
309cmake-utils_src_test() { 371cmake-utils_src_test() {
310 debug-print-function ${FUNCNAME} "$@" 372 debug-print-function ${FUNCNAME} "$@"
311 373
312 _check_build_dir 374 _check_build_dir
313 pushd "${CMAKE_BUILD_DIR}" > /dev/null 375 pushd "${CMAKE_BUILD_DIR}" &> /dev/null
314 # Standard implementation of src_test 376 # Standard implementation of src_test
315 if emake -j1 check -n &> /dev/null; then 377 if emake -j1 check -n &> /dev/null; then
316 einfo ">>> Test phase [check]: ${CATEGORY}/${PF}" 378 einfo ">>> Test phase [check]: ${CATEGORY}/${PF}"
317 if ! emake -j1 check; then 379 if ! emake -j1 check; then
318 die "Make check failed. See above for details." 380 die "Make check failed. See above for details."
323 die "Make test failed. See above for details." 385 die "Make test failed. See above for details."
324 fi 386 fi
325 else 387 else
326 einfo ">>> Test phase [none]: ${CATEGORY}/${PF}" 388 einfo ">>> Test phase [none]: ${CATEGORY}/${PF}"
327 fi 389 fi
328 popd > /dev/null 390 popd &> /dev/null
329} 391}

Legend:
Removed from v.1.18  
changed lines
  Added in v.1.29

  ViewVC Help
Powered by ViewVC 1.1.20