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

Diff of /eclass/cmake-utils.eclass

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.3 Revision 1.16
1# Copyright 1999-2007 Gentoo Foundation 1# Copyright 1999-2007 Gentoo Foundation
2# Distributed under the terms of the GNU General Public License v2 2# Distributed under the terms of the GNU General Public License v2
3# $Header: /var/cvsroot/gentoo-x86/eclass/cmake-utils.eclass,v 1.3 2007/12/06 20:40:20 philantrop Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/cmake-utils.eclass,v 1.16 2008/12/24 15:41:06 scarabeus Exp $
4 4
5# @ECLASS: cmake-utils.eclass 5# @ECLASS: cmake-utils.eclass
6# @MAINTAINER: 6# @MAINTAINER:
7# kde@gentoo.org 7# kde@gentoo.org
8# @BLURB: common ebuild functions for cmake-based packages 8# @BLURB: common ebuild functions for cmake-based packages
13# builds and an implementation of the well-known use_enable and use_with 13# builds and an implementation of the well-known use_enable and use_with
14# functions for CMake. 14# functions for CMake.
15 15
16# Original author: Zephyrus (zephyrus@mirach.it) 16# Original author: Zephyrus (zephyrus@mirach.it)
17 17
18inherit toolchain-funcs multilib 18inherit toolchain-funcs multilib flag-o-matic
19 19
20DESCRIPTION="Based on the ${ECLASS} eclass" 20DESCRIPTION="Based on the ${ECLASS} eclass"
21 21
22DEPEND="dev-util/cmake" 22DEPEND=">=dev-util/cmake-2.4.6"
23 23
24case ${EAPI} in
25 2)
26 EXPORT_FUNCTIONS src_configure src_compile src_test src_install
27 ;;
28 *)
24EXPORT_FUNCTIONS src_compile src_test src_install 29 EXPORT_FUNCTIONS src_compile src_test src_install
30 ;;
31esac
32
25 33
26# Internal function use by cmake-utils_use_with and cmake-utils_use_enable 34# Internal function use by cmake-utils_use_with and cmake-utils_use_enable
27_use_me_now() { 35_use_me_now() {
28 debug-print-function $FUNCNAME $* 36 debug-print-function $FUNCNAME $*
29 [[ -z $2 ]] && die "cmake-utils_use-$1 <USE flag> [<flag name>]" 37 [[ -z $2 ]] && die "cmake-utils_use-$1 <USE flag> [<flag name>]"
30 echo "-D$1_${3:-$2}=$(use $2 && echo ON || echo OFF)" 38 echo "-D$1_${3:-$2}=$(use $2 && echo ON || echo OFF)"
31} 39}
32 40
41# @VARIABLE: DOCS
42# @DESCRIPTION:
43# Documents to dodoc
44
33# @FUNCTION: cmake-utils_use_with 45# @FUNCTION: cmake-utils_use_with
34# @USAGE: <USE flag> [flag name] 46# @USAGE: <USE flag> [flag name]
35# @DESCRIPTION: 47# @DESCRIPTION:
36# Based on use_with. See ebuild(5). 48# Based on use_with. See ebuild(5).
37# 49#
38# `cmake-utils_use_with foo FOO` echoes -DWITH_FOO=ON if foo is enabled 50# `cmake-utils_use_with foo FOO` echoes -DWITH_FOO=ON if foo is enabled
39# and -DWITH_FOO=OFF if it is disabled. 51# and -DWITH_FOO=OFF if it is disabled.
40cmake-utils_use_with() { _use_me_now WITH "$@" ; } 52cmake-utils_use_with() { _use_me_now WITH "$@" ; }
41 53
42# @FUNCTION: cmake-utils_use_enable 54# @FUNCTION: cmake-utils_use_enable
43# @USAGE: <USE flag> [flag name] 55# @USAGE: <USE flag> [flag name]
44# @DESCRIPTION: 56# @DESCRIPTION:
45# Based on use_enable. See ebuild(5). 57# Based on use_enable. See ebuild(5).
46# 58#
47# `cmake-utils_use_enable foo FOO` echoes -DENABLE_FOO=ON if foo is enabled 59# `cmake-utils_use_enable foo FOO` echoes -DENABLE_FOO=ON if foo is enabled
48# and -DENABLE_FOO=OFF if it is disabled. 60# and -DENABLE_FOO=OFF if it is disabled.
49cmake-utils_use_enable() { _use_me_now ENABLE "$@" ; } 61cmake-utils_use_enable() { _use_me_now ENABLE "$@" ; }
50 62
51# @FUNCTION: cmake-utils_use_want 63# @FUNCTION: cmake-utils_use_want
52# @USAGE: <USE flag> [flag name] 64# @USAGE: <USE flag> [flag name]
53# @DESCRIPTION: 65# @DESCRIPTION:
54# Based on use_enable. See ebuild(5). 66# Based on use_enable. See ebuild(5).
55# 67#
56# `cmake-utils_use_want foo FOO` echoes -DWANT_FOO=ON if foo is enabled 68# `cmake-utils_use_want foo FOO` echoes -DWANT_FOO=ON if foo is enabled
57# and -DWANT_FOO=OFF if it is disabled. 69# and -DWANT_FOO=OFF if it is disabled.
58cmake-utils_use_want() { _use_me_now WANT "$@" ; } 70cmake-utils_use_want() { _use_me_now WANT "$@" ; }
59 71
60# @FUNCTION: cmake-utils_has 72# @FUNCTION: cmake-utils_has
61# @USAGE: <USE flag> [flag name] 73# @USAGE: <USE flag> [flag name]
62# @DESCRIPTION: 74# @DESCRIPTION:
63# Based on use_enable. See ebuild(5). 75# Based on use_enable. See ebuild(5).
64# 76#
65# `cmake-utils_has foo FOO` echoes -DHAVE_FOO=ON if foo is enabled 77# `cmake-utils_has foo FOO` echoes -DHAVE_FOO=ON if foo is enabled
66# and -DHAVE_FOO=OFF if it is disabled. 78# and -DHAVE_FOO=OFF if it is disabled.
67cmake-utils_has() { _use_me_now HAVE "$@" ; } 79cmake-utils_has() { _use_me_now HAVE "$@" ; }
68 80
69# @FUNCTION: cmake-utils_src_compile 81# @FUNCTION: cmake-utils_src_configure
70# @DESCRIPTION: 82# @DESCRIPTION:
71# General function for compiling with cmake. Default behaviour is to start an 83# General function for configuring with cmake. Default behaviour is to start an
72# out-of-source build. All arguments are passed to cmake-utils_src_make. 84# out-of-source build.
73cmake-utils_src_compile() { 85cmake-utils_src_configure() {
74 debug-print-function $FUNCNAME $* 86 debug-print-function $FUNCNAME $*
75 87
76 if [[ -n "${CMAKE_IN_SOURCE_BUILD}" ]]; then 88 if [[ -n "${CMAKE_IN_SOURCE_BUILD}" ]]; then
77 cmake-utils_src_configurein 89 cmake-utils_src_configurein
78 else 90 else
79 cmake-utils_src_configureout 91 cmake-utils_src_configureout
80 fi 92 fi
93}
94
95# @FUNCTION: cmake-utils_src_compile
96# @DESCRIPTION:
97# General function for compiling with cmake. Default behaviour is to check for
98# eapi and based on it configure or only compile
99cmake-utils_src_compile() {
100 case ${EAPI} in
101 2)
102 ;;
103 *)
104 cmake-utils_src_configure
105 ;;
106 esac
107
81 cmake-utils_src_make "$@" 108 cmake-utils_src_make "$@"
82} 109}
83 110
84# @FUNCTION: cmake-utils_src_configurein 111# @FUNCTION: cmake-utils_src_configurein
85# @DESCRIPTION: 112# @DESCRIPTION:
86# Function for software that requires configure and building in the source 113# Function for software that requires configure and building in the source
87# directory. 114# directory.
88cmake-utils_src_configurein() { 115cmake-utils_src_configurein() {
89 debug-print-function $FUNCNAME $* 116 debug-print-function $FUNCNAME $*
90 117
91 local cmakeargs="$(_common_configure_code) ${mycmakeargs}" 118 _common_configure_code
119 local cmakeargs="${mycmakeargs} ${EXTRA_ECONF} -DCMAKE_INSTALL_DO_STRIP=OFF"
92 120
93 debug-print "$LINENO $ECLASS $FUNCNAME: mycmakeargs is $cmakeargs" 121 debug-print "$LINENO $ECLASS $FUNCNAME: mycmakeargs is $cmakeargs"
94 cmake ${cmakeargs} . || die "Cmake failed" 122 cmake -C "${TMPDIR}/gentoo_common_config.cmake" ${cmakeargs} . || die "Cmake failed"
95} 123}
96 124
97# @FUNCTION: cmake-utils_src_configureout 125# @FUNCTION: cmake-utils_src_configureout
98# @DESCRIPTION: 126# @DESCRIPTION:
99# Function for software that requires configure and building outside the source 127# Function for software that requires configure and building outside the source
100# tree - default. 128# tree - default.
101cmake-utils_src_configureout() { 129cmake-utils_src_configureout() {
102 debug-print-function $FUNCNAME $* 130 debug-print-function $FUNCNAME $*
103 131
104 local cmakeargs="$(_common_configure_code) ${mycmakeargs}" 132 _common_configure_code
133 local cmakeargs="${mycmakeargs} ${EXTRA_ECONF} -DCMAKE_INSTALL_DO_STRIP=OFF"
105 mkdir -p "${WORKDIR}"/${PN}_build 134 mkdir -p "${WORKDIR}"/${PN}_build
106 pushd "${WORKDIR}"/${PN}_build > /dev/null 135 pushd "${WORKDIR}"/${PN}_build > /dev/null
107 136
108 debug-print "$LINENO $ECLASS $FUNCNAME: mycmakeargs is $cmakeargs" 137 debug-print "$LINENO $ECLASS $FUNCNAME: mycmakeargs is $cmakeargs"
109 cmake ${cmakeargs} "${S}" || die "Cmake failed" 138 cmake -C "${TMPDIR}/gentoo_common_config.cmake" ${cmakeargs} "${S}" || die "Cmake failed"
110 139
111 popd > /dev/null 140 popd > /dev/null
112} 141}
113 142
114# Internal use only. Common configuration options for all types of builds. 143# Internal use only. Common configuration options for all types of builds.
115_common_configure_code() { 144_common_configure_code() {
116 local tmp_libdir=$(get_libdir) 145 local tmp_libdir=$(get_libdir)
146 # here we set the compiler explicitly, set install directories prefixes, and
147 # make sure that the gentoo user compiler flags trump those set in the
148 # program
149 local modules_dir=/usr/share/cmake/Modules
150 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")
151 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")
152 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")
153 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")
154 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")
155 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")
156 cat > "${TMPDIR}/gentoo_common_config.cmake" <<_EOF_
157SET(CMAKE_C_COMPILER $(type -P $(tc-getCC)) CACHE STRING "package building C compiler")
158SET(CMAKE_CXX_COMPILER $(type -P $(tc-getCXX)) CACHE STRING "package building C++ compiler")
159${c_create_shared_library}
160${cxx_create_shared_library}
161${c_compile_object}
162${cxx_compile_object}
163${c_link_executable}
164${cxx_link_executable}
165SET(CMAKE_INSTALL_PREFIX ${PREFIX:-/usr} CACHE FILEPATH "install path prefix")
166SET(LIB_SUFFIX ${tmp_libdir/lib} CACHE FILEPATH "library path suffix")
167SET(LIB_INSTALL_DIR ${PREFIX:-/usr}/${tmp_libdir} CACHE FILEPATH "library install directory")
168
169_EOF_
170
171 [[ -n ${CMAKE_NO_COLOR} ]] && echo 'SET(CMAKE_COLOR_MAKEFILE OFF CACHE BOOL "pretty colors during make")' >> "${TMPDIR}/gentoo_common_config.cmake"
172
117 if has debug ${IUSE//+} && use debug; then 173 if has debug ${IUSE//+} && use debug ; then
118 echo -DCMAKE_BUILD_TYPE=Debug 174 echo 'SET(CMAKE_BUILD_TYPE Debug CACHE STRING "determines build settings")' >> "${TMPDIR}/gentoo_common_config.cmake"
119 else 175 else
120 echo -DCMAKE_BUILD_TYPE=Release 176 echo 'SET(CMAKE_BUILD_TYPE Release CACHE STRING "determines build settings")' >> "${TMPDIR}/gentoo_common_config.cmake"
121 fi 177 fi
122 echo -DCMAKE_C_COMPILER=$(type -P $(tc-getCC))
123 echo -DCMAKE_CXX_COMPILER=$(type -P $(tc-getCXX))
124 echo -DCMAKE_INSTALL_PREFIX=${PREFIX:-/usr}
125 echo -DLIB_SUFFIX=${tmp_libdir/lib}
126 echo -DLIB_INSTALL_DIR=${PREFIX:-/usr}/${tmp_libdir}
127 [[ -n ${CMAKE_NO_COLOR} ]] && echo -DCMAKE_COLOR_MAKEFILE=OFF
128} 178}
129 179
130# @FUNCTION: cmake-utils_src_make 180# @FUNCTION: cmake-utils_src_make
131# @DESCRIPTION: 181# @DESCRIPTION:
132# Function for building the package. Automatically detects the build type. 182# Function for building the package. Automatically detects the build type.
163 fi 213 fi
164 emake install DESTDIR="${D}" || die "Make install failed" 214 emake install DESTDIR="${D}" || die "Make install failed"
165 if [[ -d ${WORKDIR}/${PN}_build ]]; then 215 if [[ -d ${WORKDIR}/${PN}_build ]]; then
166 popd > /dev/null 216 popd > /dev/null
167 fi 217 fi
218
219 # Manual document installation
220 [[ -n "${DOCS}" ]] && dodoc ${DOCS}
168} 221}
169 222
170# @FUNCTION: cmake-utils_src_test 223# @FUNCTION: cmake-utils_src_test
171# @DESCRIPTION: 224# @DESCRIPTION:
172# Function for testing the package. Automatically detects the build type. 225# Function for testing the package. Automatically detects the build type.

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.16

  ViewVC Help
Powered by ViewVC 1.1.20