1 # Copyright 1999-2015 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
5 # @ECLASS: cmake-utils.eclass
9 # Tomáš Chvátal <scarabeus@gentoo.org>
10 # Maciej Mrozowski <reavertm@gentoo.org>
11 # (undisclosed contributors)
12 # Original author: Zephyrus (zephyrus@mirach.it)
13 # @BLURB: common ebuild functions for cmake-based packages
15 # The cmake-utils eclass makes creating ebuilds for cmake-based packages much easier.
16 # It provides all inherited features (DOCS, HTML_DOCS, PATCHES) along with out-of-source
17 # builds (default), in-source builds and an implementation of the well-known use_enable
18 # and use_with functions for CMake.
20 if [[ -z ${_CMAKE_UTILS_ECLASS} ]]; then
24 # @ECLASS-VARIABLE: BUILD_DIR
26 # Build directory where all cmake processed files should be generated.
27 # For in-source build it's fixed to ${CMAKE_USE_DIR}.
28 # For out-of-source build it can be overridden, by default it uses
29 # ${WORKDIR}/${P}_build.
31 # This variable has been called CMAKE_BUILD_DIR formerly.
32 # It is set under that name for compatibility.
34 # @ECLASS-VARIABLE: CMAKE_BINARY
36 # Eclass can use different cmake binary than the one provided in by system.
37 : ${CMAKE_BINARY:=cmake}
39 # @ECLASS-VARIABLE: CMAKE_BUILD_TYPE
41 # Set to override default CMAKE_BUILD_TYPE. Only useful for packages
42 # known to make use of "if (CMAKE_BUILD_TYPE MATCHES xxx)".
43 # If about to be set - needs to be set before invoking cmake-utils_src_configure.
44 # You usualy do *NOT* want nor need to set it as it pulls CMake default build-type
45 # specific compiler flags overriding make.conf.
46 : ${CMAKE_BUILD_TYPE:=Gentoo}
48 # @ECLASS-VARIABLE: CMAKE_IN_SOURCE_BUILD
50 # Set to enable in-source build.
52 # @ECLASS-VARIABLE: CMAKE_MAKEFILE_GENERATOR
54 # Specify a makefile generator to be used by cmake.
55 # At this point only "emake" and "ninja" are supported.
56 : ${CMAKE_MAKEFILE_GENERATOR:=emake}
58 # @ECLASS-VARIABLE: CMAKE_MIN_VERSION
60 # Specify the minimum required CMake version.
61 : ${CMAKE_MIN_VERSION:=2.8.12}
63 # @ECLASS-VARIABLE: CMAKE_REMOVE_MODULES
65 # Do we want to remove anything? yes or whatever else for no
66 : ${CMAKE_REMOVE_MODULES:=yes}
67 CMAKE_REMOVE_MODULES="${CMAKE_REMOVE_MODULES:-yes}"
69 # @ECLASS-VARIABLE: CMAKE_REMOVE_MODULES_LIST
71 # Space-separated list of CMake modules that will be removed in $S during src_prepare,
72 # in order to force packages to use the system version.
73 : ${CMAKE_REMOVE_MODULES_LIST:=FindBLAS FindLAPACK}
75 # @ECLASS-VARIABLE: CMAKE_USE_DIR
77 # Sets the directory where we are working with cmake.
78 # For example when application uses autotools and only one
79 # plugin needs to be done by cmake.
80 # By default it uses ${S}.
82 # @ECLASS-VARIABLE: CMAKE_VERBOSE
84 # Set to OFF to disable verbose messages during compilation
85 : ${CMAKE_VERBOSE:=ON}
87 # @ECLASS-VARIABLE: CMAKE_WARN_UNUSED_CLI
89 # Warn about variables that are declared on the command line
90 # but not used. Might give false-positives.
91 # "no" to disable (default) or anything else to enable.
92 : ${CMAKE_WARN_UNUSED_CLI:=no}
94 # @ECLASS-VARIABLE: PREFIX
96 # Eclass respects PREFIX variable, though it's not recommended way to set
97 # install/lib/bin prefixes.
98 # Use -DCMAKE_INSTALL_PREFIX=... CMake variable instead.
101 # @ECLASS-VARIABLE: WANT_CMAKE
103 # Specify if cmake-utils eclass should depend on cmake optionally or not.
104 # This is useful when only part of application is using cmake build system.
105 # Valid values are: always [default], optional (where the value is the useflag
106 # used for optionality)
107 : ${WANT_CMAKE:=always}
109 # @ECLASS-VARIABLE: CMAKE_EXTRA_CACHE_FILE
111 # Specifies an extra cache file to pass to cmake. This is the analog of EXTRA_ECONF
112 # for econf and is needed to pass TRY_RUN results when cross-compiling.
113 # Should be set by user in a per-package basis in /etc/portage/package.env.
116 case ${WANT_CMAKE} in
120 IUSE+=" ${WANT_CMAKE}"
121 CMAKEDEPEND+="${WANT_CMAKE}? ( "
124 inherit toolchain-funcs multilib flag-o-matic eutils versionator
128 *) die "EAPI=${EAPI:-0} is not supported" ;;
131 EXPORT_FUNCTIONS src_prepare src_configure src_compile src_test src_install
133 case ${CMAKE_MAKEFILE_GENERATOR} in
135 CMAKEDEPEND+=" sys-devel/make"
138 CMAKEDEPEND+=" dev-util/ninja"
141 eerror "Unknown value for \${CMAKE_MAKEFILE_GENERATOR}"
142 die "Value ${CMAKE_MAKEFILE_GENERATOR} is not supported"
146 if [[ ${PN} != cmake ]]; then
147 CMAKEDEPEND+=" >=dev-util/cmake-${CMAKE_MIN_VERSION}"
150 CMAKEDEPEND+=" userland_GNU? ( >=sys-apps/findutils-4.4.0 )"
152 [[ ${WANT_CMAKE} = always ]] || CMAKEDEPEND+=" )"
154 DEPEND="${CMAKEDEPEND}"
157 # Internal functions used by cmake-utils_use_*
159 debug-print-function ${FUNCNAME} "$@"
161 local uper capitalised x
162 [[ -z $2 ]] && die "cmake-utils_use-$1 <USE flag> [<flag name>]"
163 if [[ ! -z $3 ]]; then
164 # user specified the use name so use it
165 echo "-D$1$3=$(use $2 && echo ON || echo OFF)"
167 # use all various most used combinations
168 uper=$(echo ${2} | tr '[:lower:]' '[:upper:]')
169 capitalised=$(echo ${2} | sed 's/\<\(.\)\([^ ]*\)/\u\1\L\2/g')
170 for x in $2 $uper $capitalised; do
171 echo "-D$1$x=$(use $2 && echo ON || echo OFF) "
175 _use_me_now_inverted() {
176 debug-print-function ${FUNCNAME} "$@"
178 local uper capitalised x
179 [[ -z $2 ]] && die "cmake-utils_use-$1 <USE flag> [<flag name>]"
180 if [[ ! -z $3 ]]; then
181 # user specified the use name so use it
182 echo "-D$1$3=$(use $2 && echo OFF || echo ON)"
184 # use all various most used combinations
185 uper=$(echo ${2} | tr '[:lower:]' '[:upper:]')
186 capitalised=$(echo ${2} | sed 's/\<\(.\)\([^ ]*\)/\u\1\L\2/g')
187 for x in $2 $uper $capitalised; do
188 echo "-D$1$x=$(use $2 && echo OFF || echo ON) "
193 # Determine using IN or OUT source build
195 : ${CMAKE_USE_DIR:=${S}}
196 if [[ -n ${CMAKE_IN_SOURCE_BUILD} ]]; then
197 # we build in source dir
198 BUILD_DIR="${CMAKE_USE_DIR}"
200 # Respect both the old variable and the new one, depending
201 # on which one was set by the ebuild.
202 if [[ ! ${BUILD_DIR} && ${CMAKE_BUILD_DIR} ]]; then
203 eqawarn "The CMAKE_BUILD_DIR variable has been renamed to BUILD_DIR."
204 eqawarn "Please migrate the ebuild to use the new one."
206 # In the next call, both variables will be set already
207 # and we'd have to know which one takes precedence.
208 _RESPECT_CMAKE_BUILD_DIR=1
211 if [[ ${_RESPECT_CMAKE_BUILD_DIR} ]]; then
212 BUILD_DIR=${CMAKE_BUILD_DIR:-${WORKDIR}/${P}_build}
214 : ${BUILD_DIR:=${WORKDIR}/${P}_build}
218 # Backwards compatibility for getting the value.
219 CMAKE_BUILD_DIR=${BUILD_DIR}
221 mkdir -p "${BUILD_DIR}"
222 echo ">>> Working in BUILD_DIR: \"$BUILD_DIR\""
225 # Determine which generator to use
226 _generator_to_use() {
229 case ${CMAKE_MAKEFILE_GENERATOR} in
231 # if ninja is enabled but not installed, the build could fail
232 # this could happen if ninja is manually enabled (eg. make.conf) but not installed
233 if ! has_version dev-util/ninja; then
234 die "CMAKE_MAKEFILE_GENERATOR is set to ninja, but ninja is not installed. Please install dev-util/ninja or unset CMAKE_MAKEFILE_GENERATOR."
236 generator_name="Ninja"
239 generator_name="Unix Makefiles"
242 eerror "Unknown value for \${CMAKE_MAKEFILE_GENERATOR}"
243 die "Value ${CMAKE_MAKEFILE_GENERATOR} is not supported"
247 echo ${generator_name}
250 # @FUNCTION: comment_add_subdirectory
251 # @USAGE: <subdirectory>
253 # Comment out an add_subdirectory call in CMakeLists.txt in the current directory
254 comment_add_subdirectory() {
255 if [[ -z ${1} ]]; then
256 die "comment_add_subdirectory must be passed the directory name to comment"
259 if [[ -e "CMakeLists.txt" ]]; then
260 sed -e "/add_subdirectory[[:space:]]*([[:space:]]*${1//\//\\/}[[:space:]]*)/s/^/#DONOTCOMPILE /" \
261 -i CMakeLists.txt || die "failed to comment add_subdirectory(${1})"
265 # @FUNCTION: cmake-utils_use_with
266 # @USAGE: <USE flag> [flag name]
268 # Based on use_with. See ebuild(5).
270 # `cmake-utils_use_with foo FOO` echoes -DWITH_FOO=ON if foo is enabled
271 # and -DWITH_FOO=OFF if it is disabled.
272 cmake-utils_use_with() { _use_me_now WITH_ "$@" ; }
274 # @FUNCTION: cmake-utils_use_enable
275 # @USAGE: <USE flag> [flag name]
277 # Based on use_enable. See ebuild(5).
279 # `cmake-utils_use_enable foo FOO` echoes -DENABLE_FOO=ON if foo is enabled
280 # and -DENABLE_FOO=OFF if it is disabled.
281 cmake-utils_use_enable() { _use_me_now ENABLE_ "$@" ; }
283 # @FUNCTION: cmake-utils_use_find_package
284 # @USAGE: <USE flag> [flag name]
286 # Based on use_enable. See ebuild(5).
288 # `cmake-utils_use_find_package foo LibFoo` echoes -DCMAKE_DISABLE_FIND_PACKAGE_LibFoo=OFF
289 # if foo is enabled and -DCMAKE_DISABLE_FIND_PACKAGE_LibFoo=ON if it is disabled.
290 # This can be used to make find_package optional.
291 cmake-utils_use_find_package() { _use_me_now_inverted CMAKE_DISABLE_FIND_PACKAGE_ "$@" ; }
293 # @FUNCTION: cmake-utils_use_disable
294 # @USAGE: <USE flag> [flag name]
296 # Based on inversion of use_enable. See ebuild(5).
298 # `cmake-utils_use_enable foo FOO` echoes -DDISABLE_FOO=OFF if foo is enabled
299 # and -DDISABLE_FOO=ON if it is disabled.
300 cmake-utils_use_disable() { _use_me_now_inverted DISABLE_ "$@" ; }
302 # @FUNCTION: cmake-utils_use_no
303 # @USAGE: <USE flag> [flag name]
305 # Based on use_disable. See ebuild(5).
307 # `cmake-utils_use_no foo FOO` echoes -DNO_FOO=OFF if foo is enabled
308 # and -DNO_FOO=ON if it is disabled.
309 cmake-utils_use_no() { _use_me_now_inverted NO_ "$@" ; }
311 # @FUNCTION: cmake-utils_use_want
312 # @USAGE: <USE flag> [flag name]
314 # Based on use_enable. See ebuild(5).
316 # `cmake-utils_use_want foo FOO` echoes -DWANT_FOO=ON if foo is enabled
317 # and -DWANT_FOO=OFF if it is disabled.
318 cmake-utils_use_want() { _use_me_now WANT_ "$@" ; }
320 # @FUNCTION: cmake-utils_use_build
321 # @USAGE: <USE flag> [flag name]
323 # Based on use_enable. See ebuild(5).
325 # `cmake-utils_use_build foo FOO` echoes -DBUILD_FOO=ON if foo is enabled
326 # and -DBUILD_FOO=OFF if it is disabled.
327 cmake-utils_use_build() { _use_me_now BUILD_ "$@" ; }
329 # @FUNCTION: cmake-utils_use_has
330 # @USAGE: <USE flag> [flag name]
332 # Based on use_enable. See ebuild(5).
334 # `cmake-utils_use_has foo FOO` echoes -DHAVE_FOO=ON if foo is enabled
335 # and -DHAVE_FOO=OFF if it is disabled.
336 cmake-utils_use_has() { _use_me_now HAVE_ "$@" ; }
338 # @FUNCTION: cmake-utils_use_use
339 # @USAGE: <USE flag> [flag name]
341 # Based on use_enable. See ebuild(5).
343 # `cmake-utils_use_use foo FOO` echoes -DUSE_FOO=ON if foo is enabled
344 # and -DUSE_FOO=OFF if it is disabled.
345 cmake-utils_use_use() { _use_me_now USE_ "$@" ; }
347 # @FUNCTION: cmake-utils_use
348 # @USAGE: <USE flag> [flag name]
350 # Based on use_enable. See ebuild(5).
352 # `cmake-utils_use foo FOO` echoes -DFOO=ON if foo is enabled
353 # and -DFOO=OFF if it is disabled.
354 cmake-utils_use() { _use_me_now "" "$@" ; }
356 # @FUNCTION: cmake-utils_useno
357 # @USAGE: <USE flag> [flag name]
359 # Based on use_enable. See ebuild(5).
361 # `cmake-utils_useno foo NOFOO` echoes -DNOFOO=OFF if foo is enabled
362 # and -DNOFOO=ON if it is disabled.
363 cmake-utils_useno() { _use_me_now_inverted "" "$@" ; }
365 # Internal function for modifying hardcoded definitions.
366 # Removes dangerous definitions that override Gentoo settings.
367 _modify-cmakelists() {
368 debug-print-function ${FUNCNAME} "$@"
370 # Only edit the files once
371 grep -qs "<<< Gentoo configuration >>>" "${CMAKE_USE_DIR}"/CMakeLists.txt && return 0
373 # Comment out all set (<some_should_be_user_defined_variable> value)
374 # TODO Add QA checker - inform when variable being checked for below is set in CMakeLists.txt
375 find "${CMAKE_USE_DIR}" -name CMakeLists.txt \
376 -exec sed -i -e '/^[[:space:]]*[sS][eE][tT][[:space:]]*([[:space:]]*CMAKE_BUILD_TYPE.*)/{s/^/#IGNORE /g}' {} + \
377 -exec sed -i -e '/^[[:space:]]*[sS][eE][tT][[:space:]]*([[:space:]]*CMAKE_COLOR_MAKEFILE.*)/{s/^/#IGNORE /g}' {} + \
378 -exec sed -i -e '/^[[:space:]]*[sS][eE][tT][[:space:]]*([[:space:]]*CMAKE_INSTALL_PREFIX.*)/{s/^/#IGNORE /g}' {} + \
379 -exec sed -i -e '/^[[:space:]]*[sS][eE][tT][[:space:]]*([[:space:]]*CMAKE_VERBOSE_MAKEFILE.*)/{s/^/#IGNORE /g}' {} + \
380 || die "${LINENO}: failed to disable hardcoded settings"
382 # NOTE Append some useful summary here
383 cat >> "${CMAKE_USE_DIR}"/CMakeLists.txt <<- _EOF_ || die
385 MESSAGE(STATUS "<<< Gentoo configuration >>>
386 Build type \${CMAKE_BUILD_TYPE}
387 Install path \${CMAKE_INSTALL_PREFIX}
390 C++ \${CMAKE_CXX_FLAGS}
392 Executable \${CMAKE_EXE_LINKER_FLAGS}
393 Module \${CMAKE_MODULE_LINKER_FLAGS}
394 Shared \${CMAKE_SHARED_LINKER_FLAGS}\n")
398 enable_cmake-utils_src_prepare() {
399 debug-print-function ${FUNCNAME} "$@"
401 pushd "${S}" > /dev/null || die
403 debug-print "$FUNCNAME: PATCHES=$PATCHES"
404 [[ ${PATCHES[@]} ]] && epatch "${PATCHES[@]}"
406 debug-print "$FUNCNAME: applying user patches"
409 popd > /dev/null || die
412 # @VARIABLE: mycmakeargs
415 # Optional cmake defines as a bash array. Should be defined before calling
419 # local mycmakeargs=(
420 # $(cmake-utils_use_with openconnect)
423 # cmake-utils_src_configure
427 enable_cmake-utils_src_configure() {
428 debug-print-function ${FUNCNAME} "$@"
430 [[ "${CMAKE_REMOVE_MODULES}" == "yes" ]] && {
432 for name in ${CMAKE_REMOVE_MODULES_LIST} ; do
433 find "${S}" -name ${name}.cmake -exec rm -v {} +
439 # check if CMakeLists.txt exist and if no then die
440 if [[ ! -e ${CMAKE_USE_DIR}/CMakeLists.txt ]] ; then
441 eerror "Unable to locate CMakeLists.txt under:"
442 eerror "\"${CMAKE_USE_DIR}/CMakeLists.txt\""
443 eerror "Consider not inheriting the cmake eclass."
444 die "FATAL: Unable to find CMakeLists.txt"
447 # Remove dangerous things.
450 # Fix xdg collision with sandbox
451 export XDG_CONFIG_HOME="${T}"
453 # @SEE CMAKE_BUILD_TYPE
454 if [[ ${CMAKE_BUILD_TYPE} = Gentoo ]]; then
455 # Handle release builds
456 if ! has debug ${IUSE//+} || ! use debug; then
457 local CPPFLAGS=${CPPFLAGS}
458 append-cppflags -DNDEBUG
462 # Prepare Gentoo override rules (set valid compiler, append CPPFLAGS etc.)
463 local build_rules=${BUILD_DIR}/gentoo_rules.cmake
464 # Since cmake-3.4.0_rc1 "<FLAGS>" no longer contains includes and thus
465 # we need to add "<INCLUDES>"
467 if [[ ${PN} == cmake ]] ; then
468 if $(version_is_at_least 3.4.0 $(get_version_component_range 1-3 ${PV})) ; then
469 includes="<INCLUDES>"
471 elif has_version \>=dev-util/cmake-3.4.0_rc1 ; then
472 includes="<INCLUDES>"
474 cat > "${build_rules}" <<- _EOF_ || die
475 SET (CMAKE_AR $(type -P $(tc-getAR)) CACHE FILEPATH "Archive manager" FORCE)
476 SET (CMAKE_ASM_COMPILE_OBJECT "<CMAKE_C_COMPILER> <DEFINES> ${includes} ${CFLAGS} <FLAGS> -o <OBJECT> -c <SOURCE>" CACHE STRING "ASM compile command" FORCE)
477 SET (CMAKE_C_COMPILE_OBJECT "<CMAKE_C_COMPILER> <DEFINES> ${includes} ${CPPFLAGS} <FLAGS> -o <OBJECT> -c <SOURCE>" CACHE STRING "C compile command" FORCE)
478 SET (CMAKE_CXX_COMPILE_OBJECT "<CMAKE_CXX_COMPILER> <DEFINES> ${includes} ${CPPFLAGS} <FLAGS> -o <OBJECT> -c <SOURCE>" CACHE STRING "C++ compile command" FORCE)
479 SET (CMAKE_Fortran_COMPILE_OBJECT "<CMAKE_Fortran_COMPILER> <DEFINES> ${includes} ${FCFLAGS} <FLAGS> -o <OBJECT> -c <SOURCE>" CACHE STRING "Fortran compile command" FORCE)
480 SET (CMAKE_RANLIB $(type -P $(tc-getRANLIB)) CACHE FILEPATH "Archive index generator" FORCE)
481 SET (PKG_CONFIG_EXECUTABLE $(type -P $(tc-getPKG_CONFIG)) CACHE FILEPATH "pkg-config executable" FORCE)
484 local toolchain_file=${BUILD_DIR}/gentoo_toolchain.cmake
485 cat > ${toolchain_file} <<- _EOF_ || die
486 SET (CMAKE_C_COMPILER $(tc-getCC))
487 SET (CMAKE_CXX_COMPILER $(tc-getCXX))
488 SET (CMAKE_Fortran_COMPILER $(tc-getFC))
491 if tc-is-cross-compiler; then
493 case "${KERNEL:-linux}" in
494 Cygwin) sysname="CYGWIN_NT-5.1" ;;
495 HPUX) sysname="HP-UX" ;;
496 linux) sysname="Linux" ;;
499 cat >> "${toolchain_file}" <<- _EOF_ || die
500 SET (CMAKE_RC_COMPILER $(tc-getRC))
503 *) sysname="${KERNEL}" ;;
506 cat >> "${toolchain_file}" <<- _EOF_ || die
507 SET (CMAKE_SYSTEM_NAME "${sysname}")
510 if [ "${SYSROOT:-/}" != "/" ] ; then
511 # When cross-compiling with a sysroot (e.g. with crossdev's emerge wrappers)
512 # we need to tell cmake to use libs/headers from the sysroot but programs from / only.
513 cat >> "${toolchain_file}" <<- _EOF_ || die
514 set(CMAKE_FIND_ROOT_PATH "${SYSROOT}")
515 set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
516 set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
517 set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
522 has "${EAPI:-0}" 0 1 2 && ! use prefix && EPREFIX=
524 if [[ ${EPREFIX} ]]; then
525 cat >> "${build_rules}" <<- _EOF_ || die
526 # in Prefix we need rpath and must ensure cmake gets our default linker path
527 # right ... except for Darwin hosts
529 SET (CMAKE_SKIP_RPATH OFF CACHE BOOL "" FORCE)
530 SET (CMAKE_PLATFORM_REQUIRED_RUNTIME_PATH "${EPREFIX}/usr/${CHOST}/lib/gcc;${EPREFIX}/usr/${CHOST}/lib;${EPREFIX}/usr/$(get_libdir);${EPREFIX}/$(get_libdir)"
531 CACHE STRING "" FORCE)
535 SET(CMAKE_PREFIX_PATH "${EPREFIX}${PREFIX}" CACHE STRING "" FORCE)
536 SET(CMAKE_SKIP_BUILD_RPATH OFF CACHE BOOL "" FORCE)
537 SET(CMAKE_SKIP_RPATH OFF CACHE BOOL "" FORCE)
538 SET(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE CACHE BOOL "")
539 SET(CMAKE_INSTALL_RPATH "${EPREFIX}${PREFIX}/lib;${EPREFIX}/usr/${CHOST}/lib/gcc;${EPREFIX}/usr/${CHOST}/lib;${EPREFIX}/usr/$(get_libdir);${EPREFIX}/$(get_libdir)" CACHE STRING "" FORCE)
540 SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE CACHE BOOL "" FORCE)
541 SET(CMAKE_INSTALL_NAME_DIR "${EPREFIX}${PREFIX}/lib" CACHE STRING "" FORCE)
547 # Common configure parameters (invariants)
548 local common_config=${BUILD_DIR}/gentoo_common_config.cmake
549 local libdir=$(get_libdir)
550 cat > "${common_config}" <<- _EOF_ || die
551 SET (LIB_SUFFIX ${libdir/lib} CACHE STRING "library path suffix" FORCE)
552 SET (CMAKE_INSTALL_LIBDIR ${libdir} CACHE PATH "Output directory for libraries")
554 [[ "${NOCOLOR}" = true || "${NOCOLOR}" = yes ]] && echo 'SET (CMAKE_COLOR_MAKEFILE OFF CACHE BOOL "pretty colors during make" FORCE)' >> "${common_config}"
556 # Convert mycmakeargs to an array, for backwards compatibility
557 # Make the array a local variable since <=portage-2.1.6.x does not
558 # support global arrays (see bug #297255).
559 if [[ $(declare -p mycmakeargs 2>&-) != "declare -a mycmakeargs="* ]]; then
560 eqawarn "Declaring mycmakeargs as a variable is deprecated. Please use an array instead."
561 local mycmakeargs_local=(${mycmakeargs})
563 local mycmakeargs_local=("${mycmakeargs[@]}")
566 if [[ ${CMAKE_WARN_UNUSED_CLI} == no ]] ; then
567 local warn_unused_cli="--no-warn-unused-cli"
569 local warn_unused_cli=""
572 # Common configure parameters (overridable)
573 # NOTE CMAKE_BUILD_TYPE can be only overriden via CMAKE_BUILD_TYPE eclass variable
574 # No -DCMAKE_BUILD_TYPE=xxx definitions will be in effect.
577 -C "${common_config}"
578 -G "$(_generator_to_use)"
579 -DCMAKE_INSTALL_PREFIX="${EPREFIX}${PREFIX}"
580 "${mycmakeargs_local[@]}"
581 -DCMAKE_BUILD_TYPE="${CMAKE_BUILD_TYPE}"
582 -DCMAKE_INSTALL_DO_STRIP=OFF
583 -DCMAKE_USER_MAKE_RULES_OVERRIDE="${build_rules}"
584 -DCMAKE_TOOLCHAIN_FILE="${toolchain_file}"
588 if [[ -n "${CMAKE_EXTRA_CACHE_FILE}" ]] ; then
589 cmakeargs+=( -C "${CMAKE_EXTRA_CACHE_FILE}" )
592 pushd "${BUILD_DIR}" > /dev/null || die
593 debug-print "${LINENO} ${ECLASS} ${FUNCNAME}: mycmakeargs is ${mycmakeargs_local[*]}"
594 echo "${CMAKE_BINARY}" "${cmakeargs[@]}" "${CMAKE_USE_DIR}"
595 "${CMAKE_BINARY}" "${cmakeargs[@]}" "${CMAKE_USE_DIR}" || die "cmake failed"
596 popd > /dev/null || die
599 enable_cmake-utils_src_compile() {
600 debug-print-function ${FUNCNAME} "$@"
602 cmake-utils_src_make "$@"
605 _ninjaopts_from_makeopts() {
606 if [[ ${NINJAOPTS+set} == set ]]; then
624 export NINJAOPTS="${ninjaopts[*]}"
627 # @FUNCTION: ninja_src_make
630 # Build the package using ninja generator
632 debug-print-function ${FUNCNAME} "$@"
634 [[ -e build.ninja ]] || die "build.ninja not found. Error during configure stage."
636 _ninjaopts_from_makeopts
638 if [[ "${CMAKE_VERBOSE}" != "OFF" ]]; then
639 set -- ninja ${NINJAOPTS} -v "$@"
641 set -- ninja ${NINJAOPTS} "$@"
648 # @FUNCTION: emake_src_make
651 # Build the package using make generator
653 debug-print-function ${FUNCNAME} "$@"
655 [[ -e Makefile ]] || die "Makefile not found. Error during configure stage."
657 if [[ "${CMAKE_VERBOSE}" != "OFF" ]]; then
658 emake VERBOSE=1 "$@" || die
665 # @FUNCTION: cmake-utils_src_make
667 # Function for building the package. Automatically detects the build type.
668 # All arguments are passed to emake.
669 cmake-utils_src_make() {
670 debug-print-function ${FUNCNAME} "$@"
673 pushd "${BUILD_DIR}" > /dev/null || die
675 ${CMAKE_MAKEFILE_GENERATOR}_src_make "$@"
677 popd > /dev/null || die
680 enable_cmake-utils_src_test() {
681 debug-print-function ${FUNCNAME} "$@"
684 pushd "${BUILD_DIR}" > /dev/null || die
685 [[ -e CTestTestfile.cmake ]] || { echo "No tests found. Skipping."; return 0 ; }
687 [[ -n ${TEST_VERBOSE} ]] && myctestargs+=( --extra-verbose --output-on-failure )
689 if ctest "${myctestargs[@]}" "$@" ; then
690 einfo "Tests succeeded."
691 popd > /dev/null || die
694 if [[ -n "${CMAKE_YES_I_WANT_TO_SEE_THE_TEST_LOG}" ]] ; then
695 # on request from Diego
696 eerror "Tests failed. Test log ${BUILD_DIR}/Testing/Temporary/LastTest.log follows:"
697 eerror "--START TEST LOG--------------------------------------------------------------"
698 cat "${BUILD_DIR}/Testing/Temporary/LastTest.log"
699 eerror "--END TEST LOG----------------------------------------------------------------"
702 die "Tests failed. When you file a bug, please attach the following file: \n\t${BUILD_DIR}/Testing/Temporary/LastTest.log"
705 # die might not die due to nonfatal
706 popd > /dev/null || die
711 enable_cmake-utils_src_install() {
712 debug-print-function ${FUNCNAME} "$@"
715 pushd "${BUILD_DIR}" > /dev/null || die
716 DESTDIR="${D}" ${CMAKE_MAKEFILE_GENERATOR} install "$@" || die "died running ${CMAKE_MAKEFILE_GENERATOR} install"
717 popd > /dev/null || die
719 pushd "${S}" > /dev/null || die
721 popd > /dev/null || die
724 # @FUNCTION: cmake-utils_src_prepare
726 # Apply ebuild and user patches.
727 cmake-utils_src_prepare() {
728 _execute_optionally "src_prepare" "$@"
731 # @FUNCTION: cmake-utils_src_configure
733 # General function for configuring with cmake. Default behaviour is to start an
734 # out-of-source build.
735 cmake-utils_src_configure() {
736 _execute_optionally "src_configure" "$@"
739 # @FUNCTION: cmake-utils_src_compile
741 # General function for compiling with cmake.
742 # Automatically detects the build type. All arguments are passed to emake.
743 cmake-utils_src_compile() {
744 _execute_optionally "src_compile" "$@"
747 # @FUNCTION: cmake-utils_src_test
749 # Function for testing the package. Automatically detects the build type.
750 cmake-utils_src_test() {
751 _execute_optionally "src_test" "$@"
754 # @FUNCTION: cmake-utils_src_install
756 # Function for installing the package. Automatically detects the build type.
757 cmake-utils_src_install() {
758 _execute_optionally "src_install" "$@"
761 # Optionally executes phases based on WANT_CMAKE variable/USE flag.
762 _execute_optionally() {
763 local phase="$1" ; shift
764 if [[ ${WANT_CMAKE} = always ]]; then
765 enable_cmake-utils_${phase} "$@"
767 use ${WANT_CMAKE} && enable_cmake-utils_${phase} "$@"