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

Contents of /eclass/cmake-utils.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (hide annotations) (download)
Sun Nov 4 13:17:35 2007 UTC (6 years, 10 months ago) by philantrop
Branch: MAIN
New cmake-utils.eclass providing functions for the cmake build system with all requested fixes after the review on gentoo-dev.

1 philantrop 1.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.sh
37     cmake-utils_use_with() { _use_me_now WITH "$@" ; }
38    
39     # @FUNCTION: cmake-utils_use_enable
40     # @USAGE: <USE flag> [flag name]
41     # @DESCRIPTION:
42     # Based on use_enable. See ebuild.sh
43     cmake-utils_use_enable() { _use_me_now ENABLE "$@" ; }
44    
45     # @FUNCTION: cmake-utils_src_compile
46     # @DESCRIPTION:
47     # General function for compiling with cmake. Default behaviour is to start an
48     # out-of-source build
49     cmake-utils_src_compile() {
50     debug-print-function $FUNCNAME $*
51    
52     cmake-utils_src_configureout
53     cmake-utils_src_make
54     }
55    
56     # @FUNCTION: cmake-utils_src_configurein
57     # @DESCRIPTION:
58     # Function for software that requires configure and building in the source
59     # directory.
60     cmake-utils_src_configurein() {
61     debug-print-function $FUNCNAME $*
62    
63     local cmakeargs="${mycmakeargs} $(_common_configure_code)"
64    
65     debug-print "$LINENO $ECLASS $FUNCNAME: mycmakeargs is $cmakeargs"
66     cmake ${cmakeargs} . || die "Cmake failed"
67     }
68    
69     # @FUNCTION: cmake-utils_src_configureout
70     # @DESCRIPTION:
71     # Function for software that requires configure and building outside the source
72     # tree - default.
73     cmake-utils_src_configureout() {
74     debug-print-function $FUNCNAME $*
75    
76     local cmakeargs="${mycmakeargs} $(_common_configure_code)"
77     mkdir "${WORKDIR}"/${PN}_build
78     cd "${WORKDIR}"/${PN}_build
79    
80     debug-print "$LINENO $ECLASS $FUNCNAME: mycmakeargs is $cmakeargs"
81     cmake ${cmakeargs} "${S}" || die "Cmake failed"
82     }
83    
84     # Internal use only. Common configuration options for all types of builds.
85     _common_configure_code() {
86     local tmp_libdir=$(get_libdir)
87     if has debug ${IUSE} && use debug; then
88     echo -DCMAKE_BUILD_TYPE=debug
89     fi
90     echo -DCMAKE_C_COMPILER=$(type -P $(tc-getCC))
91     echo -DCMAKE_CXX_COMPILER=$(type -P $(tc-getCXX))
92     echo -DCMAKE_INSTALL_PREFIX=${PREFIX:-/usr}
93     echo -DLIB_SUFFIX=${tmp_libdir/lib}
94     [[ -n ${CMAKE_NO_COLOR} ]] && echo -DCMAKE_COLOR_MAKEFILE=OFF
95     }
96    
97     # @FUNCTION: cmake-utils_src_make
98     # @DESCRIPTION:
99     # Function for building the package. Automatically detects the build type.
100     cmake-utils_src_make() {
101     debug-print-function $FUNCNAME $*
102    
103     # At this point we can automatically check if it's an out-of-source or an
104     # in-source build
105     if [[ -d ${WORKDIR}/${PN}_build ]]; then
106     cd "${WORKDIR}"/${PN}_build;
107     fi
108     if ! [[ -z ${CMAKE_COMPILER_VERBOSE} ]]; then
109     emake VERBOSE=1 || die "Make failed!";
110     else
111     emake || die "Make failed!";
112     fi
113     }
114    
115     # @FUNCTION: cmake-utils_src_install
116     # @DESCRIPTION:
117     # Function for installing the package. Automatically detects the build type.
118     cmake-utils_src_install() {
119     debug-print-function $FUNCNAME $*
120    
121     # At this point we can automatically check if it's an out-of-source or an
122     # in-source build
123     if [[ -d ${WORKDIR}/${PN}_build ]]; then
124     cd "${WORKDIR}"/${PN}_build;
125     fi
126     emake install DESTDIR="${D}" || die "Make install failed"
127     }
128    
129     # @FUNCTION: cmake-utils_src_test
130     # @DESCRIPTION:
131     # Function for testing the package. Automatically detects the build type.
132     cmake-utils_src_test() {
133     debug-print-function $FUNCNAME $*
134    
135     # At this point we can automatically check if it's an out-of-source or an
136     # in-source build
137     if [[ -d ${WORKDIR}/${PN}_build ]]; then
138     cd "${WORKDIR}"/${PN}_build
139     fi
140     # Standard implementation of src_test
141     if emake -j1 check -n &> /dev/null; then
142     einfo ">>> Test phase [check]: ${CATEGORY}/${PF}"
143     if ! emake -j1 check; then
144     die "Make check failed. See above for details."
145     fi
146     elif emake -j1 test -n &> /dev/null; then
147     einfo ">>> Test phase [test]: ${CATEGORY}/${PF}"
148     if ! emake -j1 test; then
149     die "Make test failed. See above for details."
150     fi
151     else
152     einfo ">>> Test phase [none]: ${CATEGORY}/${PF}"
153     fi
154     }

  ViewVC Help
Powered by ViewVC 1.1.20