/[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.1 Revision 1.13
1# Copyright 1999-2007 Gentoo Foundation 1# Copyright 1999-2007 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.1 2007/11/04 13:17:35 philantrop Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/cmake-utils.eclass,v 1.13 2008/10/27 14:38:38 vapier 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# @BLURB: common ebuild functions for cmake-based packages 8# @BLURB: common ebuild functions for cmake-based packages
17 17
18inherit toolchain-funcs multilib 18inherit toolchain-funcs multilib
19 19
20DESCRIPTION="Based on the ${ECLASS} eclass" 20DESCRIPTION="Based on the ${ECLASS} eclass"
21 21
22DEPEND="dev-util/cmake" 22DEPEND=">=dev-util/cmake-2.4.6"
23 23
24case ${EAPI} in
25 2)
26 EXPORT_FUNCTIONS src_configure src_compile src_test src_install
27 ;;
28 *)
24EXPORT_FUNCTIONS src_compile src_test src_install 29 EXPORT_FUNCTIONS src_compile src_test src_install
30 ;;
31esac
32
25 33
26# Internal function use by cmake-utils_use_with and cmake-utils_use_enable 34# Internal function use by cmake-utils_use_with and cmake-utils_use_enable
27_use_me_now() { 35_use_me_now() {
28 debug-print-function $FUNCNAME $* 36 debug-print-function $FUNCNAME $*
29 [[ -z $2 ]] && die "cmake-utils_use-$1 <USE flag> [<flag name>]" 37 [[ -z $2 ]] && die "cmake-utils_use-$1 <USE flag> [<flag name>]"
30 echo "-D$1_${3:-$2}=$(use $2 && echo ON || echo OFF)" 38 echo "-D$1_${3:-$2}=$(use $2 && echo ON || echo OFF)"
31} 39}
32 40
41# @VARIABLE: DOCS
42# @DESCRIPTION:
43# Documents to dodoc
44
33# @FUNCTION: cmake-utils_use_with 45# @FUNCTION: cmake-utils_use_with
34# @USAGE: <USE flag> [flag name] 46# @USAGE: <USE flag> [flag name]
35# @DESCRIPTION: 47# @DESCRIPTION:
36# Based on use_with. See ebuild.sh 48# Based on use_with. See ebuild(5).
49#
50# `cmake-utils_use_with foo FOO` echoes -DWITH_FOO=ON if foo is enabled
51# and -DWITH_FOO=OFF if it is disabled.
37cmake-utils_use_with() { _use_me_now WITH "$@" ; } 52cmake-utils_use_with() { _use_me_now WITH "$@" ; }
38 53
39# @FUNCTION: cmake-utils_use_enable 54# @FUNCTION: cmake-utils_use_enable
40# @USAGE: <USE flag> [flag name] 55# @USAGE: <USE flag> [flag name]
41# @DESCRIPTION: 56# @DESCRIPTION:
42# Based on use_enable. See ebuild.sh 57# Based on use_enable. See ebuild(5).
58#
59# `cmake-utils_use_enable foo FOO` echoes -DENABLE_FOO=ON if foo is enabled
60# and -DENABLE_FOO=OFF if it is disabled.
43cmake-utils_use_enable() { _use_me_now ENABLE "$@" ; } 61cmake-utils_use_enable() { _use_me_now ENABLE "$@" ; }
44 62
63# @FUNCTION: cmake-utils_use_want
64# @USAGE: <USE flag> [flag name]
65# @DESCRIPTION:
66# Based on use_enable. See ebuild(5).
67#
68# `cmake-utils_use_want foo FOO` echoes -DWANT_FOO=ON if foo is enabled
69# and -DWANT_FOO=OFF if it is disabled.
70cmake-utils_use_want() { _use_me_now WANT "$@" ; }
71
72# @FUNCTION: cmake-utils_has
73# @USAGE: <USE flag> [flag name]
74# @DESCRIPTION:
75# Based on use_enable. See ebuild(5).
76#
77# `cmake-utils_has foo FOO` echoes -DHAVE_FOO=ON if foo is enabled
78# and -DHAVE_FOO=OFF if it is disabled.
79cmake-utils_has() { _use_me_now HAVE "$@" ; }
80
81# @FUNCTION: cmake-utils_src_configure
82# @DESCRIPTION:
83# General function for configuring with cmake. Default behaviour is to start an
84# out-of-source build.
85cmake-utils_src_configure() {
86 debug-print-function $FUNCNAME $*
87
88 if ! has debug ${IUSE//+} || ! use debug ; then
89 append-cppflags -DNDEBUG
90 fi
91
92 if [[ -n "${CMAKE_IN_SOURCE_BUILD}" ]]; then
93 cmake-utils_src_configurein
94 else
95 cmake-utils_src_configureout
96 fi
97}
98
45# @FUNCTION: cmake-utils_src_compile 99# @FUNCTION: cmake-utils_src_compile
46# @DESCRIPTION: 100# @DESCRIPTION:
47# General function for compiling with cmake. Default behaviour is to start an 101# General function for compiling with cmake. Default behaviour is to check for
48# out-of-source build 102# eapi and based on it configure or only compile
49cmake-utils_src_compile() { 103cmake-utils_src_compile() {
50 debug-print-function $FUNCNAME $* 104 case ${EAPI} in
51 105 2)
106 ;;
107 *)
52 cmake-utils_src_configureout 108 cmake-utils_src_configure
109 ;;
110 esac
111
53 cmake-utils_src_make 112 cmake-utils_src_make "$@"
54} 113}
55 114
56# @FUNCTION: cmake-utils_src_configurein 115# @FUNCTION: cmake-utils_src_configurein
57# @DESCRIPTION: 116# @DESCRIPTION:
58# Function for software that requires configure and building in the source 117# Function for software that requires configure and building in the source
59# directory. 118# directory.
60cmake-utils_src_configurein() { 119cmake-utils_src_configurein() {
61 debug-print-function $FUNCNAME $* 120 debug-print-function $FUNCNAME $*
62 121
63 local cmakeargs="${mycmakeargs} $(_common_configure_code)" 122 local cmakeargs="$(_common_configure_code) ${mycmakeargs} ${EXTRA_ECONF}"
64 123
65 debug-print "$LINENO $ECLASS $FUNCNAME: mycmakeargs is $cmakeargs" 124 debug-print "$LINENO $ECLASS $FUNCNAME: mycmakeargs is $cmakeargs"
66 cmake ${cmakeargs} . || die "Cmake failed" 125 cmake ${cmakeargs} . || die "Cmake failed"
67} 126}
68 127
71# Function for software that requires configure and building outside the source 130# Function for software that requires configure and building outside the source
72# tree - default. 131# tree - default.
73cmake-utils_src_configureout() { 132cmake-utils_src_configureout() {
74 debug-print-function $FUNCNAME $* 133 debug-print-function $FUNCNAME $*
75 134
76 local cmakeargs="${mycmakeargs} $(_common_configure_code)" 135 local cmakeargs="$(_common_configure_code) ${mycmakeargs} ${EXTRA_ECONF}"
77 mkdir "${WORKDIR}"/${PN}_build 136 mkdir -p "${WORKDIR}"/${PN}_build
78 cd "${WORKDIR}"/${PN}_build 137 pushd "${WORKDIR}"/${PN}_build > /dev/null
79 138
80 debug-print "$LINENO $ECLASS $FUNCNAME: mycmakeargs is $cmakeargs" 139 debug-print "$LINENO $ECLASS $FUNCNAME: mycmakeargs is $cmakeargs"
81 cmake ${cmakeargs} "${S}" || die "Cmake failed" 140 cmake ${cmakeargs} "${S}" || die "Cmake failed"
141
142 popd > /dev/null
82} 143}
83 144
84# Internal use only. Common configuration options for all types of builds. 145# Internal use only. Common configuration options for all types of builds.
85_common_configure_code() { 146_common_configure_code() {
86 local tmp_libdir=$(get_libdir) 147 local tmp_libdir=$(get_libdir)
87 if has debug ${IUSE} && use debug; then 148 # CMAKE_BUILD_TYPE only modifies compiler flags, so set to None
88 echo -DCMAKE_BUILD_TYPE=debug 149 echo -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE:-None}
89 fi
90 echo -DCMAKE_C_COMPILER=$(type -P $(tc-getCC)) 150 echo -DCMAKE_C_COMPILER=$(type -P $(tc-getCC))
91 echo -DCMAKE_CXX_COMPILER=$(type -P $(tc-getCXX)) 151 echo -DCMAKE_CXX_COMPILER=$(type -P $(tc-getCXX))
92 echo -DCMAKE_INSTALL_PREFIX=${PREFIX:-/usr} 152 echo -DCMAKE_INSTALL_PREFIX=${PREFIX:-/usr}
93 echo -DLIB_SUFFIX=${tmp_libdir/lib} 153 echo -DLIB_SUFFIX=${tmp_libdir/lib}
154 echo -DLIB_INSTALL_DIR=${PREFIX:-/usr}/${tmp_libdir}
94 [[ -n ${CMAKE_NO_COLOR} ]] && echo -DCMAKE_COLOR_MAKEFILE=OFF 155 [[ -n ${CMAKE_NO_COLOR} ]] && echo -DCMAKE_COLOR_MAKEFILE=OFF
95} 156}
96 157
97# @FUNCTION: cmake-utils_src_make 158# @FUNCTION: cmake-utils_src_make
98# @DESCRIPTION: 159# @DESCRIPTION:
99# Function for building the package. Automatically detects the build type. 160# Function for building the package. Automatically detects the build type.
161# All arguments are passed to emake:
162# "cmake-utils_src_make -j1" can be used to work around parallel make issues.
100cmake-utils_src_make() { 163cmake-utils_src_make() {
101 debug-print-function $FUNCNAME $* 164 debug-print-function $FUNCNAME $*
102 165
103 # At this point we can automatically check if it's an out-of-source or an 166 # At this point we can automatically check if it's an out-of-source or an
104 # in-source build 167 # in-source build
105 if [[ -d ${WORKDIR}/${PN}_build ]]; then 168 if [[ -d ${WORKDIR}/${PN}_build ]]; then
106 cd "${WORKDIR}"/${PN}_build; 169 pushd "${WORKDIR}"/${PN}_build > /dev/null
107 fi 170 fi
108 if ! [[ -z ${CMAKE_COMPILER_VERBOSE} ]]; then 171 if ! [[ -z ${CMAKE_COMPILER_VERBOSE} ]]; then
109 emake VERBOSE=1 || die "Make failed!"; 172 emake VERBOSE=1 "$@" || die "Make failed!"
110 else 173 else
111 emake || die "Make failed!"; 174 emake "$@" || die "Make failed!"
175 fi
176 if [[ -d ${WORKDIR}/${PN}_build ]]; then
177 popd > /dev/null
112 fi 178 fi
113} 179}
114 180
115# @FUNCTION: cmake-utils_src_install 181# @FUNCTION: cmake-utils_src_install
116# @DESCRIPTION: 182# @DESCRIPTION:
119 debug-print-function $FUNCNAME $* 185 debug-print-function $FUNCNAME $*
120 186
121 # At this point we can automatically check if it's an out-of-source or an 187 # At this point we can automatically check if it's an out-of-source or an
122 # in-source build 188 # in-source build
123 if [[ -d ${WORKDIR}/${PN}_build ]]; then 189 if [[ -d ${WORKDIR}/${PN}_build ]]; then
124 cd "${WORKDIR}"/${PN}_build; 190 pushd "${WORKDIR}"/${PN}_build > /dev/null
125 fi 191 fi
126 emake install DESTDIR="${D}" || die "Make install failed" 192 emake install DESTDIR="${D}" || die "Make install failed"
193 if [[ -d ${WORKDIR}/${PN}_build ]]; then
194 popd > /dev/null
195 fi
196
197 # Manual document installation
198 [[ -n "${DOCS}" ]] && dodoc ${DOCS}
127} 199}
128 200
129# @FUNCTION: cmake-utils_src_test 201# @FUNCTION: cmake-utils_src_test
130# @DESCRIPTION: 202# @DESCRIPTION:
131# Function for testing the package. Automatically detects the build type. 203# Function for testing the package. Automatically detects the build type.
133 debug-print-function $FUNCNAME $* 205 debug-print-function $FUNCNAME $*
134 206
135 # At this point we can automatically check if it's an out-of-source or an 207 # At this point we can automatically check if it's an out-of-source or an
136 # in-source build 208 # in-source build
137 if [[ -d ${WORKDIR}/${PN}_build ]]; then 209 if [[ -d ${WORKDIR}/${PN}_build ]]; then
138 cd "${WORKDIR}"/${PN}_build 210 pushd "${WORKDIR}"/${PN}_build > /dev/null
139 fi 211 fi
140 # Standard implementation of src_test 212 # Standard implementation of src_test
141 if emake -j1 check -n &> /dev/null; then 213 if emake -j1 check -n &> /dev/null; then
142 einfo ">>> Test phase [check]: ${CATEGORY}/${PF}" 214 einfo ">>> Test phase [check]: ${CATEGORY}/${PF}"
143 if ! emake -j1 check; then 215 if ! emake -j1 check; then
149 die "Make test failed. See above for details." 221 die "Make test failed. See above for details."
150 fi 222 fi
151 else 223 else
152 einfo ">>> Test phase [none]: ${CATEGORY}/${PF}" 224 einfo ">>> Test phase [none]: ${CATEGORY}/${PF}"
153 fi 225 fi
226 if [[ -d ${WORKDIR}/${PN}_build ]]; then
227 popd > /dev/null
228 fi
154} 229}

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.13

  ViewVC Help
Powered by ViewVC 1.1.20