summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomas Chvatal <scarabeus@gentoo.org>2009-03-10 23:22:39 +0000
committerTomas Chvatal <scarabeus@gentoo.org>2009-03-10 23:22:39 +0000
commitdcdf02d1a04ebd029e1d3b8656de7f8a63073266 (patch)
treec96602566f53f97bc965894653852be006a5086d /eclass/cmake-utils.eclass
parentBug #257574: ibiblio is no longer carrying Gentoo distfiles. Also remove ftp.... (diff)
downloadhistorical-dcdf02d1a04ebd029e1d3b8656de7f8a63073266.tar.gz
historical-dcdf02d1a04ebd029e1d3b8656de7f8a63073266.tar.bz2
historical-dcdf02d1a04ebd029e1d3b8656de7f8a63073266.zip
Update cmake-utils.eclass new targest, etc. see mail to dev for moar.
Diffstat (limited to 'eclass/cmake-utils.eclass')
-rw-r--r--eclass/cmake-utils.eclass326
1 files changed, 203 insertions, 123 deletions
diff --git a/eclass/cmake-utils.eclass b/eclass/cmake-utils.eclass
index 85d879ebcc37..d1b829a4908d 100644
--- a/eclass/cmake-utils.eclass
+++ b/eclass/cmake-utils.eclass
@@ -1,10 +1,15 @@
# Copyright 1999-2007 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
-# $Header: /var/cvsroot/gentoo-x86/eclass/cmake-utils.eclass,v 1.16 2008/12/24 15:41:06 scarabeus Exp $
+# $Header: /var/cvsroot/gentoo-x86/eclass/cmake-utils.eclass,v 1.17 2009/03/10 23:22:39 scarabeus Exp $
# @ECLASS: cmake-utils.eclass
# @MAINTAINER:
# kde@gentoo.org
+# @AUTHORS:
+# Tomáš Chvátal <scarabeus@gentoo.org>
+# Maciej Mrozowski <reavertm@poczta.fm>
+# (undisclosed contributors)
+# Original author: Zephyrus (zephyrus@mirach.it)
# @BLURB: common ebuild functions for cmake-based packages
# @DESCRIPTION:
# The cmake-utils eclass contains functions that make creating ebuilds for
@@ -13,35 +18,80 @@
# builds and an implementation of the well-known use_enable and use_with
# functions for CMake.
-# Original author: Zephyrus (zephyrus@mirach.it)
-
-inherit toolchain-funcs multilib flag-o-matic
+inherit toolchain-funcs multilib flag-o-matic base
-DESCRIPTION="Based on the ${ECLASS} eclass"
-
-DEPEND=">=dev-util/cmake-2.4.6"
-
-case ${EAPI} in
- 2)
- EXPORT_FUNCTIONS src_configure src_compile src_test src_install
- ;;
- *)
- EXPORT_FUNCTIONS src_compile src_test src_install
+EXPF="src_compile src_test src_install"
+case ${EAPI:-0} in
+ 2) EXPF="${EXPF} src_configure"
;;
+ 1|0) ;;
+ *) die "Unknown EAPI, Bug eclass maintainers." ;;
esac
+EXPORT_FUNCTIONS ${EXPF}
+: ${DESCRIPTION:="Based on the ${ECLASS} eclass"}
-# Internal function use by cmake-utils_use_with and cmake-utils_use_enable
+DEPEND=">=dev-util/cmake-2.4.6-r1"
+
+# Internal functions used by cmake-utils_use_*
_use_me_now() {
- debug-print-function $FUNCNAME $*
+ debug-print-function ${FUNCNAME} "$@"
[[ -z $2 ]] && die "cmake-utils_use-$1 <USE flag> [<flag name>]"
echo "-D$1_${3:-$2}=$(use $2 && echo ON || echo OFF)"
}
+_use_me_now_inverted() {
+ debug-print-function ${FUNCNAME} "$@"
+ [[ -z $2 ]] && die "cmake-utils_use-$1 <USE flag> [<flag name>]"
+ echo "-D$1_${3:-$2}=$(use $2 && echo OFF || echo ON)"
+}
+
+# @ECLASS-VARIABLE: DOCS
+# @DESCRIPTION:
+# Documents passed to dodoc command.
-# @VARIABLE: DOCS
+# @ECLASS-VARIABLE: HTML_DOCS
# @DESCRIPTION:
-# Documents to dodoc
+# Documents passed to dohtml command.
+# @ECLASS-VARIABLE: PREFIX
+# @DESCRIPTION
+# Eclass respects PREFIX variable, though it's not recommended way to set
+# install/lib/bin prefixes.
+# Use -DCMAKE_INSTALL_PREFIX=... CMake variable instead.
+
+# @ECLASS-VARIABLE: CMAKE_IN_SOURCE_BUILD
+# @DESCRIPTION:
+# Set to enable in-source build.
+
+# @ECLASS-VARIABLE: CMAKE_NO_COLOR
+# @DESCRIPTION:
+# Set to disable cmake output coloring.
+
+# @ECLASS-VARIABLE: CMAKE_VERBOSE
+# @DESCRIPTION:
+# Set to enable verbose messages during compilation.
+
+# @ECLASS-VARIABLE: CMAKE_BUILD_TYPE
+# @DESCRIPTION:
+# Set to override default CMAKE_BUILD_TYPE. Only useful for packages
+# known to make use of "if (CMAKE_BUILD_TYPE MATCHES xxx)".
+# If about to be set - needs to be set before invoking cmake-utils_src_configure.
+# You usualy do *NOT* want nor need to set it as it pulls CMake default build-type
+# specific compiler flags overriding make.conf.
+: ${CMAKE_BUILD_TYPE:=Gentoo}
+
+# @FUNCTION: _check_build_dir
+# @DESCRIPTION:
+# Determine using IN or OUT source build
+_check_build_dir() {
+ # in/out source build
+ if [[ -n "${CMAKE_IN_SOURCE_BUILD}" ]]; then
+ CMAKE_BUILD_DIR="${S}"
+ else
+ CMAKE_BUILD_DIR="${WORKDIR}/${PN}_build"
+ fi
+ echo ">>> Working in BUILD_DIR: \"$CMAKE_BUILD_DIR\""
+}
# @FUNCTION: cmake-utils_use_with
# @USAGE: <USE flag> [flag name]
# @DESCRIPTION:
@@ -60,6 +110,24 @@ cmake-utils_use_with() { _use_me_now WITH "$@" ; }
# and -DENABLE_FOO=OFF if it is disabled.
cmake-utils_use_enable() { _use_me_now ENABLE "$@" ; }
+# @FUNCTION: cmake-utils_use_disable
+# @USAGE: <USE flag> [flag name]
+# @DESCRIPTION:
+# Based on inversion of use_enable. See ebuild(5).
+#
+# `cmake-utils_use_enable foo FOO` echoes -DDISABLE_FOO=OFF if foo is enabled
+# and -DDISABLE_FOO=ON if it is disabled.
+cmake-utils_use_disable() { _use_me_now_inverted DISABLE "$@" ; }
+
+# @FUNCTION: cmake-utils_use_no
+# @USAGE: <USE flag> [flag name]
+# @DESCRIPTION:
+# Based on use_disable. See ebuild(5).
+#
+# `cmake-utils_use_no foo FOO` echoes -DNO_FOO=OFF if foo is enabled
+# and -DNO_FOO=ON if it is disabled.
+cmake-utils_use_no() { _use_me_now_inverted NO "$@" ; }
+
# @FUNCTION: cmake-utils_use_want
# @USAGE: <USE flag> [flag name]
# @DESCRIPTION:
@@ -69,168 +137,182 @@ cmake-utils_use_enable() { _use_me_now ENABLE "$@" ; }
# and -DWANT_FOO=OFF if it is disabled.
cmake-utils_use_want() { _use_me_now WANT "$@" ; }
-# @FUNCTION: cmake-utils_has
+# @FUNCTION: cmake-utils_use_build
+# @USAGE: <USE flag> [flag name]
+# @DESCRIPTION:
+# Based on use_enable. See ebuild(5).
+#
+# `cmake-utils_use_build foo FOO` echoes -DBUILD_FOO=ON if foo is enabled
+# and -DBUILD_FOO=OFF if it is disabled.
+cmake-utils_use_build() { _use_me_now BUILD "$@" ; }
+
+# @FUNCTION: cmake-utils_use_has
# @USAGE: <USE flag> [flag name]
# @DESCRIPTION:
# Based on use_enable. See ebuild(5).
#
-# `cmake-utils_has foo FOO` echoes -DHAVE_FOO=ON if foo is enabled
+# `cmake-utils_use_has foo FOO` echoes -DHAVE_FOO=ON if foo is enabled
# and -DHAVE_FOO=OFF if it is disabled.
-cmake-utils_has() { _use_me_now HAVE "$@" ; }
+cmake-utils_use_has() { _use_me_now HAVE "$@" ; }
+
+# @FUNCTION: cmake-utils_has
+# @DESCRIPTION:
+# Deprecated, use cmake-utils_use_has, kept now for backcompat.
+cmake-utils_has() { ewarn "QA: ebuild is using deprecated call. Inform maintainer." ; _use_me_now HAVE "$@" ; }
+
+# @FUNCTION: cmake-utils_use
+# @USAGE: <USE flag> [flag name]
+# @DESCRIPTION:
+# Based on use_enable. See ebuild(5).
+#
+# `cmake-utils_use foo FOO` echoes -DFOO=ON if foo is enabled
+# and -DFOO=OFF if it is disabled.
+cmake-utils_use() { _use_me_now "" "$@" ; }
+
+# Internal function for modifying hardcoded definitions.
+# Removes dangerous definitionts that override Gentoo settings.
+_modify-cmakelists() {
+ debug-print-function ${FUNCNAME} "$@"
+
+ # Comment out all set (<some_should_be_user_defined_variable> value)
+ # TODO Add QA checker - inform when variable being checked for below is set in CMakeLists.txt
+ find "${S}" -name CMakeLists.txt \
+ -exec sed -i -e '/^[[:space:]]*[sS][eE][tT][[:space:]]*([[:space:]]*CMAKE_BUILD_TYPE.*)/{s/^/#IGNORE /g}' {} + \
+ -exec sed -i -e '/^[[:space:]]*[sS][eE][tT][[:space:]]*([[:space:]]*CMAKE_INSTALL_PREFIX.*)/{s/^/#IGNORE /g}' {} + \
+ || die "${LINENO}: failed to disable hardcoded settings"
+
+ # NOTE Append some useful summary here
+ echo '
+MESSAGE(STATUS "<<< Gentoo configuration >>>
+Build type: ${CMAKE_BUILD_TYPE}
+Install path: ${CMAKE_INSTALL_PREFIX}\n")' >> CMakeLists.txt
+}
# @FUNCTION: cmake-utils_src_configure
# @DESCRIPTION:
# General function for configuring with cmake. Default behaviour is to start an
# out-of-source build.
cmake-utils_src_configure() {
- debug-print-function $FUNCNAME $*
+ debug-print-function ${FUNCNAME} "$@"
- if [[ -n "${CMAKE_IN_SOURCE_BUILD}" ]]; then
- cmake-utils_src_configurein
- else
- cmake-utils_src_configureout
+ # Remove dangerous things.
+ _modify-cmakelists
+
+ # @SEE CMAKE_BUILD_TYPE
+ if [[ ${CMAKE_BUILD_TYPE} = Gentoo ]]; then
+ # Handle release builds
+ if ! has debug ${IUSE//+} || ! use debug; then
+ append-cppflags -DNDEBUG
+ fi
fi
+
+ # Prepare Gentoo override rules (set valid compiler, append CPPFLAGS)
+ local build_rules="${TMPDIR}"/gentoo_rules.cmake
+cat > ${build_rules} << _EOF_
+SET (CMAKE_C_COMPILER $(type -P $(tc-getCC)) CACHE FILEPATH "C compiler" FORCE)
+SET (CMAKE_C_COMPILE_OBJECT "<CMAKE_C_COMPILER> <DEFINES> ${CPPFLAGS} <FLAGS> -o <OBJECT> -c <SOURCE>" CACHE STRING "C compile command" FORCE)
+SET (CMAKE_CXX_COMPILER $(type -P $(tc-getCXX)) CACHE FILEPATH "C++ compiler" FORCE)
+SET (CMAKE_CXX_COMPILE_OBJECT "<CMAKE_CXX_COMPILER> <DEFINES> ${CPPFLAGS} <FLAGS> -o <OBJECT> -c <SOURCE>" CACHE STRING "C++ compile command" FORCE)
+_EOF_
+
+ # Common configure parameters (overridable)
+ # NOTE CMAKE_BUILD_TYPE can be only overriden via CMAKE_BUILD_TYPE eclass variable
+ # No -DCMAKE_BUILD_TYPE=xxx definitions will be in effect.
+ local cmakeargs="
+ -DCMAKE_INSTALL_PREFIX=${PREFIX:-/usr}
+ ${mycmakeargs}
+ -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
+ -DCMAKE_INSTALL_DO_STRIP=OFF
+ -DCMAKE_USER_MAKE_RULES_OVERRIDE=${build_rules}"
+
+ # Common configure parameters (invariants)
+ local common_config="${TMPDIR}"/gentoo_common_config.cmake
+ local libdir=$(get_libdir)
+cat > ${common_config} << _EOF_
+SET (LIB_SUFFIX ${libdir/lib} CACHE STRING "library path suffix" FORCE)
+_EOF_
+ [[ -n ${CMAKE_NO_COLOR} ]] && echo 'SET (CMAKE_COLOR_MAKEFILE OFF CACHE BOOL "pretty colors during make" FORCE)' >> ${common_config}
+ cmakeargs="-C ${common_config} ${cmakeargs}"
+
+ _check_build_dir
+ mkdir -p "${CMAKE_BUILD_DIR}"
+ pushd "${CMAKE_BUILD_DIR}" > /dev/null
+ debug-print "${LINENO} ${ECLASS} ${FUNCNAME}: mycmakeargs is $cmakeargs"
+ cmake ${cmakeargs} "${S}" || die "cmake failed"
+
+ popd > /dev/null
}
# @FUNCTION: cmake-utils_src_compile
# @DESCRIPTION:
# General function for compiling with cmake. Default behaviour is to check for
-# eapi and based on it configure or only compile
+# EAPI and respectively to configure as well or just compile.
cmake-utils_src_compile() {
- case ${EAPI} in
- 2)
- ;;
- *)
- cmake-utils_src_configure
- ;;
- esac
+ debug-print-function ${FUNCNAME} "$@"
+ has src_configure ${EXPF} || cmake-utils_src_configure
cmake-utils_src_make "$@"
}
# @FUNCTION: cmake-utils_src_configurein
# @DESCRIPTION:
-# Function for software that requires configure and building in the source
-# directory.
+# Deprecated
cmake-utils_src_configurein() {
- debug-print-function $FUNCNAME $*
-
- _common_configure_code
- local cmakeargs="${mycmakeargs} ${EXTRA_ECONF} -DCMAKE_INSTALL_DO_STRIP=OFF"
-
- debug-print "$LINENO $ECLASS $FUNCNAME: mycmakeargs is $cmakeargs"
- cmake -C "${TMPDIR}/gentoo_common_config.cmake" ${cmakeargs} . || die "Cmake failed"
+ ewarn "QA: This ebuild is using deprecated function call: ${FUNCNAME}"
+ ewarn "QA: Inform ebuild maintainer."
+ cmake-utils_src_configure
}
# @FUNCTION: cmake-utils_src_configureout
# @DESCRIPTION:
-# Function for software that requires configure and building outside the source
-# tree - default.
+# Deprecated
cmake-utils_src_configureout() {
- debug-print-function $FUNCNAME $*
-
- _common_configure_code
- local cmakeargs="${mycmakeargs} ${EXTRA_ECONF} -DCMAKE_INSTALL_DO_STRIP=OFF"
- mkdir -p "${WORKDIR}"/${PN}_build
- pushd "${WORKDIR}"/${PN}_build > /dev/null
-
- debug-print "$LINENO $ECLASS $FUNCNAME: mycmakeargs is $cmakeargs"
- cmake -C "${TMPDIR}/gentoo_common_config.cmake" ${cmakeargs} "${S}" || die "Cmake failed"
-
- popd > /dev/null
-}
-
-# Internal use only. Common configuration options for all types of builds.
-_common_configure_code() {
- local tmp_libdir=$(get_libdir)
- # here we set the compiler explicitly, set install directories prefixes, and
- # make sure that the gentoo user compiler flags trump those set in the
- # program
- local modules_dir=/usr/share/cmake/Modules
- local cxx_create_shared_library=$(sed -n -e 's/)/ CACHE STRING "")/' -e "s/<TARGET_SONAME>/<TARGET_SONAME> ${CXXFLAGS}/" -e '/SET(CMAKE_CXX_CREATE_SHARED_LIBRARY/,/)/p' "${modules_dir}/CMakeCXXInformation.cmake")
- local c_create_shared_library=$(sed -n -e 's/)/ CACHE STRING "")/' -e "s/<TARGET_SONAME>/<TARGET_SONAME> ${CFLAGS}/" -e '/SET(CMAKE_C_CREATE_SHARED_LIBRARY/,/)/p' "${modules_dir}/CMakeCInformation.cmake")
- local c_compile_object=$(sed -n -e 's/)/ CACHE STRING "")/' -e "s/<FLAGS>/<FLAGS> ${CFLAGS}/" -e '/SET(CMAKE_C_COMPILE_OBJECT/,/)/p' "${modules_dir}/CMakeCInformation.cmake")
- local cxx_compile_object=$(sed -n -e 's/)/ CACHE STRING "")/' -e "s/<FLAGS>/<FLAGS> ${CXXFLAGS}/" -e '/SET(CMAKE_CXX_COMPILE_OBJECT/,/)/p' "${modules_dir}/CMakeCXXInformation.cmake")
- local c_link_executable=$(sed -n -e 's/)/ CACHE STRING "")/' -e "s/<FLAGS>/<FLAGS> ${CFLAGS}/" -e "s/<LINK_FLAGS>/<LINK_FLAGS> ${LDFLAGS}/" -e '/SET(CMAKE_C_LINK_EXECUTABLE/,/)/p' "${modules_dir}/CMakeCInformation.cmake")
- local cxx_link_executable=$(sed -n -e 's/)/ CACHE STRING "")/' -e "s/<FLAGS>/<FLAGS> ${CXXFLAGS}/" -e "s/<LINK_FLAGS>/<LINK_FLAGS> ${LDFLAGS}/" -e '/SET(CMAKE_CXX_LINK_EXECUTABLE/,/)/p' "${modules_dir}/CMakeCXXInformation.cmake")
- cat > "${TMPDIR}/gentoo_common_config.cmake" <<_EOF_
-SET(CMAKE_C_COMPILER $(type -P $(tc-getCC)) CACHE STRING "package building C compiler")
-SET(CMAKE_CXX_COMPILER $(type -P $(tc-getCXX)) CACHE STRING "package building C++ compiler")
-${c_create_shared_library}
-${cxx_create_shared_library}
-${c_compile_object}
-${cxx_compile_object}
-${c_link_executable}
-${cxx_link_executable}
-SET(CMAKE_INSTALL_PREFIX ${PREFIX:-/usr} CACHE FILEPATH "install path prefix")
-SET(LIB_SUFFIX ${tmp_libdir/lib} CACHE FILEPATH "library path suffix")
-SET(LIB_INSTALL_DIR ${PREFIX:-/usr}/${tmp_libdir} CACHE FILEPATH "library install directory")
-
-_EOF_
-
- [[ -n ${CMAKE_NO_COLOR} ]] && echo 'SET(CMAKE_COLOR_MAKEFILE OFF CACHE BOOL "pretty colors during make")' >> "${TMPDIR}/gentoo_common_config.cmake"
-
- if has debug ${IUSE//+} && use debug ; then
- echo 'SET(CMAKE_BUILD_TYPE Debug CACHE STRING "determines build settings")' >> "${TMPDIR}/gentoo_common_config.cmake"
- else
- echo 'SET(CMAKE_BUILD_TYPE Release CACHE STRING "determines build settings")' >> "${TMPDIR}/gentoo_common_config.cmake"
- fi
+ ewarn "QA: This ebuild is using deprecated function call: ${FUNCNAME}"
+ ewarn "QA: Inform ebuild maintainer."
+ cmake-utils_src_configure
}
# @FUNCTION: cmake-utils_src_make
# @DESCRIPTION:
# Function for building the package. Automatically detects the build type.
# All arguments are passed to emake:
-# "cmake-utils_src_make -j1" can be used to work around parallel make issues.
cmake-utils_src_make() {
- debug-print-function $FUNCNAME $*
+ debug-print-function ${FUNCNAME} "$@"
- # At this point we can automatically check if it's an out-of-source or an
- # in-source build
- if [[ -d ${WORKDIR}/${PN}_build ]]; then
- pushd "${WORKDIR}"/${PN}_build > /dev/null
- fi
- if ! [[ -z ${CMAKE_COMPILER_VERBOSE} ]]; then
+ _check_build_dir
+ pushd "${CMAKE_BUILD_DIR}" > /dev/null
+ if [[ -n ${CMAKE_VERBOSE} ]]; then
emake VERBOSE=1 "$@" || die "Make failed!"
else
emake "$@" || die "Make failed!"
fi
- if [[ -d ${WORKDIR}/${PN}_build ]]; then
- popd > /dev/null
- fi
+ popd > /dev/null
}
# @FUNCTION: cmake-utils_src_install
# @DESCRIPTION:
# Function for installing the package. Automatically detects the build type.
cmake-utils_src_install() {
- debug-print-function $FUNCNAME $*
+ debug-print-function ${FUNCNAME} "$@"
- # At this point we can automatically check if it's an out-of-source or an
- # in-source build
- if [[ -d ${WORKDIR}/${PN}_build ]]; then
- pushd "${WORKDIR}"/${PN}_build > /dev/null
- fi
+ _check_build_dir
+ pushd "${CMAKE_BUILD_DIR}" > /dev/null
emake install DESTDIR="${D}" || die "Make install failed"
- if [[ -d ${WORKDIR}/${PN}_build ]]; then
- popd > /dev/null
- fi
+ popd > /dev/null
# Manual document installation
- [[ -n "${DOCS}" ]] && dodoc ${DOCS}
+ [[ -n "${DOCS}" ]] && { dodoc ${DOCS} || die "dodoc failed" ; }
+ [[ -n "${HTML_DOCS}" ]] && { dohtml -r ${HTML_DOCS} || die "dohtml failed" ; }
}
# @FUNCTION: cmake-utils_src_test
# @DESCRIPTION:
# Function for testing the package. Automatically detects the build type.
cmake-utils_src_test() {
- debug-print-function $FUNCNAME $*
+ debug-print-function ${FUNCNAME} "$@"
- # At this point we can automatically check if it's an out-of-source or an
- # in-source build
- if [[ -d ${WORKDIR}/${PN}_build ]]; then
- pushd "${WORKDIR}"/${PN}_build > /dev/null
- fi
+ _check_build_dir
+ pushd "${CMAKE_BUILD_DIR}" > /dev/null
# Standard implementation of src_test
if emake -j1 check -n &> /dev/null; then
einfo ">>> Test phase [check]: ${CATEGORY}/${PF}"
@@ -245,7 +327,5 @@ cmake-utils_src_test() {
else
einfo ">>> Test phase [none]: ${CATEGORY}/${PF}"
fi
- if [[ -d ${WORKDIR}/${PN}_build ]]; then
- popd > /dev/null
- fi
+ popd > /dev/null
}