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

Contents of /eclass/cmake-utils.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (show annotations) (download)
Thu Dec 6 20:40:20 2007 UTC (6 years, 10 months ago) by philantrop
Branch: MAIN
Changes since 1.2: +33 -11 lines
Minor enhancements.

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

  ViewVC Help
Powered by ViewVC 1.1.20