/[gentoo-x86]/eclass/cmake-utils.eclass
Gentoo

Contents of /eclass/cmake-utils.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.9 - (show annotations) (download)
Sun Sep 28 16:19:06 2008 UTC (6 years, 1 month ago) by jmbsvicetto
Branch: MAIN
Changes since 1.8: +21 -6 lines
Applied fixes to the cmake-utils eclass to support EAPI-2. Thanks to Tomas Chvatal (scarabeus) for the patch.

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

  ViewVC Help
Powered by ViewVC 1.1.20