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

Contents of /eclass/cmake-utils.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.5 - (show annotations) (download)
Wed Feb 20 00:35:11 2008 UTC (6 years, 7 months ago) by zlin
Branch: MAIN
Changes since 1.4: +9 -1 lines
Apply DOCS support to cmake-utils.eclass. Patch from Peter Volkov.

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.4 2007/12/13 16:23:59 betelgeuse 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 # @USAGE: DOCS="README ChangeLog"
35 # @DESCRIPTION:
36 # Documents to dodoc
37
38 # @FUNCTION: cmake-utils_use_with
39 # @USAGE: <USE flag> [flag name]
40 # @DESCRIPTION:
41 # Based on use_with. See ebuild(5).
42 #
43 # `cmake-utils_use_with foo FOO` echoes -DWITH_FOO=ON if foo is enabled
44 # and -DWITH_FOO=OFF if it is disabled.
45 cmake-utils_use_with() { _use_me_now WITH "$@" ; }
46
47 # @FUNCTION: cmake-utils_use_enable
48 # @USAGE: <USE flag> [flag name]
49 # @DESCRIPTION:
50 # Based on use_enable. See ebuild(5).
51 #
52 # `cmake-utils_use_enable foo FOO` echoes -DENABLE_FOO=ON if foo is enabled
53 # and -DENABLE_FOO=OFF if it is disabled.
54 cmake-utils_use_enable() { _use_me_now ENABLE "$@" ; }
55
56 # @FUNCTION: cmake-utils_use_want
57 # @USAGE: <USE flag> [flag name]
58 # @DESCRIPTION:
59 # Based on use_enable. See ebuild(5).
60 #
61 # `cmake-utils_use_want foo FOO` echoes -DWANT_FOO=ON if foo is enabled
62 # and -DWANT_FOO=OFF if it is disabled.
63 cmake-utils_use_want() { _use_me_now WANT "$@" ; }
64
65 # @FUNCTION: cmake-utils_has
66 # @USAGE: <USE flag> [flag name]
67 # @DESCRIPTION:
68 # Based on use_enable. See ebuild(5).
69 #
70 # `cmake-utils_has foo FOO` echoes -DHAVE_FOO=ON if foo is enabled
71 # and -DHAVE_FOO=OFF if it is disabled.
72 cmake-utils_has() { _use_me_now HAVE "$@" ; }
73
74 # @FUNCTION: cmake-utils_src_compile
75 # @DESCRIPTION:
76 # General function for compiling with cmake. Default behaviour is to start an
77 # out-of-source build. All arguments are passed to cmake-utils_src_make.
78 cmake-utils_src_compile() {
79 debug-print-function $FUNCNAME $*
80
81 if [[ -n "${CMAKE_IN_SOURCE_BUILD}" ]]; then
82 cmake-utils_src_configurein
83 else
84 cmake-utils_src_configureout
85 fi
86 cmake-utils_src_make "$@"
87 }
88
89 # @FUNCTION: cmake-utils_src_configurein
90 # @DESCRIPTION:
91 # Function for software that requires configure and building in the source
92 # directory.
93 cmake-utils_src_configurein() {
94 debug-print-function $FUNCNAME $*
95
96 local cmakeargs="$(_common_configure_code) ${mycmakeargs}"
97
98 debug-print "$LINENO $ECLASS $FUNCNAME: mycmakeargs is $cmakeargs"
99 cmake ${cmakeargs} . || die "Cmake failed"
100 }
101
102 # @FUNCTION: cmake-utils_src_configureout
103 # @DESCRIPTION:
104 # Function for software that requires configure and building outside the source
105 # tree - default.
106 cmake-utils_src_configureout() {
107 debug-print-function $FUNCNAME $*
108
109 local cmakeargs="$(_common_configure_code) ${mycmakeargs}"
110 mkdir -p "${WORKDIR}"/${PN}_build
111 pushd "${WORKDIR}"/${PN}_build > /dev/null
112
113 debug-print "$LINENO $ECLASS $FUNCNAME: mycmakeargs is $cmakeargs"
114 cmake ${cmakeargs} "${S}" || die "Cmake failed"
115
116 popd > /dev/null
117 }
118
119 # Internal use only. Common configuration options for all types of builds.
120 _common_configure_code() {
121 local tmp_libdir=$(get_libdir)
122 if has debug ${IUSE//+} && use debug; then
123 echo -DCMAKE_BUILD_TYPE=Debug
124 else
125 echo -DCMAKE_BUILD_TYPE=Release
126 fi
127 echo -DCMAKE_C_COMPILER=$(type -P $(tc-getCC))
128 echo -DCMAKE_CXX_COMPILER=$(type -P $(tc-getCXX))
129 echo -DCMAKE_INSTALL_PREFIX=${PREFIX:-/usr}
130 echo -DLIB_SUFFIX=${tmp_libdir/lib}
131 echo -DLIB_INSTALL_DIR=${PREFIX:-/usr}/${tmp_libdir}
132 [[ -n ${CMAKE_NO_COLOR} ]] && echo -DCMAKE_COLOR_MAKEFILE=OFF
133 }
134
135 # @FUNCTION: cmake-utils_src_make
136 # @DESCRIPTION:
137 # Function for building the package. Automatically detects the build type.
138 # All arguments are passed to emake:
139 # "cmake-utils_src_make -j1" can be used to work around parallel make issues.
140 cmake-utils_src_make() {
141 debug-print-function $FUNCNAME $*
142
143 # At this point we can automatically check if it's an out-of-source or an
144 # in-source build
145 if [[ -d ${WORKDIR}/${PN}_build ]]; then
146 pushd "${WORKDIR}"/${PN}_build > /dev/null
147 fi
148 if ! [[ -z ${CMAKE_COMPILER_VERBOSE} ]]; then
149 emake VERBOSE=1 "$@" || die "Make failed!"
150 else
151 emake "$@" || die "Make failed!"
152 fi
153 if [[ -d ${WORKDIR}/${PN}_build ]]; then
154 popd > /dev/null
155 fi
156 }
157
158 # @FUNCTION: cmake-utils_src_install
159 # @DESCRIPTION:
160 # Function for installing the package. Automatically detects the build type.
161 cmake-utils_src_install() {
162 debug-print-function $FUNCNAME $*
163
164 # At this point we can automatically check if it's an out-of-source or an
165 # in-source build
166 if [[ -d ${WORKDIR}/${PN}_build ]]; then
167 pushd "${WORKDIR}"/${PN}_build > /dev/null
168 fi
169 emake install DESTDIR="${D}" || die "Make install failed"
170 if [[ -d ${WORKDIR}/${PN}_build ]]; then
171 popd > /dev/null
172 fi
173
174 # Manual document installation
175 [[ -n "${DOCS}" ]] && dodoc ${DOCS}
176 }
177
178 # @FUNCTION: cmake-utils_src_test
179 # @DESCRIPTION:
180 # Function for testing the package. Automatically detects the build type.
181 cmake-utils_src_test() {
182 debug-print-function $FUNCNAME $*
183
184 # At this point we can automatically check if it's an out-of-source or an
185 # in-source build
186 if [[ -d ${WORKDIR}/${PN}_build ]]; then
187 pushd "${WORKDIR}"/${PN}_build > /dev/null
188 fi
189 # Standard implementation of src_test
190 if emake -j1 check -n &> /dev/null; then
191 einfo ">>> Test phase [check]: ${CATEGORY}/${PF}"
192 if ! emake -j1 check; then
193 die "Make check failed. See above for details."
194 fi
195 elif emake -j1 test -n &> /dev/null; then
196 einfo ">>> Test phase [test]: ${CATEGORY}/${PF}"
197 if ! emake -j1 test; then
198 die "Make test failed. See above for details."
199 fi
200 else
201 einfo ">>> Test phase [none]: ${CATEGORY}/${PF}"
202 fi
203 if [[ -d ${WORKDIR}/${PN}_build ]]; then
204 popd > /dev/null
205 fi
206 }

  ViewVC Help
Powered by ViewVC 1.1.20