| 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.6 2008/02/20 14:33:20 zlin Exp $ |
3 | # $Header: /var/cvsroot/gentoo-x86/eclass/cmake-utils.eclass,v 1.12 2008/10/27 05:36:02 vapier 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 |
| … | |
… | |
| 17 | |
17 | |
| 18 | inherit toolchain-funcs multilib |
18 | inherit toolchain-funcs multilib |
| 19 | |
19 | |
| 20 | DESCRIPTION="Based on the ${ECLASS} eclass" |
20 | DESCRIPTION="Based on the ${ECLASS} eclass" |
| 21 | |
21 | |
| 22 | DEPEND="dev-util/cmake" |
22 | DEPEND=">=dev-util/cmake-2.4.6" |
| 23 | |
23 | |
|
|
24 | case ${EAPI} in |
|
|
25 | 2) |
|
|
26 | EXPORT_FUNCTIONS src_configure src_compile src_test src_install |
|
|
27 | ;; |
|
|
28 | *) |
| 24 | EXPORT_FUNCTIONS src_compile src_test src_install |
29 | EXPORT_FUNCTIONS src_compile src_test src_install |
|
|
30 | ;; |
|
|
31 | esac |
|
|
32 | |
| 25 | |
33 | |
| 26 | # Internal function use by cmake-utils_use_with and cmake-utils_use_enable |
34 | # Internal function use by cmake-utils_use_with and cmake-utils_use_enable |
| 27 | _use_me_now() { |
35 | _use_me_now() { |
| 28 | debug-print-function $FUNCNAME $* |
36 | debug-print-function $FUNCNAME $* |
| 29 | [[ -z $2 ]] && die "cmake-utils_use-$1 <USE flag> [<flag name>]" |
37 | [[ -z $2 ]] && die "cmake-utils_use-$1 <USE flag> [<flag name>]" |
| … | |
… | |
| 68 | # |
76 | # |
| 69 | # `cmake-utils_has foo FOO` echoes -DHAVE_FOO=ON if foo is enabled |
77 | # `cmake-utils_has foo FOO` echoes -DHAVE_FOO=ON if foo is enabled |
| 70 | # and -DHAVE_FOO=OFF if it is disabled. |
78 | # and -DHAVE_FOO=OFF if it is disabled. |
| 71 | cmake-utils_has() { _use_me_now HAVE "$@" ; } |
79 | cmake-utils_has() { _use_me_now HAVE "$@" ; } |
| 72 | |
80 | |
| 73 | # @FUNCTION: cmake-utils_src_compile |
81 | # @FUNCTION: cmake-utils_src_configure |
| 74 | # @DESCRIPTION: |
82 | # @DESCRIPTION: |
| 75 | # General function for compiling with cmake. Default behaviour is to start an |
83 | # General function for configuring with cmake. Default behaviour is to start an |
| 76 | # out-of-source build. All arguments are passed to cmake-utils_src_make. |
84 | # out-of-source build. |
| 77 | cmake-utils_src_compile() { |
85 | cmake-utils_src_configure() { |
| 78 | debug-print-function $FUNCNAME $* |
86 | debug-print-function $FUNCNAME $* |
|
|
87 | |
|
|
88 | if ! has debug ${IUSE//+} || ! use debug ; then |
|
|
89 | append-cppflags -DNDEBUG |
|
|
90 | fi |
| 79 | |
91 | |
| 80 | if [[ -n "${CMAKE_IN_SOURCE_BUILD}" ]]; then |
92 | if [[ -n "${CMAKE_IN_SOURCE_BUILD}" ]]; then |
| 81 | cmake-utils_src_configurein |
93 | cmake-utils_src_configurein |
| 82 | else |
94 | else |
| 83 | cmake-utils_src_configureout |
95 | cmake-utils_src_configureout |
| 84 | fi |
96 | fi |
|
|
97 | } |
|
|
98 | |
|
|
99 | # @FUNCTION: cmake-utils_src_compile |
|
|
100 | # @DESCRIPTION: |
|
|
101 | # General function for compiling with cmake. Default behaviour is to check for |
|
|
102 | # eapi and based on it configure or only compile |
|
|
103 | cmake-utils_src_compile() { |
|
|
104 | case ${EAPI} in |
|
|
105 | 2) |
|
|
106 | ;; |
|
|
107 | *) |
|
|
108 | cmake-utils_src_configure |
|
|
109 | ;; |
|
|
110 | esac |
|
|
111 | |
| 85 | cmake-utils_src_make "$@" |
112 | cmake-utils_src_make "$@" |
| 86 | } |
113 | } |
| 87 | |
114 | |
| 88 | # @FUNCTION: cmake-utils_src_configurein |
115 | # @FUNCTION: cmake-utils_src_configurein |
| 89 | # @DESCRIPTION: |
116 | # @DESCRIPTION: |
| 90 | # Function for software that requires configure and building in the source |
117 | # Function for software that requires configure and building in the source |
| 91 | # directory. |
118 | # directory. |
| 92 | cmake-utils_src_configurein() { |
119 | cmake-utils_src_configurein() { |
| 93 | debug-print-function $FUNCNAME $* |
120 | debug-print-function $FUNCNAME $* |
| 94 | |
121 | |
| 95 | local cmakeargs="$(_common_configure_code) ${mycmakeargs}" |
122 | local cmakeargs="$(_common_configure_code) ${mycmakeargs} ${EXTRA_ECONF}" |
| 96 | |
123 | |
| 97 | debug-print "$LINENO $ECLASS $FUNCNAME: mycmakeargs is $cmakeargs" |
124 | debug-print "$LINENO $ECLASS $FUNCNAME: mycmakeargs is $cmakeargs" |
| 98 | cmake ${cmakeargs} . || die "Cmake failed" |
125 | cmake ${cmakeargs} . || die "Cmake failed" |
| 99 | } |
126 | } |
| 100 | |
127 | |
| … | |
… | |
| 103 | # Function for software that requires configure and building outside the source |
130 | # Function for software that requires configure and building outside the source |
| 104 | # tree - default. |
131 | # tree - default. |
| 105 | cmake-utils_src_configureout() { |
132 | cmake-utils_src_configureout() { |
| 106 | debug-print-function $FUNCNAME $* |
133 | debug-print-function $FUNCNAME $* |
| 107 | |
134 | |
| 108 | local cmakeargs="$(_common_configure_code) ${mycmakeargs}" |
135 | local cmakeargs="$(_common_configure_code) ${mycmakeargs} ${EXTRA_ECONF}" |
| 109 | mkdir -p "${WORKDIR}"/${PN}_build |
136 | mkdir -p "${WORKDIR}"/${PN}_build |
| 110 | pushd "${WORKDIR}"/${PN}_build > /dev/null |
137 | pushd "${WORKDIR}"/${PN}_build > /dev/null |
| 111 | |
138 | |
| 112 | debug-print "$LINENO $ECLASS $FUNCNAME: mycmakeargs is $cmakeargs" |
139 | debug-print "$LINENO $ECLASS $FUNCNAME: mycmakeargs is $cmakeargs" |
| 113 | cmake ${cmakeargs} "${S}" || die "Cmake failed" |
140 | cmake ${cmakeargs} "${S}" || die "Cmake failed" |
| … | |
… | |
| 116 | } |
143 | } |
| 117 | |
144 | |
| 118 | # Internal use only. Common configuration options for all types of builds. |
145 | # Internal use only. Common configuration options for all types of builds. |
| 119 | _common_configure_code() { |
146 | _common_configure_code() { |
| 120 | local tmp_libdir=$(get_libdir) |
147 | local tmp_libdir=$(get_libdir) |
| 121 | if has debug ${IUSE//+} && use debug; then |
148 | # CMAKE_BUILD_TYPE only modifies compiler flags, so set to None |
| 122 | echo -DCMAKE_BUILD_TYPE=Debug |
149 | echo -DCMAKE_BUILD_TYPE=None |
| 123 | else |
|
|
| 124 | echo -DCMAKE_BUILD_TYPE=Release |
|
|
| 125 | fi |
|
|
| 126 | echo -DCMAKE_C_COMPILER=$(type -P $(tc-getCC)) |
150 | echo -DCMAKE_C_COMPILER=$(type -P $(tc-getCC)) |
| 127 | echo -DCMAKE_CXX_COMPILER=$(type -P $(tc-getCXX)) |
151 | echo -DCMAKE_CXX_COMPILER=$(type -P $(tc-getCXX)) |
| 128 | echo -DCMAKE_INSTALL_PREFIX=${PREFIX:-/usr} |
152 | echo -DCMAKE_INSTALL_PREFIX=${PREFIX:-/usr} |
| 129 | echo -DLIB_SUFFIX=${tmp_libdir/lib} |
153 | echo -DLIB_SUFFIX=${tmp_libdir/lib} |
| 130 | echo -DLIB_INSTALL_DIR=${PREFIX:-/usr}/${tmp_libdir} |
154 | echo -DLIB_INSTALL_DIR=${PREFIX:-/usr}/${tmp_libdir} |