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