| 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.21 2009/03/15 16:54:32 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 | |
| 21 | inherit toolchain-funcs multilib flag-o-matic base |
23 | inherit toolchain-funcs multilib flag-o-matic base |
| 22 | |
24 | |
| 23 | EXPF="src_compile src_test src_install" |
25 | EXPF="src_compile src_test src_install" |
| 24 | case ${EAPI:-0} in |
26 | case ${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." ;; |
| 29 | esac |
30 | esac |
| 30 | EXPORT_FUNCTIONS ${EXPF} |
31 | EXPORT_FUNCTIONS ${EXPF} |
| 31 | |
32 | |
| 32 | : ${DESCRIPTION:="Based on the ${ECLASS} eclass"} |
33 | : ${DESCRIPTION:="Based on the ${ECLASS} eclass"} |
| 33 | |
34 | |
|
|
35 | if [[ ${PN} != cmake ]]; then |
| 34 | DEPEND=">=dev-util/cmake-2.6.2-r1" |
36 | CMAKEDEPEND=">=dev-util/cmake-2.6.2-r1" |
|
|
37 | fi |
|
|
38 | |
|
|
39 | DEPEND="${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] |
| … | |
… | |
| 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. |
| 195 | cmake-utils_src_configure() { |
239 | cmake-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 |
| … | |
… | |
| 232 | SET (LIB_SUFFIX ${libdir/lib} CACHE STRING "library path suffix" FORCE) |
286 | SET (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 |
| … | |
… | |
| 277 | cmake-utils_src_make() { |
330 | cmake-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 |