/[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.19 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.19 2009/03/12 08:45:52 fauli 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
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
89 CMAKE_BUILD_DIR="${S}" 133 CMAKE_BUILD_DIR="${CMAKE_USE_DIR}"
90 else 134 else
91 CMAKE_BUILD_DIR="${WORKDIR}/${PN}_build" 135 CMAKE_BUILD_DIR="${CMAKE_USE_DIR}_build"
92 fi 136 fi
93 echo ">>> Working in BUILD_DIR: \"$CMAKE_BUILD_DIR\"" 137 echo ">>> Working in BUILD_DIR: \"$CMAKE_BUILD_DIR\""
94} 138}
95# @FUNCTION: cmake-utils_use_with 139# @FUNCTION: cmake-utils_use_with
96# @USAGE: <USE flag> [flag name] 140# @USAGE: <USE flag> [flag name]
97# @DESCRIPTION: 141# @DESCRIPTION:
98# Based on use_with. See ebuild(5). 142# Based on use_with. See ebuild(5).
99# 143#
100# `cmake-utils_use_with foo FOO` echoes -DWITH_FOO=ON if foo is enabled 144# `cmake-utils_use_with foo FOO` echoes -DWITH_FOO=ON if foo is enabled
101# and -DWITH_FOO=OFF if it is disabled. 145# and -DWITH_FOO=OFF if it is disabled.
102cmake-utils_use_with() { _use_me_now WITH "$@" ; } 146cmake-utils_use_with() { _use_me_now WITH_ "$@" ; }
103 147
104# @FUNCTION: cmake-utils_use_enable 148# @FUNCTION: cmake-utils_use_enable
105# @USAGE: <USE flag> [flag name] 149# @USAGE: <USE flag> [flag name]
106# @DESCRIPTION: 150# @DESCRIPTION:
107# Based on use_enable. See ebuild(5). 151# Based on use_enable. See ebuild(5).
108# 152#
109# `cmake-utils_use_enable foo FOO` echoes -DENABLE_FOO=ON if foo is enabled 153# `cmake-utils_use_enable foo FOO` echoes -DENABLE_FOO=ON if foo is enabled
110# and -DENABLE_FOO=OFF if it is disabled. 154# and -DENABLE_FOO=OFF if it is disabled.
111cmake-utils_use_enable() { _use_me_now ENABLE "$@" ; } 155cmake-utils_use_enable() { _use_me_now ENABLE_ "$@" ; }
112 156
113# @FUNCTION: cmake-utils_use_disable 157# @FUNCTION: cmake-utils_use_disable
114# @USAGE: <USE flag> [flag name] 158# @USAGE: <USE flag> [flag name]
115# @DESCRIPTION: 159# @DESCRIPTION:
116# Based on inversion of use_enable. See ebuild(5). 160# Based on inversion of use_enable. See ebuild(5).
117# 161#
118# `cmake-utils_use_enable foo FOO` echoes -DDISABLE_FOO=OFF if foo is enabled 162# `cmake-utils_use_enable foo FOO` echoes -DDISABLE_FOO=OFF if foo is enabled
119# and -DDISABLE_FOO=ON if it is disabled. 163# and -DDISABLE_FOO=ON if it is disabled.
120cmake-utils_use_disable() { _use_me_now_inverted DISABLE "$@" ; } 164cmake-utils_use_disable() { _use_me_now_inverted DISABLE_ "$@" ; }
121 165
122# @FUNCTION: cmake-utils_use_no 166# @FUNCTION: cmake-utils_use_no
123# @USAGE: <USE flag> [flag name] 167# @USAGE: <USE flag> [flag name]
124# @DESCRIPTION: 168# @DESCRIPTION:
125# Based on use_disable. See ebuild(5). 169# Based on use_disable. See ebuild(5).
126# 170#
127# `cmake-utils_use_no foo FOO` echoes -DNO_FOO=OFF if foo is enabled 171# `cmake-utils_use_no foo FOO` echoes -DNO_FOO=OFF if foo is enabled
128# and -DNO_FOO=ON if it is disabled. 172# and -DNO_FOO=ON if it is disabled.
129cmake-utils_use_no() { _use_me_now_inverted NO "$@" ; } 173cmake-utils_use_no() { _use_me_now_inverted NO_ "$@" ; }
130 174
131# @FUNCTION: cmake-utils_use_want 175# @FUNCTION: cmake-utils_use_want
132# @USAGE: <USE flag> [flag name] 176# @USAGE: <USE flag> [flag name]
133# @DESCRIPTION: 177# @DESCRIPTION:
134# Based on use_enable. See ebuild(5). 178# Based on use_enable. See ebuild(5).
135# 179#
136# `cmake-utils_use_want foo FOO` echoes -DWANT_FOO=ON if foo is enabled 180# `cmake-utils_use_want foo FOO` echoes -DWANT_FOO=ON if foo is enabled
137# and -DWANT_FOO=OFF if it is disabled. 181# and -DWANT_FOO=OFF if it is disabled.
138cmake-utils_use_want() { _use_me_now WANT "$@" ; } 182cmake-utils_use_want() { _use_me_now WANT_ "$@" ; }
139 183
140# @FUNCTION: cmake-utils_use_build 184# @FUNCTION: cmake-utils_use_build
141# @USAGE: <USE flag> [flag name] 185# @USAGE: <USE flag> [flag name]
142# @DESCRIPTION: 186# @DESCRIPTION:
143# Based on use_enable. See ebuild(5). 187# Based on use_enable. See ebuild(5).
144# 188#
145# `cmake-utils_use_build foo FOO` echoes -DBUILD_FOO=ON if foo is enabled 189# `cmake-utils_use_build foo FOO` echoes -DBUILD_FOO=ON if foo is enabled
146# and -DBUILD_FOO=OFF if it is disabled. 190# and -DBUILD_FOO=OFF if it is disabled.
147cmake-utils_use_build() { _use_me_now BUILD "$@" ; } 191cmake-utils_use_build() { _use_me_now BUILD_ "$@" ; }
148 192
149# @FUNCTION: cmake-utils_use_has 193# @FUNCTION: cmake-utils_use_has
150# @USAGE: <USE flag> [flag name] 194# @USAGE: <USE flag> [flag name]
151# @DESCRIPTION: 195# @DESCRIPTION:
152# Based on use_enable. See ebuild(5). 196# Based on use_enable. See ebuild(5).
153# 197#
154# `cmake-utils_use_has foo FOO` echoes -DHAVE_FOO=ON if foo is enabled 198# `cmake-utils_use_has foo FOO` echoes -DHAVE_FOO=ON if foo is enabled
155# and -DHAVE_FOO=OFF if it is disabled. 199# and -DHAVE_FOO=OFF if it is disabled.
156cmake-utils_use_has() { _use_me_now HAVE "$@" ; } 200cmake-utils_use_has() { _use_me_now HAVE_ "$@" ; }
157 201
158# @FUNCTION: cmake-utils_has 202# @FUNCTION: cmake-utils_has
159# @DESCRIPTION: 203# @DESCRIPTION:
160# Deprecated, use cmake-utils_use_has, kept now for backcompat. 204# 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 "$@" ; } 205cmake-utils_has() { ewarn "QA notice: using deprecated ${FUNCNAME} call, use cmake-utils_use_has instead." ; _use_me_now HAVE_ "$@" ; }
162 206
163# @FUNCTION: cmake-utils_use 207# @FUNCTION: cmake-utils_use
164# @USAGE: <USE flag> [flag name] 208# @USAGE: <USE flag> [flag name]
165# @DESCRIPTION: 209# @DESCRIPTION:
166# Based on use_enable. See ebuild(5). 210# Based on use_enable. See ebuild(5).
174_modify-cmakelists() { 218_modify-cmakelists() {
175 debug-print-function ${FUNCNAME} "$@" 219 debug-print-function ${FUNCNAME} "$@"
176 220
177 # Comment out all set (<some_should_be_user_defined_variable> value) 221 # 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 222 # TODO Add QA checker - inform when variable being checked for below is set in CMakeLists.txt
179 find "${S}" -name CMakeLists.txt \ 223 find "${CMAKE_USE_DIR}" -name CMakeLists.txt \
180 -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}' {} + \
181 -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}' {} + \
182 || die "${LINENO}: failed to disable hardcoded settings" 226 || die "${LINENO}: failed to disable hardcoded settings"
183 227
184 # NOTE Append some useful summary here 228 # NOTE Append some useful summary here
192# @DESCRIPTION: 236# @DESCRIPTION:
193# 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
194# out-of-source build. 238# out-of-source build.
195cmake-utils_src_configure() { 239cmake-utils_src_configure() {
196 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
197 251
198 # Remove dangerous things. 252 # Remove dangerous things.
199 _modify-cmakelists 253 _modify-cmakelists
200 254
201 # @SEE CMAKE_BUILD_TYPE 255 # @SEE CMAKE_BUILD_TYPE
232SET (LIB_SUFFIX ${libdir/lib} CACHE STRING "library path suffix" FORCE) 286SET (LIB_SUFFIX ${libdir/lib} CACHE STRING "library path suffix" FORCE)
233_EOF_ 287_EOF_
234 [[ -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}
235 cmakeargs="-C ${common_config} ${cmakeargs}" 289 cmakeargs="-C ${common_config} ${cmakeargs}"
236 290
237 _check_build_dir
238 mkdir -p "${CMAKE_BUILD_DIR}" 291 mkdir -p "${CMAKE_BUILD_DIR}"
239 pushd "${CMAKE_BUILD_DIR}" > /dev/null 292 pushd "${CMAKE_BUILD_DIR}" > /dev/null
240 debug-print "${LINENO} ${ECLASS} ${FUNCNAME}: mycmakeargs is $cmakeargs" 293 debug-print "${LINENO} ${ECLASS} ${FUNCNAME}: mycmakeargs is $cmakeargs"
241 cmake ${cmakeargs} "${S}" || die "cmake failed" 294 cmake ${cmakeargs} "${CMAKE_USE_DIR}" || die "cmake failed"
242 295
243 popd > /dev/null 296 popd > /dev/null
244} 297}
245 298
246# @FUNCTION: cmake-utils_src_compile 299# @FUNCTION: cmake-utils_src_compile
277cmake-utils_src_make() { 330cmake-utils_src_make() {
278 debug-print-function ${FUNCNAME} "$@" 331 debug-print-function ${FUNCNAME} "$@"
279 332
280 _check_build_dir 333 _check_build_dir
281 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."
282 if [[ -n ${CMAKE_VERBOSE} ]]; then 337 if [[ -n ${CMAKE_VERBOSE} ]]; then
283 emake VERBOSE=1 "$@" || die "Make failed!" 338 emake VERBOSE=1 "$@" || die "Make failed!"
284 else 339 else
285 emake "$@" || die "Make failed!" 340 emake "$@" || die "Make failed!"
286 fi 341 fi

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

  ViewVC Help
Powered by ViewVC 1.1.20