/[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.52 Revision 1.65
1# Copyright 1999-2010 Gentoo Foundation 1# Copyright 1999-2010 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.52 2010/05/27 02:44:14 reavertm Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/cmake-utils.eclass,v 1.65 2011/01/20 00:48:51 reavertm 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# 8#
28# used for optionality) 28# used for optionality)
29WANT_CMAKE="${WANT_CMAKE:-always}" 29WANT_CMAKE="${WANT_CMAKE:-always}"
30 30
31# @ECLASS-VARIABLE: CMAKE_MIN_VERSION 31# @ECLASS-VARIABLE: CMAKE_MIN_VERSION
32# @DESCRIPTION: 32# @DESCRIPTION:
33# Specify the minimum allowable version of cmake. Defaults to 2.6.2-r1 33# Specify the minimum required CMake version. Default is 2.8.1
34CMAKE_MIN_VERSION="${CMAKE_MIN_VERSION:-2.6.2-r1}" 34CMAKE_MIN_VERSION="${CMAKE_MIN_VERSION:-2.8.1}"
35 35
36CMAKEDEPEND="" 36CMAKEDEPEND=""
37case ${WANT_CMAKE} in 37case ${WANT_CMAKE} in
38 always) 38 always)
39 ;; 39 ;;
99 echo "-D$1$x=$(use $2 && echo OFF || echo ON) " 99 echo "-D$1$x=$(use $2 && echo OFF || echo ON) "
100 done 100 done
101 fi 101 fi
102} 102}
103 103
104# @ECLASS-VARIABLE: PREFIX
105# @DESCRIPTION:
106# Eclass respects PREFIX variable, though it's not recommended way to set
107# install/lib/bin prefixes.
108# Use -DCMAKE_INSTALL_PREFIX=... CMake variable instead.
109
110# @ECLASS-VARIABLE: CMAKE_IN_SOURCE_BUILD 104# @ECLASS-VARIABLE: CMAKE_BUILD_DIR
111# @DESCRIPTION: 105# @DESCRIPTION:
112# Set to enable in-source build. 106# Build directory where all cmake processed files should be generated.
113 107# For in-source build it's fixed to ${CMAKE_USE_DIR}.
114# @ECLASS-VARIABLE: CMAKE_VERBOSE 108# For out-of-source build it can be overriden, by default it uses
115# @DESCRIPTION: 109# ${WORKDIR}/${P}_build.
116# Set to enable verbose messages during compilation.
117 110
118# @ECLASS-VARIABLE: CMAKE_BUILD_TYPE 111# @ECLASS-VARIABLE: CMAKE_BUILD_TYPE
119# @DESCRIPTION: 112# @DESCRIPTION:
120# Set to override default CMAKE_BUILD_TYPE. Only useful for packages 113# Set to override default CMAKE_BUILD_TYPE. Only useful for packages
121# known to make use of "if (CMAKE_BUILD_TYPE MATCHES xxx)". 114# known to make use of "if (CMAKE_BUILD_TYPE MATCHES xxx)".
122# If about to be set - needs to be set before invoking cmake-utils_src_configure. 115# If about to be set - needs to be set before invoking cmake-utils_src_configure.
123# You usualy do *NOT* want nor need to set it as it pulls CMake default build-type 116# You usualy do *NOT* want nor need to set it as it pulls CMake default build-type
124# specific compiler flags overriding make.conf. 117# specific compiler flags overriding make.conf.
125: ${CMAKE_BUILD_TYPE:=Gentoo} 118: ${CMAKE_BUILD_TYPE:=Gentoo}
126 119
120# @ECLASS-VARIABLE: CMAKE_IN_SOURCE_BUILD
121# @DESCRIPTION:
122# Set to enable in-source build.
123
124# @ECLASS-VARIABLE: CMAKE_USE_DIR
125# @DESCRIPTION:
126# Sets the directory where we are working with cmake.
127# For example when application uses autotools and only one
128# plugin needs to be done by cmake.
129# By default it uses ${S}.
130
131# @ECLASS-VARIABLE: CMAKE_VERBOSE
132# @DESCRIPTION:
133# Set to enable verbose messages during compilation.
134
135# @ECLASS-VARIABLE: PREFIX
136# @DESCRIPTION:
137# Eclass respects PREFIX variable, though it's not recommended way to set
138# install/lib/bin prefixes.
139# Use -DCMAKE_INSTALL_PREFIX=... CMake variable instead.
140
141# @ECLASS-VARIABLE: CMAKE_BINARY
142# @DESCRIPTION:
143# Eclass can use different cmake binary than the one provided in by system.
144: ${CMAKE_BINARY:=cmake}
145
127# Determine using IN or OUT source build 146# Determine using IN or OUT source build
128_check_build_dir() { 147_check_build_dir() {
129 # @ECLASS-VARIABLE: CMAKE_USE_DIR
130 # @DESCRIPTION:
131 # Sets the directory where we are working with cmake.
132 # For example when application uses autotools and only one
133 # plugin needs to be done by cmake.
134 # By default it uses ${S}.
135 : ${CMAKE_USE_DIR:=${S}} 148 : ${CMAKE_USE_DIR:=${S}}
136
137 # @ECLASS-VARIABLE: CMAKE_BUILD_DIR
138 # @DESCRIPTION:
139 # Specify the build directory where all cmake processed
140 # files should be located.
141 #
142 # For installing binary doins "${CMAKE_BUILD_DIR}/${PN}"
143 if [[ -n ${CMAKE_IN_SOURCE_BUILD} ]]; then 149 if [[ -n ${CMAKE_IN_SOURCE_BUILD} ]]; then
144 # we build in source dir 150 # we build in source dir
145 CMAKE_BUILD_DIR="${CMAKE_USE_DIR}" 151 CMAKE_BUILD_DIR="${CMAKE_USE_DIR}"
146 elif [[ ${CMAKE_USE_DIR} = ${WORKDIR} ]]; then
147 # out of tree build, but with $S=$WORKDIR, see bug #273949 for reason.
148 CMAKE_BUILD_DIR="${CMAKE_USE_DIR}/build"
149 else 152 else
150 # regular out of tree build 153 : ${CMAKE_BUILD_DIR:=${WORKDIR}/${P}_build}
151 [[ ${1} = init || -d ${CMAKE_USE_DIR}_build ]] && SUF="_build" || SUF=""
152 CMAKE_BUILD_DIR="${CMAKE_USE_DIR}${SUF}"
153 fi 154 fi
154 echo ">>> Working in BUILD_DIR: \"$CMAKE_BUILD_DIR\"" 155 echo ">>> Working in BUILD_DIR: \"$CMAKE_BUILD_DIR\""
155} 156}
156# @FUNCTION: cmake-utils_use_with 157# @FUNCTION: cmake-utils_use_with
157# @USAGE: <USE flag> [flag name] 158# @USAGE: <USE flag> [flag name]
213# Based on use_enable. See ebuild(5). 214# Based on use_enable. See ebuild(5).
214# 215#
215# `cmake-utils_use_has foo FOO` echoes -DHAVE_FOO=ON if foo is enabled 216# `cmake-utils_use_has foo FOO` echoes -DHAVE_FOO=ON if foo is enabled
216# and -DHAVE_FOO=OFF if it is disabled. 217# and -DHAVE_FOO=OFF if it is disabled.
217cmake-utils_use_has() { _use_me_now HAVE_ "$@" ; } 218cmake-utils_use_has() { _use_me_now HAVE_ "$@" ; }
219
220# @FUNCTION: cmake-utils_use_use
221# @USAGE: <USE flag> [flag name]
222# @DESCRIPTION:
223# Based on use_enable. See ebuild(5).
224#
225# `cmake-utils_use_use foo FOO` echoes -DUSE_FOO=ON if foo is enabled
226# and -DUSE_FOO=OFF if it is disabled.
227cmake-utils_use_use() { _use_me_now USE_ "$@" ; }
218 228
219# @FUNCTION: cmake-utils_use 229# @FUNCTION: cmake-utils_use
220# @USAGE: <USE flag> [flag name] 230# @USAGE: <USE flag> [flag name]
221# @DESCRIPTION: 231# @DESCRIPTION:
222# Based on use_enable. See ebuild(5). 232# Based on use_enable. See ebuild(5).
232 242
233 # Comment out all set (<some_should_be_user_defined_variable> value) 243 # Comment out all set (<some_should_be_user_defined_variable> value)
234 # TODO Add QA checker - inform when variable being checked for below is set in CMakeLists.txt 244 # TODO Add QA checker - inform when variable being checked for below is set in CMakeLists.txt
235 find "${CMAKE_USE_DIR}" -name CMakeLists.txt \ 245 find "${CMAKE_USE_DIR}" -name CMakeLists.txt \
236 -exec sed -i -e '/^[[:space:]]*[sS][eE][tT][[:space:]]*([[:space:]]*CMAKE_BUILD_TYPE.*)/{s/^/#IGNORE /g}' {} + \ 246 -exec sed -i -e '/^[[:space:]]*[sS][eE][tT][[:space:]]*([[:space:]]*CMAKE_BUILD_TYPE.*)/{s/^/#IGNORE /g}' {} + \
247 -exec sed -i -e '/^[[:space:]]*[sS][eE][tT][[:space:]]*([[:space:]]*CMAKE_COLOR_MAKEFILE.*)/{s/^/#IGNORE /g}' {} + \
237 -exec sed -i -e '/^[[:space:]]*[sS][eE][tT][[:space:]]*([[:space:]]*CMAKE_INSTALL_PREFIX.*)/{s/^/#IGNORE /g}' {} + \ 248 -exec sed -i -e '/^[[:space:]]*[sS][eE][tT][[:space:]]*([[:space:]]*CMAKE_INSTALL_PREFIX.*)/{s/^/#IGNORE /g}' {} + \
249 -exec sed -i -e '/^[[:space:]]*[sS][eE][tT][[:space:]]*([[:space:]]*CMAKE_VERBOSE_MAKEFILE.*)/{s/^/#IGNORE /g}' {} + \
238 || die "${LINENO}: failed to disable hardcoded settings" 250 || die "${LINENO}: failed to disable hardcoded settings"
239 251
240 # NOTE Append some useful summary here 252 # NOTE Append some useful summary here
241 cat >> CMakeLists.txt <<- _EOF_ 253 cat >> CMakeLists.txt <<- _EOF_
242 254
254} 266}
255 267
256enable_cmake-utils_src_configure() { 268enable_cmake-utils_src_configure() {
257 debug-print-function ${FUNCNAME} "$@" 269 debug-print-function ${FUNCNAME} "$@"
258 270
259 _check_build_dir init 271 _check_build_dir
260 272
261 # check if CMakeLists.txt exist and if no then die 273 # check if CMakeLists.txt exist and if no then die
262 if [[ ! -e ${CMAKE_USE_DIR}/CMakeLists.txt ]] ; then 274 if [[ ! -e ${CMAKE_USE_DIR}/CMakeLists.txt ]] ; then
263 eerror "Unable to locate CMakeLists.txt under:" 275 eerror "Unable to locate CMakeLists.txt under:"
264 eerror "\"${CMAKE_USE_DIR}/CMakeLists.txt\"" 276 eerror "\"${CMAKE_USE_DIR}/CMakeLists.txt\""
295 # right ... except for Darwin hosts 307 # right ... except for Darwin hosts
296 IF (NOT APPLE) 308 IF (NOT APPLE)
297 SET (CMAKE_SKIP_RPATH OFF CACHE BOOL "" FORCE) 309 SET (CMAKE_SKIP_RPATH OFF CACHE BOOL "" FORCE)
298 SET (CMAKE_PLATFORM_REQUIRED_RUNTIME_PATH "${EPREFIX}/usr/${CHOST}/lib/gcc;${EPREFIX}/usr/${CHOST}/lib;${EPREFIX}/usr/$(get_libdir);${EPREFIX}/$(get_libdir)" 310 SET (CMAKE_PLATFORM_REQUIRED_RUNTIME_PATH "${EPREFIX}/usr/${CHOST}/lib/gcc;${EPREFIX}/usr/${CHOST}/lib;${EPREFIX}/usr/$(get_libdir);${EPREFIX}/$(get_libdir)"
299 CACHE STRING "" FORCE) 311 CACHE STRING "" FORCE)
312
313 ELSE ()
314
315 SET(CMAKE_PREFIX_PATH "${EPREFIX}${PREFIX:-/usr}" CACHE STRING ""FORCE)
316 SET(CMAKE_SKIP_BUILD_RPATH OFF CACHE BOOL "" FORCE)
317 SET(CMAKE_SKIP_RPATH OFF CACHE BOOL "" FORCE)
318 SET(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE CACHE BOOL "" FORCE)
319 SET(CMAKE_INSTALL_RPATH "${EPREFIX}${PREFIX:-/usr}/lib;${EPREFIX}/usr/${CHOST}/lib/gcc;${EPREFIX}/usr/${CHOST}/lib;${EPREFIX}/usr/$(get_libdir);${EPREFIX}/$(get_libdir)" CACHE STRING "" FORCE)
320 SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE CACHE BOOL "" FORCE)
321 SET(CMAKE_INSTALL_NAME_DIR "${EPREFIX}${PREFIX:-/usr}/lib" CACHE STRING "" FORCE)
322
300 ENDIF (NOT APPLE) 323 ENDIF (NOT APPLE)
301 _EOF_ 324 _EOF_
302 fi 325 fi
303 326
304 # Common configure parameters (invariants) 327 # Common configure parameters (invariants)
306 local libdir=$(get_libdir) 329 local libdir=$(get_libdir)
307 cat > "${common_config}" <<- _EOF_ 330 cat > "${common_config}" <<- _EOF_
308 SET (LIB_SUFFIX ${libdir/lib} CACHE STRING "library path suffix" FORCE) 331 SET (LIB_SUFFIX ${libdir/lib} CACHE STRING "library path suffix" FORCE)
309 SET (CMAKE_INSTALL_LIBDIR ${libdir} CACHE PATH "Output directory for libraries") 332 SET (CMAKE_INSTALL_LIBDIR ${libdir} CACHE PATH "Output directory for libraries")
310 _EOF_ 333 _EOF_
311 [[ -n ${NOCOLOR} ]] || echo 'SET (CMAKE_COLOR_MAKEFILE OFF CACHE BOOL "pretty colors during make" FORCE)' >> "${common_config}" 334 [[ "${NOCOLOR}" = true || "${NOCOLOR}" = yes ]] && echo 'SET (CMAKE_COLOR_MAKEFILE OFF CACHE BOOL "pretty colors during make" FORCE)' >> "${common_config}"
312 335
313 # Convert mycmakeargs to an array, for backwards compatibility 336 # Convert mycmakeargs to an array, for backwards compatibility
314 # Make the array a local variable since <=portage-2.1.6.x does not 337 # Make the array a local variable since <=portage-2.1.6.x does not
315 # support global arrays (see bug #297255). 338 # support global arrays (see bug #297255).
316 if [[ $(declare -p mycmakeargs 2>&-) != "declare -a mycmakeargs="* ]]; then 339 if [[ $(declare -p mycmakeargs 2>&-) != "declare -a mycmakeargs="* ]]; then
335 ) 358 )
336 359
337 mkdir -p "${CMAKE_BUILD_DIR}" 360 mkdir -p "${CMAKE_BUILD_DIR}"
338 pushd "${CMAKE_BUILD_DIR}" > /dev/null 361 pushd "${CMAKE_BUILD_DIR}" > /dev/null
339 debug-print "${LINENO} ${ECLASS} ${FUNCNAME}: mycmakeargs is ${mycmakeargs_local[*]}" 362 debug-print "${LINENO} ${ECLASS} ${FUNCNAME}: mycmakeargs is ${mycmakeargs_local[*]}"
340 echo cmake "${cmakeargs[@]}" "${CMAKE_USE_DIR}" 363 echo "${CMAKE_BINARY}" "${cmakeargs[@]}" "${CMAKE_USE_DIR}"
341 cmake "${cmakeargs[@]}" "${CMAKE_USE_DIR}" || die "cmake failed" 364 "${CMAKE_BINARY}" "${cmakeargs[@]}" "${CMAKE_USE_DIR}" || die "cmake failed"
342
343 popd > /dev/null 365 popd > /dev/null
344} 366}
345 367
346enable_cmake-utils_src_compile() { 368enable_cmake-utils_src_compile() {
347 debug-print-function ${FUNCNAME} "$@" 369 debug-print-function ${FUNCNAME} "$@"
351} 373}
352 374
353# @FUNCTION: cmake-utils_src_make 375# @FUNCTION: cmake-utils_src_make
354# @DESCRIPTION: 376# @DESCRIPTION:
355# Function for building the package. Automatically detects the build type. 377# Function for building the package. Automatically detects the build type.
356# All arguments are passed to emake 378# All arguments are passed to emake.
357cmake-utils_src_make() { 379cmake-utils_src_make() {
358 debug-print-function ${FUNCNAME} "$@" 380 debug-print-function ${FUNCNAME} "$@"
359 381
360 _check_build_dir 382 _check_build_dir
361 pushd "${CMAKE_BUILD_DIR}" &> /dev/null 383 pushd "${CMAKE_BUILD_DIR}" > /dev/null
362 # first check if Makefile exist otherwise die 384 # first check if Makefile exist otherwise die
363 [[ -e Makefile ]] || die "Makefile not found. Error during configure stage." 385 [[ -e Makefile ]] || die "Makefile not found. Error during configure stage."
364 if [[ -n ${CMAKE_VERBOSE} ]]; then 386 if [[ -n ${CMAKE_VERBOSE} ]]; then
365 emake VERBOSE=1 "$@" || die "Make failed!" 387 emake VERBOSE=1 "$@" || die "Make failed!"
366 else 388 else
367 emake "$@" || die "Make failed!" 389 emake "$@" || die "Make failed!"
368 fi 390 fi
369 popd &> /dev/null 391 popd > /dev/null
370} 392}
371 393
372enable_cmake-utils_src_install() { 394enable_cmake-utils_src_install() {
373 debug-print-function ${FUNCNAME} "$@" 395 debug-print-function ${FUNCNAME} "$@"
374 396
375 _check_build_dir 397 _check_build_dir
376 pushd "${CMAKE_BUILD_DIR}" &> /dev/null 398 pushd "${CMAKE_BUILD_DIR}" > /dev/null
377 base_src_install 399 base_src_install "$@"
378 popd &> /dev/null 400 popd > /dev/null
379 401
380 # Backward compatibility, for non-array variables 402 # Backward compatibility, for non-array variables
381 if [[ -n "${DOCS}" ]] && [[ "$(declare -p DOCS 2>/dev/null 2>&1)" != "declare -a"* ]]; then 403 if [[ -n "${DOCS}" ]] && [[ "$(declare -p DOCS 2>/dev/null 2>&1)" != "declare -a"* ]]; then
382 dodoc ${DOCS} || die "dodoc failed" 404 dodoc ${DOCS} || die "dodoc failed"
383 fi 405 fi
388 410
389enable_cmake-utils_src_test() { 411enable_cmake-utils_src_test() {
390 debug-print-function ${FUNCNAME} "$@" 412 debug-print-function ${FUNCNAME} "$@"
391 413
392 _check_build_dir 414 _check_build_dir
393 pushd "${CMAKE_BUILD_DIR}" &> /dev/null 415 pushd "${CMAKE_BUILD_DIR}" > /dev/null
394 # Standard implementation of src_test 416 local ctestargs
395 if emake -j1 check -n &> /dev/null; then 417 [[ -n ${TEST_VERBOSE} ]] && ctestargs="--extra-verbose --output-on-failure"
396 einfo ">>> Test phase [check]: ${CATEGORY}/${PF}" 418 ctest ${ctestargs} "$@" || die "Tests failed."
397 if ! emake -j1 check; then
398 die "Make check failed. See above for details."
399 fi
400 elif emake -j1 test -n &> /dev/null; then
401 einfo ">>> Test phase [test]: ${CATEGORY}/${PF}"
402 if ! emake -j1 test; then
403 die "Make test failed. See above for details."
404 fi
405 else
406 einfo ">>> Test phase [none]: ${CATEGORY}/${PF}"
407 fi
408 popd &> /dev/null 419 popd > /dev/null
409} 420}
410 421
411# @FUNCTION: cmake-utils_src_configure 422# @FUNCTION: cmake-utils_src_configure
412# @DESCRIPTION: 423# @DESCRIPTION:
413# General function for configuring with cmake. Default behaviour is to start an 424# General function for configuring with cmake. Default behaviour is to start an

Legend:
Removed from v.1.52  
changed lines
  Added in v.1.65

  ViewVC Help
Powered by ViewVC 1.1.20