public inbox for gentoo-dev@lists.gentoo.org
 help / color / mirror / Atom feed
From: Krzysiek Pawlik <nelchael@gentoo.org>
To: gentoo-dev@lists.gentoo.org
Subject: Re: [gentoo-dev] RFC: cmake.eclass
Date: Sun, 04 Nov 2007 13:34:27 +0100	[thread overview]
Message-ID: <472DBC53.6080507@gentoo.org> (raw)
In-Reply-To: <20071104121243.GN30328@supernova>


[-- Attachment #1.1: Type: text/plain, Size: 1444 bytes --]

Donnie Berkholz wrote:
>> I've wrote an eclass that makes writing ebuilds for such packages a little
>> easier - it provides an ecmake function that takes care of few needed variables,
>> prefix and such.
> 
> Great! When's the scons one coming? =)

I don't know scons ;)

>> #
>> # Original Author: nelchael
>> # Purpose: Automate src_install and src_compile for packages using cmake
>> #
> 
> This would be a great opportunity to start using real eclass 
> documentation (e.g. that found in eutils.eclass) so we can autogenerate 
> a useful manpage on how to use it.

Done.

>> # If you want to build in source tree set CMAKE_IN_SOURCE_BUILD to anything:
>> [[ -n "${CMAKE_IN_SOURCE_BUILD}" ]] && CMAKE_BUILD_DIR="${S}"
> 
> Why would I want to do that? Some documentation would help.

Added: some packages refuse to build out of source, so it may be needed in some
cases.

>> function ecmake() {
> 
> Why are some functions declared with 'function' and others not?

Fixed: added '^function '

>> 		-DCMAKE_CXX_COMPILER="$(type -P $(tc-getCXX))" \
> 
> Why the 'type -P' bit?

To get the full path to $CC and $CXX

>> 	make DESTDIR="${D}" install || die "make install failed"
> 
> Does emake work?

It should -> fixed.

Attached is new version and a diff to previous.

-- 
Krzysiek Pawlik   <nelchael at gentoo.org>   key id: 0xBC555551
desktop-misc, desktop-dock, x86, java, apache, ppc...

[-- Attachment #1.2: cmake.eclass --]
[-- Type: text/plain, Size: 2553 bytes --]

# Copyright 1999-2007 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $

# @ECLASS: cmake.eclass
# @MAINTAINER:
# nelchael@gentoo.org
# @BLURB: wrap cmake
# @DESCRIPTION:
# The cmake eclass contains functions wrapping cmake to ease its usage in
# ebuilds. It allows both out of source and in source builds.

inherit toolchain-funcs multilib

EXPORT_FUNCTIONS src_compile src_install

DEPEND="${DEPEND}
	>=dev-util/cmake-2.4.6-r1"

CMAKE_BUILD_DIR="${WORKDIR}/cmake-build"

# Some packages don't build out of source, so if you want to build in source
# tree set CMAKE_IN_SOURCE_BUILD to anything before inheriting cmake.eclass:
[[ -n "${CMAKE_IN_SOURCE_BUILD}" ]] && CMAKE_BUILD_DIR="${S}"

# @FUNCTION: prepare_build_dir
# @USAGE:
# @DESCRIPTION:
# Create the build directory if it doesn't exist, this function should not be
# used outside of this eclass.
function prepare_build_dir() {

	if [[ ! -d "${CMAKE_BUILD_DIR}" ]]; then
		mkdir -p "${CMAKE_BUILD_DIR}" \
			|| die "mkdir \"${CMAKE_BUILD_DIR}\" failed"
	fi

}

# @FUNCTION: ecmake
# @USAGE:
# @DESCRIPTION:
# Run cmake to prepare makefiles, also prepares the build directory.
function ecmake() {

	prepare_build_dir

	pushd "${CMAKE_BUILD_DIR}" > /dev/null

	[[ -n "${CMAKE_VERBOSE}" ]] && \
		CMAKE_FLAGS="-DCMAKE_VERBOSE_MAKEFILE=1 ${CMAKE_FLAGS}"

	echo "cmake -DCMAKE_CXX_COMPILER=\"$(type -P $(tc-getCXX))\" -DCMAKE_CXX_FLAGS=\"${CXXFLAGS}\" -DCMAKE_C_COMPILER=\"$(type -P $(tc-getCC))\" -DCMAKE_C_FLAGS=\"${CFLAGS}\" -DCMAKE_INSTALL_PREFIX=\"/usr\" -DLIB_INSTALL_DIR=\"/usr/$(get_libdir)\" \"${S}\" ${CMAKE_FLAGS}"

	/usr/bin/cmake \
		-DCMAKE_CXX_COMPILER="$(type -P $(tc-getCXX))" \
		-DCMAKE_CXX_FLAGS="${CXXFLAGS}" \
		-DCMAKE_C_COMPILER="$(type -P $(tc-getCC))" \
		-DCMAKE_C_FLAGS="${CFLAGS}" \
		-DCMAKE_INSTALL_PREFIX="/usr" \
		-DLIB_INSTALL_DIR="/usr/$(get_libdir)" \
		${CMAKE_FLAGS} \
		"${S}" || die "cmake failed"

	popd > /dev/null

}

# @FUNCTION: cmake_src_compile
# @USAGE: <make arguments>
# @DESCRIPTION:
# Default src_compile for ebuilds using cmake, runs `ecmake' and then `emake'.
function cmake_src_compile() {

	ecmake

	pushd "${CMAKE_BUILD_DIR}" > /dev/null
	emake ${@} || die "emake failed"
	popd > /dev/null

}

# @FUNCTION: cmake_src_install
# @USAGE:
# @DESCRIPTION:
# Default src_install for ebuilds using cmake, runs `emake install' in build
# directory.
function cmake_src_install() {

	pushd "${CMAKE_BUILD_DIR}" > /dev/null
	emake DESTDIR="${D}" install || die "make install failed"
	popd > /dev/null

}

[-- Attachment #1.3: cmake.eclass.diff --]
[-- Type: text/plain, Size: 2455 bytes --]

Index: cmake.eclass
===================================================================
--- cmake.eclass	(revision 285)
+++ cmake.eclass	(working copy)
@@ -2,10 +2,13 @@
 # Distributed under the terms of the GNU General Public License v2
 # $Header: $
 
-#
-# Original Author: nelchael
-# Purpose: Automate src_install and src_compile for packages using cmake
-#
+# @ECLASS: cmake.eclass
+# @MAINTAINER:
+# nelchael@gentoo.org
+# @BLURB: wrap cmake
+# @DESCRIPTION:
+# The cmake eclass contains functions wrapping cmake to ease its usage in
+# ebuilds. It allows both out of source and in source builds.
 
 inherit toolchain-funcs multilib
 
@@ -16,13 +19,15 @@
 
 CMAKE_BUILD_DIR="${WORKDIR}/cmake-build"
 
-# If you want to build in source tree set CMAKE_IN_SOURCE_BUILD to anything:
+# Some packages don't build out of source, so if you want to build in source
+# tree set CMAKE_IN_SOURCE_BUILD to anything before inheriting cmake.eclass:
 [[ -n "${CMAKE_IN_SOURCE_BUILD}" ]] && CMAKE_BUILD_DIR="${S}"
 
-#
-# Prepare CMAKE_BUILD_DIR:
-#	- create the directory if it's missing
-#
+# @FUNCTION: prepare_build_dir
+# @USAGE:
+# @DESCRIPTION:
+# Create the build directory if it doesn't exist, this function should not be
+# used outside of this eclass.
 function prepare_build_dir() {
 
 	if [[ ! -d "${CMAKE_BUILD_DIR}" ]]; then
@@ -32,11 +37,10 @@
 
 }
 
-#
-# Run cmake with some needed defines.
-# If you want to add something use CMAKE_FLAGS.
-# If you want verbose makefile set CMAKE_VERBOSE to anything.
-#
+# @FUNCTION: ecmake
+# @USAGE:
+# @DESCRIPTION:
+# Run cmake to prepare makefiles, also prepares the build directory.
 function ecmake() {
 
 	prepare_build_dir
@@ -62,10 +66,11 @@
 
 }
 
-#
-# Run `ecmake' and default make target.
-#
-cmake_src_compile() {
+# @FUNCTION: cmake_src_compile
+# @USAGE: <make arguments>
+# @DESCRIPTION:
+# Default src_compile for ebuilds using cmake, runs `ecmake' and then `emake'.
+function cmake_src_compile() {
 
 	ecmake
 
@@ -75,13 +80,15 @@
 
 }
 
-#
-# Change to build directory and run `make install'.
-#
-cmake_src_install() {
+# @FUNCTION: cmake_src_install
+# @USAGE:
+# @DESCRIPTION:
+# Default src_install for ebuilds using cmake, runs `emake install' in build
+# directory.
+function cmake_src_install() {
 
 	pushd "${CMAKE_BUILD_DIR}" > /dev/null
-	make DESTDIR="${D}" install || die "make install failed"
+	emake DESTDIR="${D}" install || die "make install failed"
 	popd > /dev/null
 
 }

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 252 bytes --]

  reply	other threads:[~2007-11-04 12:37 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-11-04 11:51 [gentoo-dev] RFC: cmake.eclass Krzysiek Pawlik
2007-11-04 12:12 ` Donnie Berkholz
2007-11-04 12:34   ` Krzysiek Pawlik [this message]
     [not found] ` <200711041420.38049.philantrop@gentoo.org>
2007-11-04 13:30   ` Krzysiek Pawlik
2007-11-04 14:09     ` Krzysiek Pawlik
2007-11-04 14:35       ` Wulf C. Krueger
2007-11-04 14:01 ` Marijn Schouten (hkBst)
2007-11-04 14:07   ` Krzysiek Pawlik

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=472DBC53.6080507@gentoo.org \
    --to=nelchael@gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox