1 # Copyright 1999-2020 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
4 # @ECLASS: cmake.eclass
8 # Tomáš Chvátal <scarabeus@gentoo.org>
9 # Maciej Mrozowski <reavertm@gentoo.org>
10 # (undisclosed contributors)
11 # Original author: Zephyrus (zephyrus@mirach.it)
13 # @BLURB: common ebuild functions for cmake-based packages
15 # The cmake eclass makes creating ebuilds for cmake-based packages much easier.
16 # It provides all inherited features (DOCS, HTML_DOCS, PATCHES) along with
17 # out-of-source builds (default), in-source builds and an implementation of the
18 # well-known use_enable function for CMake.
20 if [[ -z ${_CMAKE_ECLASS} ]]; then
23 # @ECLASS-VARIABLE: BUILD_DIR
25 # Build directory where all cmake processed files should be generated.
26 # For in-source build it's fixed to ${CMAKE_USE_DIR}.
27 # For out-of-source build it can be overridden, by default it uses
28 # ${WORKDIR}/${P}_build.
29 : ${BUILD_DIR:=${WORKDIR}/${P}_build}
31 # @ECLASS-VARIABLE: CMAKE_BINARY
33 # Eclass can use different cmake binary than the one provided in by system.
34 : ${CMAKE_BINARY:=cmake}
36 # @ECLASS-VARIABLE: CMAKE_BUILD_TYPE
38 # Set to override default CMAKE_BUILD_TYPE. Only useful for packages
39 # known to make use of "if (CMAKE_BUILD_TYPE MATCHES xxx)".
40 # If about to be set - needs to be set before invoking cmake_src_configure.
41 # You usually do *NOT* want nor need to set it as it pulls CMake default
42 # build-type specific compiler flags overriding make.conf.
43 : ${CMAKE_BUILD_TYPE:=Gentoo}
45 # @ECLASS-VARIABLE: CMAKE_IN_SOURCE_BUILD
48 # Set to enable in-source build.
50 # @ECLASS-VARIABLE: CMAKE_MAKEFILE_GENERATOR
53 # Specify a makefile generator to be used by cmake.
54 # At this point only "emake" and "ninja" are supported.
55 # The default is set to "ninja".
56 : ${CMAKE_MAKEFILE_GENERATOR:=ninja}
58 # @ECLASS-VARIABLE: CMAKE_REMOVE_MODULES_LIST
60 # Array of CMake modules that will be removed in $S during src_prepare,
61 # in order to force packages to use the system version.
62 # Set to "none" to disable removing modules entirely.
63 : ${CMAKE_REMOVE_MODULES_LIST:=FindBLAS FindLAPACK}
65 # @ECLASS-VARIABLE: CMAKE_USE_DIR
67 # Sets the directory where we are working with cmake, for example when
68 # application uses autotools and only one plugin needs to be done by cmake.
69 # By default it uses ${S}.
71 # @ECLASS-VARIABLE: CMAKE_VERBOSE
73 # Set to OFF to disable verbose messages during compilation
74 : ${CMAKE_VERBOSE:=ON}
76 # @ECLASS-VARIABLE: CMAKE_WARN_UNUSED_CLI
78 # Warn about variables that are declared on the command line
79 # but not used. Might give false-positives.
80 # "no" to disable (default) or anything else to enable.
81 : ${CMAKE_WARN_UNUSED_CLI:=yes}
83 # @ECLASS-VARIABLE: CMAKE_EXTRA_CACHE_FILE
86 # Specifies an extra cache file to pass to cmake. This is the analog of EXTRA_ECONF
87 # for econf and is needed to pass TRY_RUN results when cross-compiling.
88 # Should be set by user in a per-package basis in /etc/portage/package.env.
90 # @ECLASS-VARIABLE: CMAKE_QA_SRC_DIR_READONLY
93 # After running cmake_src_prepare, sets ${S} to read-only. This is
94 # a user flag and should under _no circumstances_ be set in the ebuild.
95 # Helps in improving QA of build systems that write to source tree.
99 *) die "EAPI=${EAPI:-0} is not supported" ;;
102 inherit toolchain-funcs ninja-utils flag-o-matic multiprocessing xdg-utils
104 EXPORT_FUNCTIONS src_prepare src_configure src_compile src_test src_install
106 [[ ${CMAKE_MIN_VERSION} ]] && die "CMAKE_MIN_VERSION is banned; if necessary, set BDEPEND=\">=dev-util/cmake-${CMAKE_MIN_VERSION}\" directly"
107 [[ ${CMAKE_BUILD_DIR} ]] && die "The ebuild must be migrated to BUILD_DIR"
108 [[ ${CMAKE_REMOVE_MODULES} ]] && die "CMAKE_REMOVE_MODULES is banned, set CMAKE_REMOVE_MODULES_LIST=\"\" instead"
109 [[ ${CMAKE_UTILS_QA_SRC_DIR_READONLY} ]] && die "Use CMAKE_QA_SRC_DIR_READONLY instead"
110 [[ ${WANT_CMAKE} ]] && die "WANT_CMAKE has been removed and is a no-op"
111 [[ ${PREFIX} ]] && die "PREFIX has been removed and is a no-op"
113 case ${CMAKE_MAKEFILE_GENERATOR} in
115 BDEPEND="sys-devel/make"
118 BDEPEND="dev-util/ninja"
121 eerror "Unknown value for \${CMAKE_MAKEFILE_GENERATOR}"
122 die "Value ${CMAKE_MAKEFILE_GENERATOR} is not supported"
126 if [[ ${PN} != cmake ]]; then
127 BDEPEND+=" dev-util/cmake"
130 # @FUNCTION: _cmake_banned_func
133 # Banned functions are banned.
134 _cmake_banned_func() {
135 die "${FUNCNAME[1]} is banned. use -D$1<related_CMake_variable>=\"\$(usex $2)\" instead"
138 # Determine using IN or OUT source build
139 _cmake_check_build_dir() {
140 : ${CMAKE_USE_DIR:=${S}}
141 if [[ -n ${CMAKE_IN_SOURCE_BUILD} ]]; then
142 # we build in source dir
143 BUILD_DIR="${CMAKE_USE_DIR}"
146 mkdir -p "${BUILD_DIR}" || die
147 einfo "Working in BUILD_DIR: \"$BUILD_DIR\""
150 # @FUNCTION: cmake_comment_add_subdirectory
151 # @USAGE: <subdirectory>
153 # Comment out one or more add_subdirectory calls in CMakeLists.txt in the current directory
154 cmake_comment_add_subdirectory() {
155 if [[ -z ${1} ]]; then
156 die "comment_add_subdirectory must be passed at least one directory name to comment"
159 if [[ -e "CMakeLists.txt" ]]; then
162 sed -e "/add_subdirectory[[:space:]]*([[:space:]]*${d//\//\\/}[[:space:]]*)/I s/^/#DONOTCOMPILE /" \
163 -i CMakeLists.txt || die "failed to comment add_subdirectory(${d})"
168 # @FUNCTION: comment_add_subdirectory
171 # Banned. Use cmake_comment_add_subdirectory instead.
172 comment_add_subdirectory() {
173 die "comment_add_subdirectory is banned. Use cmake_comment_add_subdirectory instead"
176 # @FUNCTION: cmake-utils_use_with
179 # Banned. Use -DWITH_FOO=$(usex foo) instead.
180 cmake-utils_use_with() { _cmake_banned_func WITH_ "$@" ; }
182 # @FUNCTION: cmake-utils_use_enable
185 # Banned. Use -DENABLE_FOO=$(usex foo) instead.
186 cmake-utils_use_enable() { _cmake_banned_func ENABLE_ "$@" ; }
188 # @FUNCTION: cmake_use_find_package
189 # @USAGE: <USE flag> <package name>
191 # Based on use_enable. See ebuild(5).
193 # `cmake_use_find_package foo LibFoo` echoes -DCMAKE_DISABLE_FIND_PACKAGE_LibFoo=OFF
194 # if foo is enabled and -DCMAKE_DISABLE_FIND_PACKAGE_LibFoo=ON if it is disabled.
195 # This can be used to make find_package optional.
196 cmake_use_find_package() {
197 debug-print-function ${FUNCNAME} "$@"
199 if [[ "$#" != 2 || -z $1 ]] ; then
200 die "Usage: cmake_use_find_package <USE flag> <package name>"
203 echo "-DCMAKE_DISABLE_FIND_PACKAGE_$2=$(use $1 && echo OFF || echo ON)"
206 # @FUNCTION: cmake-utils_use_disable
209 # Banned. Use -DDISABLE_FOO=$(usex !foo) instead.
210 cmake-utils_use_disable() { _cmake_banned_func DISABLE_ "$@" ; }
212 # @FUNCTION: cmake-utils_use_no
215 # Banned. Use -DNO_FOO=$(usex !foo) instead.
216 cmake-utils_use_no() { _cmake_banned_func NO_ "$@" ; }
218 # @FUNCTION: cmake-utils_use_want
221 # Banned. Use -DWANT_FOO=$(usex foo) instead.
222 cmake-utils_use_want() { _cmake_banned_func WANT_ "$@" ; }
224 # @FUNCTION: cmake-utils_use_build
227 # Banned. Use -DBUILD_FOO=$(usex foo) instead.
228 cmake-utils_use_build() { _cmake_banned_func BUILD_ "$@" ; }
230 # @FUNCTION: cmake-utils_use_has
233 # Banned. Use -DHAVE_FOO=$(usex foo) instead.
234 cmake-utils_use_has() { _cmake_banned_func HAVE_ "$@" ; }
236 # @FUNCTION: cmake-utils_use_use
239 # Banned. Use -DUSE_FOO=$(usex foo) instead.
240 cmake-utils_use_use() { _cmake_banned_func USE_ "$@" ; }
242 # @FUNCTION: cmake-utils_use
245 # Banned. Use -DFOO=$(usex foo) instead.
246 cmake-utils_use() { _cmake_banned_func "" "$@" ; }
248 # @FUNCTION: cmake-utils_useno
251 # Banned. Use -DNOFOO=$(usex !foo) instead.
252 cmake-utils_useno() { _cmake_banned_func "" "$@" ; }
254 # Internal function for modifying hardcoded definitions.
255 # Removes dangerous definitions that override Gentoo settings.
256 _cmake_modify-cmakelists() {
257 debug-print-function ${FUNCNAME} "$@"
259 # Only edit the files once
260 grep -qs "<<< Gentoo configuration >>>" "${CMAKE_USE_DIR}"/CMakeLists.txt && return 0
262 # Comment out all set (<some_should_be_user_defined_variable> value)
263 find "${CMAKE_USE_DIR}" -name CMakeLists.txt -exec sed \
264 -e '/^[[:space:]]*set[[:space:]]*([[:space:]]*CMAKE_BUILD_TYPE\([[:space:]].*)\|)\)/I{s/^/#_cmake_modify_IGNORE /g}' \
265 -e '/^[[:space:]]*set[[:space:]]*([[:space:]]*CMAKE_COLOR_MAKEFILE[[:space:]].*)/I{s/^/#_cmake_modify_IGNORE /g}' \
266 -e '/^[[:space:]]*set[[:space:]]*([[:space:]]*CMAKE_INSTALL_PREFIX[[:space:]].*)/I{s/^/#_cmake_modify_IGNORE /g}' \
267 -e '/^[[:space:]]*set[[:space:]]*([[:space:]]*CMAKE_VERBOSE_MAKEFILE[[:space:]].*)/I{s/^/#_cmake_modify_IGNORE /g}' \
268 -i {} + || die "${LINENO}: failed to disable hardcoded settings"
270 for x in $(find "${CMAKE_USE_DIR}" -name CMakeLists.txt -exec grep -l "^#_cmake_modify_IGNORE" {} +;); do
271 einfo "Hardcoded definition(s) removed in $(echo "${x}" | cut -c $((${#CMAKE_USE_DIR}+2))-):"
272 einfo "$(grep -se '^#_cmake_modify_IGNORE' ${x} | cut -c 22-99)"
275 # NOTE Append some useful summary here
276 cat >> "${CMAKE_USE_DIR}"/CMakeLists.txt <<- _EOF_ || die
278 MESSAGE(STATUS "<<< Gentoo configuration >>>
279 Build type \${CMAKE_BUILD_TYPE}
280 Install path \${CMAKE_INSTALL_PREFIX}
283 C++ \${CMAKE_CXX_FLAGS}
285 Executable \${CMAKE_EXE_LINKER_FLAGS}
286 Module \${CMAKE_MODULE_LINKER_FLAGS}
287 Shared \${CMAKE_SHARED_LINKER_FLAGS}\n")
291 # @FUNCTION: cmake_src_prepare
293 # Apply ebuild and user patches.
294 cmake_src_prepare() {
295 debug-print-function ${FUNCNAME} "$@"
297 # FIXME: workaround from cmake-utils; use current working directory instead, bug #704524
298 # esp. test with 'special' pkgs like: app-arch/brotli, media-gfx/gmic, net-libs/quiche
299 pushd "${S}" > /dev/null || die
302 _cmake_check_build_dir
304 # check if CMakeLists.txt exist and if no then die
305 if [[ ! -e ${CMAKE_USE_DIR}/CMakeLists.txt ]] ; then
306 eerror "Unable to locate CMakeLists.txt under:"
307 eerror "\"${CMAKE_USE_DIR}/CMakeLists.txt\""
308 eerror "Consider not inheriting the cmake eclass."
309 die "FATAL: Unable to find CMakeLists.txt"
312 # if ninja is enabled but not installed, the build could fail
313 # this could happen if ninja is manually enabled (eg. make.conf) but not installed
314 if [[ ${CMAKE_MAKEFILE_GENERATOR} == ninja ]] && ! has_version -b dev-util/ninja; then
315 eerror "CMAKE_MAKEFILE_GENERATOR is set to ninja, but ninja is not installed."
316 die "Please install dev-util/ninja or unset CMAKE_MAKEFILE_GENERATOR."
320 if [[ $(declare -p CMAKE_REMOVE_MODULES_LIST) == "declare -a"* ]]; then
321 modules_list=( "${CMAKE_REMOVE_MODULES_LIST[@]}" )
323 modules_list=( ${CMAKE_REMOVE_MODULES_LIST} )
327 for name in "${modules_list[@]}" ; do
328 find "${S}" -name ${name}.cmake -exec rm -v {} + || die
331 # Remove dangerous things.
332 _cmake_modify-cmakelists
334 popd > /dev/null || die
336 # make ${S} read-only in order to detect broken build-systems
337 if [[ ${CMAKE_QA_SRC_DIR_READONLY} && ! ${CMAKE_IN_SOURCE_BUILD} ]]; then
341 _CMAKE_SRC_PREPARE_HAS_RUN=1
344 # @VARIABLE: mycmakeargs
347 # Optional cmake defines as a bash array. Should be defined before calling
351 # local mycmakeargs=(
352 # $(cmake_use_with openconnect)
355 # cmake_src_configure
359 # @FUNCTION: cmake_src_configure
361 # General function for configuring with cmake. Default behaviour is to start an
362 # out-of-source build.
363 cmake_src_configure() {
364 debug-print-function ${FUNCNAME} "$@"
366 [[ ${_CMAKE_SRC_PREPARE_HAS_RUN} ]] || \
367 die "FATAL: cmake_src_prepare has not been run"
369 _cmake_check_build_dir
371 # Fix xdg collision with sandbox
372 xdg_environment_reset
374 # Prepare Gentoo override rules (set valid compiler, append CPPFLAGS etc.)
375 local build_rules=${BUILD_DIR}/gentoo_rules.cmake
377 cat > "${build_rules}" <<- _EOF_ || die
378 SET (CMAKE_ASM_COMPILE_OBJECT "<CMAKE_ASM_COMPILER> <DEFINES> <INCLUDES> ${CPPFLAGS} <FLAGS> -o <OBJECT> -c <SOURCE>" CACHE STRING "ASM compile command" FORCE)
379 SET (CMAKE_ASM-ATT_COMPILE_OBJECT "<CMAKE_ASM-ATT_COMPILER> <DEFINES> <INCLUDES> ${CPPFLAGS} <FLAGS> -o <OBJECT> -c -x assembler <SOURCE>" CACHE STRING "ASM-ATT compile command" FORCE)
380 SET (CMAKE_ASM-ATT_LINK_FLAGS "-nostdlib" CACHE STRING "ASM-ATT link flags" FORCE)
381 SET (CMAKE_C_COMPILE_OBJECT "<CMAKE_C_COMPILER> <DEFINES> <INCLUDES> ${CPPFLAGS} <FLAGS> -o <OBJECT> -c <SOURCE>" CACHE STRING "C compile command" FORCE)
382 SET (CMAKE_CXX_COMPILE_OBJECT "<CMAKE_CXX_COMPILER> <DEFINES> <INCLUDES> ${CPPFLAGS} <FLAGS> -o <OBJECT> -c <SOURCE>" CACHE STRING "C++ compile command" FORCE)
383 SET (CMAKE_Fortran_COMPILE_OBJECT "<CMAKE_Fortran_COMPILER> <DEFINES> <INCLUDES> ${FCFLAGS} <FLAGS> -o <OBJECT> -c <SOURCE>" CACHE STRING "Fortran compile command" FORCE)
386 local myCC=$(tc-getCC) myCXX=$(tc-getCXX) myFC=$(tc-getFC)
388 # !!! IMPORTANT NOTE !!!
389 # Single slash below is intentional. CMake is weird and wants the
390 # CMAKE_*_VARIABLES split into two elements: the first one with
391 # compiler path, and the second one with all command-line options,
393 local toolchain_file=${BUILD_DIR}/gentoo_toolchain.cmake
394 cat > ${toolchain_file} <<- _EOF_ || die
395 SET (CMAKE_ASM_COMPILER "${myCC/ /;}")
396 SET (CMAKE_ASM-ATT_COMPILER "${myCC/ /;}")
397 SET (CMAKE_C_COMPILER "${myCC/ /;}")
398 SET (CMAKE_CXX_COMPILER "${myCXX/ /;}")
399 SET (CMAKE_Fortran_COMPILER "${myFC/ /;}")
400 SET (CMAKE_AR $(type -P $(tc-getAR)) CACHE FILEPATH "Archive manager" FORCE)
401 SET (CMAKE_RANLIB $(type -P $(tc-getRANLIB)) CACHE FILEPATH "Archive index generator" FORCE)
402 SET (CMAKE_SYSTEM_PROCESSOR "${CHOST%%-*}")
405 # We are using the C compiler for assembly by default.
406 local -x ASMFLAGS=${CFLAGS}
407 local -x PKG_CONFIG=$(tc-getPKG_CONFIG)
409 if tc-is-cross-compiler; then
411 case "${KERNEL:-linux}" in
412 Cygwin) sysname="CYGWIN_NT-5.1" ;;
413 HPUX) sysname="HP-UX" ;;
414 linux) sysname="Linux" ;;
417 cat >> "${toolchain_file}" <<- _EOF_ || die
418 SET (CMAKE_RC_COMPILER $(tc-getRC))
421 *) sysname="${KERNEL}" ;;
424 cat >> "${toolchain_file}" <<- _EOF_ || die
425 SET (CMAKE_SYSTEM_NAME "${sysname}")
428 if [ "${SYSROOT:-/}" != "/" ] ; then
429 # When cross-compiling with a sysroot (e.g. with crossdev's emerge wrappers)
430 # we need to tell cmake to use libs/headers from the sysroot but programs from / only.
431 cat >> "${toolchain_file}" <<- _EOF_ || die
432 SET (CMAKE_FIND_ROOT_PATH "${SYSROOT}")
433 SET (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
434 SET (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
435 SET (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
440 if use prefix-guest; then
441 cat >> "${build_rules}" <<- _EOF_ || die
442 # in Prefix we need rpath and must ensure cmake gets our default linker path
443 # right ... except for Darwin hosts
445 SET (CMAKE_SKIP_RPATH OFF CACHE BOOL "" FORCE)
446 SET (CMAKE_PLATFORM_REQUIRED_RUNTIME_PATH "${EPREFIX}/usr/${CHOST}/lib/gcc;${EPREFIX}/usr/${CHOST}/lib;${EPREFIX}/usr/$(get_libdir);${EPREFIX}/$(get_libdir)"
447 CACHE STRING "" FORCE)
451 SET (CMAKE_PREFIX_PATH "${EPREFIX}/usr" CACHE STRING "" FORCE)
452 SET (CMAKE_MACOSX_RPATH ON CACHE BOOL "" FORCE)
453 SET (CMAKE_SKIP_BUILD_RPATH OFF CACHE BOOL "" FORCE)
454 SET (CMAKE_SKIP_RPATH OFF CACHE BOOL "" FORCE)
455 SET (CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE CACHE BOOL "" FORCE)
461 # Common configure parameters (invariants)
462 local common_config=${BUILD_DIR}/gentoo_common_config.cmake
463 local libdir=$(get_libdir)
464 cat > "${common_config}" <<- _EOF_ || die
465 SET (CMAKE_GENTOO_BUILD ON CACHE BOOL "Indicate Gentoo package build")
466 SET (LIB_SUFFIX ${libdir/lib} CACHE STRING "library path suffix" FORCE)
467 SET (CMAKE_INSTALL_LIBDIR ${libdir} CACHE PATH "Output directory for libraries")
468 SET (CMAKE_INSTALL_INFODIR "${EPREFIX}/usr/share/info" CACHE PATH "")
469 SET (CMAKE_INSTALL_MANDIR "${EPREFIX}/usr/share/man" CACHE PATH "")
470 SET (CMAKE_USER_MAKE_RULES_OVERRIDE "${build_rules}" CACHE FILEPATH "Gentoo override rules")
471 SET (CMAKE_INSTALL_DOCDIR "${EPREFIX}/usr/share/doc/${PF}" CACHE PATH "")
472 SET (BUILD_SHARED_LIBS ON CACHE BOOL "")
474 if [[ "${NOCOLOR}" = true || "${NOCOLOR}" = yes ]]; then
475 echo 'SET (CMAKE_COLOR_MAKEFILE OFF CACHE BOOL "pretty colors during make" FORCE)' >> "${common_config}" || die
478 # Wipe the default optimization flags out of CMake
479 if [[ ${CMAKE_BUILD_TYPE} != Gentoo ]]; then
480 cat >> ${common_config} <<- _EOF_ || die
481 SET (CMAKE_ASM_FLAGS_${CMAKE_BUILD_TYPE^^} "" CACHE STRING "")
482 SET (CMAKE_ASM-ATT_FLAGS_${CMAKE_BUILD_TYPE^^} "" CACHE STRING "")
483 SET (CMAKE_C_FLAGS_${CMAKE_BUILD_TYPE^^} "" CACHE STRING "")
484 SET (CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE^^} "" CACHE STRING "")
485 SET (CMAKE_Fortran_FLAGS_${CMAKE_BUILD_TYPE^^} "" CACHE STRING "")
486 SET (CMAKE_EXE_LINKER_FLAGS_${CMAKE_BUILD_TYPE^^} "" CACHE STRING "")
487 SET (CMAKE_MODULE_LINKER_FLAGS_${CMAKE_BUILD_TYPE^^} "" CACHE STRING "")
488 SET (CMAKE_SHARED_LINKER_FLAGS_${CMAKE_BUILD_TYPE^^} "" CACHE STRING "")
489 SET (CMAKE_STATIC_LINKER_FLAGS_${CMAKE_BUILD_TYPE^^} "" CACHE STRING "")
493 # Make the array a local variable since <=portage-2.1.6.x does not support
494 # global arrays (see bug #297255). But first make sure it is initialised.
495 [[ -z ${mycmakeargs} ]] && declare -a mycmakeargs=()
496 local mycmakeargstype=$(declare -p mycmakeargs 2>&-)
497 if [[ "${mycmakeargstype}" != "declare -a mycmakeargs="* ]]; then
498 die "mycmakeargs must be declared as array"
501 local mycmakeargs_local=( "${mycmakeargs[@]}" )
503 local warn_unused_cli=""
504 if [[ ${CMAKE_WARN_UNUSED_CLI} == no ]] ; then
505 warn_unused_cli="--no-warn-unused-cli"
509 case ${CMAKE_MAKEFILE_GENERATOR} in
510 ninja) generator_name="Ninja" ;;
511 emake) generator_name="Unix Makefiles" ;;
514 # Common configure parameters (overridable)
515 # NOTE CMAKE_BUILD_TYPE can be only overridden via CMAKE_BUILD_TYPE eclass variable
516 # No -DCMAKE_BUILD_TYPE=xxx definitions will be in effect.
519 -C "${common_config}"
520 -G "${generator_name}"
521 -DCMAKE_INSTALL_PREFIX="${EPREFIX}/usr"
522 "${mycmakeargs_local[@]}"
523 -DCMAKE_BUILD_TYPE="${CMAKE_BUILD_TYPE}"
524 -DCMAKE_TOOLCHAIN_FILE="${toolchain_file}"
528 if [[ -n "${CMAKE_EXTRA_CACHE_FILE}" ]] ; then
529 cmakeargs+=( -C "${CMAKE_EXTRA_CACHE_FILE}" )
532 pushd "${BUILD_DIR}" > /dev/null || die
533 debug-print "${LINENO} ${ECLASS} ${FUNCNAME}: mycmakeargs is ${mycmakeargs_local[*]}"
534 echo "${CMAKE_BINARY}" "${cmakeargs[@]}" "${CMAKE_USE_DIR}"
535 "${CMAKE_BINARY}" "${cmakeargs[@]}" "${CMAKE_USE_DIR}" || die "cmake failed"
536 popd > /dev/null || die
539 # @FUNCTION: cmake_src_compile
541 # General function for compiling with cmake.
542 # Automatically detects the build type. All arguments are passed to emake.
543 cmake_src_compile() {
544 debug-print-function ${FUNCNAME} "$@"
549 # @FUNCTION: cmake_build
551 # Function for building the package. Automatically detects the build type.
552 # All arguments are passed to emake.
554 debug-print-function ${FUNCNAME} "$@"
556 _cmake_check_build_dir
557 pushd "${BUILD_DIR}" > /dev/null || die
559 case ${CMAKE_MAKEFILE_GENERATOR} in
561 [[ -e Makefile ]] || die "Makefile not found. Error during configure stage."
562 case ${CMAKE_VERBOSE} in
564 *) emake VERBOSE=1 "$@" ;;
568 [[ -e build.ninja ]] || die "build.ninja not found. Error during configure stage."
573 popd > /dev/null || die
576 # @FUNCTION: cmake-utils_src_make
579 # Banned. Use cmake_build instead.
580 cmake-utils_src_make() {
581 die "cmake-utils_src_make is banned. Use cmake_build instead"
584 # @FUNCTION: cmake_src_test
586 # Function for testing the package. Automatically detects the build type.
588 debug-print-function ${FUNCNAME} "$@"
590 _cmake_check_build_dir
591 pushd "${BUILD_DIR}" > /dev/null || die
592 [[ -e CTestTestfile.cmake ]] || { echo "No tests found. Skipping."; return 0 ; }
594 [[ -n ${TEST_VERBOSE} ]] && myctestargs+=( --extra-verbose --output-on-failure )
596 set -- ctest -j "$(makeopts_jobs)" --test-load "$(makeopts_loadavg)" "${myctestargs[@]}" "$@"
599 einfo "Tests succeeded."
600 popd > /dev/null || die
603 if [[ -n "${CMAKE_YES_I_WANT_TO_SEE_THE_TEST_LOG}" ]] ; then
604 # on request from Diego
605 eerror "Tests failed. Test log ${BUILD_DIR}/Testing/Temporary/LastTest.log follows:"
606 eerror "--START TEST LOG--------------------------------------------------------------"
607 cat "${BUILD_DIR}/Testing/Temporary/LastTest.log"
608 eerror "--END TEST LOG----------------------------------------------------------------"
611 die "Tests failed. When you file a bug, please attach the following file: \n\t${BUILD_DIR}/Testing/Temporary/LastTest.log"
614 # die might not die due to nonfatal
615 popd > /dev/null || die
620 # @FUNCTION: cmake_src_install
622 # Function for installing the package. Automatically detects the build type.
623 cmake_src_install() {
624 debug-print-function ${FUNCNAME} "$@"
626 _cmake_check_build_dir
627 pushd "${BUILD_DIR}" > /dev/null || die
628 DESTDIR="${D}" ${CMAKE_MAKEFILE_GENERATOR} install "$@" ||
629 die "died running ${CMAKE_MAKEFILE_GENERATOR} install"
630 popd > /dev/null || die
632 pushd "${S}" > /dev/null || die
634 popd > /dev/null || die