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