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