1 # Copyright 1999-2019 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 pushd "${S}" > /dev/null || die
300 _cmake_check_build_dir
302 # check if CMakeLists.txt exist and if no then die
303 if [[ ! -e ${CMAKE_USE_DIR}/CMakeLists.txt ]] ; then
304 eerror "Unable to locate CMakeLists.txt under:"
305 eerror "\"${CMAKE_USE_DIR}/CMakeLists.txt\""
306 eerror "Consider not inheriting the cmake eclass."
307 die "FATAL: Unable to find CMakeLists.txt"
310 # if ninja is enabled but not installed, the build could fail
311 # this could happen if ninja is manually enabled (eg. make.conf) but not installed
312 if [[ ${CMAKE_MAKEFILE_GENERATOR} == ninja ]] && ! has_version -b dev-util/ninja; then
313 eerror "CMAKE_MAKEFILE_GENERATOR is set to ninja, but ninja is not installed."
314 die "Please install dev-util/ninja or unset CMAKE_MAKEFILE_GENERATOR."
318 if [[ $(declare -p CMAKE_REMOVE_MODULES_LIST) == "declare -a"* ]]; then
319 modules_list=( "${CMAKE_REMOVE_MODULES_LIST[@]}" )
321 modules_list=( ${CMAKE_REMOVE_MODULES_LIST} )
325 for name in "${modules_list[@]}" ; do
326 find "${S}" -name ${name}.cmake -exec rm -v {} + || die
329 # Remove dangerous things.
330 _cmake_modify-cmakelists
332 popd > /dev/null || die
334 # make ${S} read-only in order to detect broken build-systems
335 if [[ ${CMAKE_QA_SRC_DIR_READONLY} && ! ${CMAKE_IN_SOURCE_BUILD} ]]; then
339 _CMAKE_SRC_PREPARE_HAS_RUN=1
342 # @VARIABLE: mycmakeargs
345 # Optional cmake defines as a bash array. Should be defined before calling
349 # local mycmakeargs=(
350 # $(cmake_use_with openconnect)
353 # cmake_src_configure
357 # @FUNCTION: cmake_src_configure
359 # General function for configuring with cmake. Default behaviour is to start an
360 # out-of-source build.
361 cmake_src_configure() {
362 debug-print-function ${FUNCNAME} "$@"
364 [[ ${_CMAKE_SRC_PREPARE_HAS_RUN} ]] || \
365 die "FATAL: cmake_src_prepare has not been run"
367 _cmake_check_build_dir
369 # Fix xdg collision with sandbox
370 xdg_environment_reset
372 # @SEE CMAKE_BUILD_TYPE
373 if [[ ${CMAKE_BUILD_TYPE} = Gentoo ]]; then
374 # Handle release builds
375 if ! in_iuse debug || ! use debug; then
376 local CPPFLAGS=${CPPFLAGS}
377 append-cppflags -DNDEBUG
381 # Prepare Gentoo override rules (set valid compiler, append CPPFLAGS etc.)
382 local build_rules=${BUILD_DIR}/gentoo_rules.cmake
384 cat > "${build_rules}" <<- _EOF_ || die
385 SET (CMAKE_ASM_COMPILE_OBJECT "<CMAKE_ASM_COMPILER> <DEFINES> <INCLUDES> ${CPPFLAGS} <FLAGS> -o <OBJECT> -c <SOURCE>" CACHE STRING "ASM compile command" FORCE)
386 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)
387 SET (CMAKE_ASM-ATT_LINK_FLAGS "-nostdlib" CACHE STRING "ASM-ATT link flags" FORCE)
388 SET (CMAKE_C_COMPILE_OBJECT "<CMAKE_C_COMPILER> <DEFINES> <INCLUDES> ${CPPFLAGS} <FLAGS> -o <OBJECT> -c <SOURCE>" CACHE STRING "C compile command" FORCE)
389 SET (CMAKE_CXX_COMPILE_OBJECT "<CMAKE_CXX_COMPILER> <DEFINES> <INCLUDES> ${CPPFLAGS} <FLAGS> -o <OBJECT> -c <SOURCE>" CACHE STRING "C++ compile command" FORCE)
390 SET (CMAKE_Fortran_COMPILE_OBJECT "<CMAKE_Fortran_COMPILER> <DEFINES> <INCLUDES> ${FCFLAGS} <FLAGS> -o <OBJECT> -c <SOURCE>" CACHE STRING "Fortran compile command" FORCE)
393 local myCC=$(tc-getCC) myCXX=$(tc-getCXX) myFC=$(tc-getFC)
395 # !!! IMPORTANT NOTE !!!
396 # Single slash below is intentional. CMake is weird and wants the
397 # CMAKE_*_VARIABLES split into two elements: the first one with
398 # compiler path, and the second one with all command-line options,
400 local toolchain_file=${BUILD_DIR}/gentoo_toolchain.cmake
401 cat > ${toolchain_file} <<- _EOF_ || die
402 SET (CMAKE_ASM_COMPILER "${myCC/ /;}")
403 SET (CMAKE_ASM-ATT_COMPILER "${myCC/ /;}")
404 SET (CMAKE_C_COMPILER "${myCC/ /;}")
405 SET (CMAKE_CXX_COMPILER "${myCXX/ /;}")
406 SET (CMAKE_Fortran_COMPILER "${myFC/ /;}")
407 SET (CMAKE_AR $(type -P $(tc-getAR)) CACHE FILEPATH "Archive manager" FORCE)
408 SET (CMAKE_RANLIB $(type -P $(tc-getRANLIB)) CACHE FILEPATH "Archive index generator" FORCE)
409 SET (CMAKE_SYSTEM_PROCESSOR "${CHOST%%-*}")
412 # We are using the C compiler for assembly by default.
413 local -x ASMFLAGS=${CFLAGS}
414 local -x PKG_CONFIG=$(tc-getPKG_CONFIG)
416 if tc-is-cross-compiler; then
418 case "${KERNEL:-linux}" in
419 Cygwin) sysname="CYGWIN_NT-5.1" ;;
420 HPUX) sysname="HP-UX" ;;
421 linux) sysname="Linux" ;;
424 cat >> "${toolchain_file}" <<- _EOF_ || die
425 SET (CMAKE_RC_COMPILER $(tc-getRC))
428 *) sysname="${KERNEL}" ;;
431 cat >> "${toolchain_file}" <<- _EOF_ || die
432 SET (CMAKE_SYSTEM_NAME "${sysname}")
435 if [ "${SYSROOT:-/}" != "/" ] ; then
436 # When cross-compiling with a sysroot (e.g. with crossdev's emerge wrappers)
437 # we need to tell cmake to use libs/headers from the sysroot but programs from / only.
438 cat >> "${toolchain_file}" <<- _EOF_ || die
439 SET (CMAKE_FIND_ROOT_PATH "${SYSROOT}")
440 SET (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
441 SET (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
442 SET (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
447 if use prefix-guest; then
448 cat >> "${build_rules}" <<- _EOF_ || die
449 # in Prefix we need rpath and must ensure cmake gets our default linker path
450 # right ... except for Darwin hosts
452 SET (CMAKE_SKIP_RPATH OFF CACHE BOOL "" FORCE)
453 SET (CMAKE_PLATFORM_REQUIRED_RUNTIME_PATH "${EPREFIX}/usr/${CHOST}/lib/gcc;${EPREFIX}/usr/${CHOST}/lib;${EPREFIX}/usr/$(get_libdir);${EPREFIX}/$(get_libdir)"
454 CACHE STRING "" FORCE)
458 SET (CMAKE_PREFIX_PATH "${EPREFIX}/usr" CACHE STRING "" FORCE)
459 SET (CMAKE_MACOSX_RPATH ON CACHE BOOL "" FORCE)
460 SET (CMAKE_SKIP_BUILD_RPATH OFF CACHE BOOL "" FORCE)
461 SET (CMAKE_SKIP_RPATH OFF CACHE BOOL "" FORCE)
462 SET (CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE CACHE BOOL "" FORCE)
468 # Common configure parameters (invariants)
469 local common_config=${BUILD_DIR}/gentoo_common_config.cmake
470 local libdir=$(get_libdir)
471 cat > "${common_config}" <<- _EOF_ || die
472 SET (CMAKE_GENTOO_BUILD ON CACHE BOOL "Indicate Gentoo package build")
473 SET (LIB_SUFFIX ${libdir/lib} CACHE STRING "library path suffix" FORCE)
474 SET (CMAKE_INSTALL_LIBDIR ${libdir} CACHE PATH "Output directory for libraries")
475 SET (CMAKE_INSTALL_INFODIR "${EPREFIX}/usr/share/info" CACHE PATH "")
476 SET (CMAKE_INSTALL_MANDIR "${EPREFIX}/usr/share/man" CACHE PATH "")
477 SET (CMAKE_USER_MAKE_RULES_OVERRIDE "${build_rules}" CACHE FILEPATH "Gentoo override rules")
478 SET (CMAKE_INSTALL_DOCDIR "${EPREFIX}/usr/share/doc/${PF}" CACHE PATH "")
479 SET (BUILD_SHARED_LIBS ON CACHE BOOL "")
481 if [[ "${NOCOLOR}" = true || "${NOCOLOR}" = yes ]]; then
482 echo 'SET (CMAKE_COLOR_MAKEFILE OFF CACHE BOOL "pretty colors during make" FORCE)' >> "${common_config}" || die
485 # Wipe the default optimization flags out of CMake
486 if [[ ${CMAKE_BUILD_TYPE} != Gentoo ]]; then
487 cat >> ${common_config} <<- _EOF_ || die
488 SET (CMAKE_ASM_FLAGS_${CMAKE_BUILD_TYPE^^} "" CACHE STRING "")
489 SET (CMAKE_ASM-ATT_FLAGS_${CMAKE_BUILD_TYPE^^} "" CACHE STRING "")
490 SET (CMAKE_C_FLAGS_${CMAKE_BUILD_TYPE^^} "" CACHE STRING "")
491 SET (CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE^^} "" CACHE STRING "")
492 SET (CMAKE_Fortran_FLAGS_${CMAKE_BUILD_TYPE^^} "" CACHE STRING "")
493 SET (CMAKE_EXE_LINKER_FLAGS_${CMAKE_BUILD_TYPE^^} "" CACHE STRING "")
494 SET (CMAKE_MODULE_LINKER_FLAGS_${CMAKE_BUILD_TYPE^^} "" CACHE STRING "")
495 SET (CMAKE_SHARED_LINKER_FLAGS_${CMAKE_BUILD_TYPE^^} "" CACHE STRING "")
496 SET (CMAKE_STATIC_LINKER_FLAGS_${CMAKE_BUILD_TYPE^^} "" CACHE STRING "")
500 # Make the array a local variable since <=portage-2.1.6.x does not support
501 # global arrays (see bug #297255). But first make sure it is initialised.
502 [[ -z ${mycmakeargs} ]] && declare -a mycmakeargs=()
503 local mycmakeargstype=$(declare -p mycmakeargs 2>&-)
504 if [[ "${mycmakeargstype}" != "declare -a mycmakeargs="* ]]; then
505 die "mycmakeargs must be declared as array"
508 local mycmakeargs_local=( "${mycmakeargs[@]}" )
510 local warn_unused_cli=""
511 if [[ ${CMAKE_WARN_UNUSED_CLI} == no ]] ; then
512 warn_unused_cli="--no-warn-unused-cli"
516 case ${CMAKE_MAKEFILE_GENERATOR} in
517 ninja) generator_name="Ninja" ;;
518 emake) generator_name="Unix Makefiles" ;;
521 # Common configure parameters (overridable)
522 # NOTE CMAKE_BUILD_TYPE can be only overridden via CMAKE_BUILD_TYPE eclass variable
523 # No -DCMAKE_BUILD_TYPE=xxx definitions will be in effect.
526 -C "${common_config}"
527 -G "${generator_name}"
528 -DCMAKE_INSTALL_PREFIX="${EPREFIX}/usr"
529 "${mycmakeargs_local[@]}"
530 -DCMAKE_BUILD_TYPE="${CMAKE_BUILD_TYPE}"
531 -DCMAKE_TOOLCHAIN_FILE="${toolchain_file}"
535 if [[ -n "${CMAKE_EXTRA_CACHE_FILE}" ]] ; then
536 cmakeargs+=( -C "${CMAKE_EXTRA_CACHE_FILE}" )
539 pushd "${BUILD_DIR}" > /dev/null || die
540 debug-print "${LINENO} ${ECLASS} ${FUNCNAME}: mycmakeargs is ${mycmakeargs_local[*]}"
541 echo "${CMAKE_BINARY}" "${cmakeargs[@]}" "${CMAKE_USE_DIR}"
542 "${CMAKE_BINARY}" "${cmakeargs[@]}" "${CMAKE_USE_DIR}" || die "cmake failed"
543 popd > /dev/null || die
546 # @FUNCTION: cmake_src_compile
548 # General function for compiling with cmake.
549 # Automatically detects the build type. All arguments are passed to emake.
550 cmake_src_compile() {
551 debug-print-function ${FUNCNAME} "$@"
556 # @FUNCTION: cmake_build
558 # Function for building the package. Automatically detects the build type.
559 # All arguments are passed to emake.
561 debug-print-function ${FUNCNAME} "$@"
563 _cmake_check_build_dir
564 pushd "${BUILD_DIR}" > /dev/null || die
566 case ${CMAKE_MAKEFILE_GENERATOR} in
568 [[ -e Makefile ]] || die "Makefile not found. Error during configure stage."
569 [[ "${CMAKE_VERBOSE}" != "OFF" ]] && local verbosity="VERBOSE=1"
570 emake "${verbosity} "$@"
573 [[ -e build.ninja ]] || die "build.ninja not found. Error during configure stage."
578 popd > /dev/null || die
581 # @FUNCTION: cmake-utils_src_make
584 # Banned. Use cmake_build instead.
585 cmake-utils_src_make() {
586 die "cmake_src_make is banned. Use cmake_build instead"
589 # @FUNCTION: cmake_src_test
591 # Function for testing the package. Automatically detects the build type.
593 debug-print-function ${FUNCNAME} "$@"
595 _cmake_check_build_dir
596 pushd "${BUILD_DIR}" > /dev/null || die
597 [[ -e CTestTestfile.cmake ]] || { echo "No tests found. Skipping."; return 0 ; }
599 [[ -n ${TEST_VERBOSE} ]] && myctestargs+=( --extra-verbose --output-on-failure )
601 set -- ctest -j "$(makeopts_jobs)" --test-load "$(makeopts_loadavg)" "${myctestargs[@]}" "$@"
604 einfo "Tests succeeded."
605 popd > /dev/null || die
608 if [[ -n "${CMAKE_YES_I_WANT_TO_SEE_THE_TEST_LOG}" ]] ; then
609 # on request from Diego
610 eerror "Tests failed. Test log ${BUILD_DIR}/Testing/Temporary/LastTest.log follows:"
611 eerror "--START TEST LOG--------------------------------------------------------------"
612 cat "${BUILD_DIR}/Testing/Temporary/LastTest.log"
613 eerror "--END TEST LOG----------------------------------------------------------------"
616 die "Tests failed. When you file a bug, please attach the following file: \n\t${BUILD_DIR}/Testing/Temporary/LastTest.log"
619 # die might not die due to nonfatal
620 popd > /dev/null || die
625 # @FUNCTION: cmake_src_install
627 # Function for installing the package. Automatically detects the build type.
628 cmake_src_install() {
629 debug-print-function ${FUNCNAME} "$@"
631 _cmake_check_build_dir
632 pushd "${BUILD_DIR}" > /dev/null || die
633 DESTDIR="${D}" ${CMAKE_MAKEFILE_GENERATOR} install "$@" ||
634 die "died running ${CMAKE_MAKEFILE_GENERATOR} install"
635 popd > /dev/null || die
637 pushd "${S}" > /dev/null || die
639 popd > /dev/null || die