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

Contents of /eclass/cmake-utils.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.7 - (show annotations) (download)
Sat Mar 29 21:33:17 2008 UTC (6 years, 5 months ago) by philantrop
Branch: MAIN
Changes since 1.6: +3 -3 lines
Added a patch kindly provided by Calchan to enable the use of EXTRA_ECONF with cmake-utils.eclass.

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.6 2008/02/20 14:33:20 zlin 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"
23
24 EXPORT_FUNCTIONS 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_compile
74 # @DESCRIPTION:
75 # General function for compiling with cmake. Default behaviour is to start an
76 # out-of-source build. All arguments are passed to cmake-utils_src_make.
77 cmake-utils_src_compile() {
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 cmake-utils_src_make "$@"
86 }
87
88 # @FUNCTION: cmake-utils_src_configurein
89 # @DESCRIPTION:
90 # Function for software that requires configure and building in the source
91 # directory.
92 cmake-utils_src_configurein() {
93 debug-print-function $FUNCNAME $*
94
95 local cmakeargs="$(_common_configure_code) ${mycmakeargs} ${EXTRA_ECONF}"
96
97 debug-print "$LINENO $ECLASS $FUNCNAME: mycmakeargs is $cmakeargs"
98 cmake ${cmakeargs} . || die "Cmake failed"
99 }
100
101 # @FUNCTION: cmake-utils_src_configureout
102 # @DESCRIPTION:
103 # Function for software that requires configure and building outside the source
104 # tree - default.
105 cmake-utils_src_configureout() {
106 debug-print-function $FUNCNAME $*
107
108 local cmakeargs="$(_common_configure_code) ${mycmakeargs} ${EXTRA_ECONF}"
109 mkdir -p "${WORKDIR}"/${PN}_build
110 pushd "${WORKDIR}"/${PN}_build > /dev/null
111
112 debug-print "$LINENO $ECLASS $FUNCNAME: mycmakeargs is $cmakeargs"
113 cmake ${cmakeargs} "${S}" || die "Cmake failed"
114
115 popd > /dev/null
116 }
117
118 # Internal use only. Common configuration options for all types of builds.
119 _common_configure_code() {
120 local tmp_libdir=$(get_libdir)
121 if has debug ${IUSE//+} && use debug; then
122 echo -DCMAKE_BUILD_TYPE=Debug
123 else
124 echo -DCMAKE_BUILD_TYPE=Release
125 fi
126 echo -DCMAKE_C_COMPILER=$(type -P $(tc-getCC))
127 echo -DCMAKE_CXX_COMPILER=$(type -P $(tc-getCXX))
128 echo -DCMAKE_INSTALL_PREFIX=${PREFIX:-/usr}
129 echo -DLIB_SUFFIX=${tmp_libdir/lib}
130 echo -DLIB_INSTALL_DIR=${PREFIX:-/usr}/${tmp_libdir}
131 [[ -n ${CMAKE_NO_COLOR} ]] && echo -DCMAKE_COLOR_MAKEFILE=OFF
132 }
133
134 # @FUNCTION: cmake-utils_src_make
135 # @DESCRIPTION:
136 # Function for building the package. Automatically detects the build type.
137 # All arguments are passed to emake:
138 # "cmake-utils_src_make -j1" can be used to work around parallel make issues.
139 cmake-utils_src_make() {
140 debug-print-function $FUNCNAME $*
141
142 # At this point we can automatically check if it's an out-of-source or an
143 # in-source build
144 if [[ -d ${WORKDIR}/${PN}_build ]]; then
145 pushd "${WORKDIR}"/${PN}_build > /dev/null
146 fi
147 if ! [[ -z ${CMAKE_COMPILER_VERBOSE} ]]; then
148 emake VERBOSE=1 "$@" || die "Make failed!"
149 else
150 emake "$@" || die "Make failed!"
151 fi
152 if [[ -d ${WORKDIR}/${PN}_build ]]; then
153 popd > /dev/null
154 fi
155 }
156
157 # @FUNCTION: cmake-utils_src_install
158 # @DESCRIPTION:
159 # Function for installing the package. Automatically detects the build type.
160 cmake-utils_src_install() {
161 debug-print-function $FUNCNAME $*
162
163 # At this point we can automatically check if it's an out-of-source or an
164 # in-source build
165 if [[ -d ${WORKDIR}/${PN}_build ]]; then
166 pushd "${WORKDIR}"/${PN}_build > /dev/null
167 fi
168 emake install DESTDIR="${D}" || die "Make install failed"
169 if [[ -d ${WORKDIR}/${PN}_build ]]; then
170 popd > /dev/null
171 fi
172
173 # Manual document installation
174 [[ -n "${DOCS}" ]] && dodoc ${DOCS}
175 }
176
177 # @FUNCTION: cmake-utils_src_test
178 # @DESCRIPTION:
179 # Function for testing the package. Automatically detects the build type.
180 cmake-utils_src_test() {
181 debug-print-function $FUNCNAME $*
182
183 # At this point we can automatically check if it's an out-of-source or an
184 # in-source build
185 if [[ -d ${WORKDIR}/${PN}_build ]]; then
186 pushd "${WORKDIR}"/${PN}_build > /dev/null
187 fi
188 # Standard implementation of src_test
189 if emake -j1 check -n &> /dev/null; then
190 einfo ">>> Test phase [check]: ${CATEGORY}/${PF}"
191 if ! emake -j1 check; then
192 die "Make check failed. See above for details."
193 fi
194 elif emake -j1 test -n &> /dev/null; then
195 einfo ">>> Test phase [test]: ${CATEGORY}/${PF}"
196 if ! emake -j1 test; then
197 die "Make test failed. See above for details."
198 fi
199 else
200 einfo ">>> Test phase [none]: ${CATEGORY}/${PF}"
201 fi
202 if [[ -d ${WORKDIR}/${PN}_build ]]; then
203 popd > /dev/null
204 fi
205 }

  ViewVC Help
Powered by ViewVC 1.1.20