eclass/cmake: Sync with Gentoo

It's from Gentoo commit 759cec852497f888d93cccfedbc83f16eb765fb4.
This commit is contained in:
Krzesimir Nowak 2022-08-23 16:50:06 +02:00
parent 7b4897eebf
commit 6b973e990a

View File

@ -1,4 +1,4 @@
# Copyright 1999-2021 Gentoo Authors # Copyright 1999-2022 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2 # Distributed under the terms of the GNU General Public License v2
# @ECLASS: cmake.eclass # @ECLASS: cmake.eclass
@ -28,7 +28,7 @@ _CMAKE_ECLASS=1
inherit flag-o-matic multiprocessing ninja-utils toolchain-funcs xdg-utils inherit flag-o-matic multiprocessing ninja-utils toolchain-funcs xdg-utils
# @ECLASS-VARIABLE: BUILD_DIR # @ECLASS_VARIABLE: BUILD_DIR
# @DEFAULT_UNSET # @DEFAULT_UNSET
# @DESCRIPTION: # @DESCRIPTION:
# Build directory where all cmake processed files should be generated. # Build directory where all cmake processed files should be generated.
@ -38,13 +38,13 @@ inherit flag-o-matic multiprocessing ninja-utils toolchain-funcs xdg-utils
[[ ${EAPI} == 7 ]] && : ${BUILD_DIR:=${WORKDIR}/${P}_build} [[ ${EAPI} == 7 ]] && : ${BUILD_DIR:=${WORKDIR}/${P}_build}
# EAPI-8: set inside _cmake_check_build_dir # EAPI-8: set inside _cmake_check_build_dir
# @ECLASS-VARIABLE: CMAKE_BINARY # @ECLASS_VARIABLE: CMAKE_BINARY
# @DESCRIPTION: # @DESCRIPTION:
# Eclass can use different cmake binary than the one provided in by system. # Eclass can use different cmake binary than the one provided in by system.
: ${CMAKE_BINARY:=cmake} : ${CMAKE_BINARY:=cmake}
[[ ${EAPI} == 7 ]] && : ${CMAKE_BUILD_TYPE:=Gentoo} [[ ${EAPI} == 7 ]] && : ${CMAKE_BUILD_TYPE:=Gentoo}
# @ECLASS-VARIABLE: CMAKE_BUILD_TYPE # @ECLASS_VARIABLE: CMAKE_BUILD_TYPE
# @DESCRIPTION: # @DESCRIPTION:
# Set to override default CMAKE_BUILD_TYPE. Only useful for packages # Set to override default CMAKE_BUILD_TYPE. Only useful for packages
# known to make use of "if (CMAKE_BUILD_TYPE MATCHES xxx)". # known to make use of "if (CMAKE_BUILD_TYPE MATCHES xxx)".
@ -57,12 +57,12 @@ inherit flag-o-matic multiprocessing ninja-utils toolchain-funcs xdg-utils
# In EAPI 7, the default was non-standard build type of Gentoo. # In EAPI 7, the default was non-standard build type of Gentoo.
: ${CMAKE_BUILD_TYPE:=RelWithDebInfo} : ${CMAKE_BUILD_TYPE:=RelWithDebInfo}
# @ECLASS-VARIABLE: CMAKE_IN_SOURCE_BUILD # @ECLASS_VARIABLE: CMAKE_IN_SOURCE_BUILD
# @DEFAULT_UNSET # @DEFAULT_UNSET
# @DESCRIPTION: # @DESCRIPTION:
# Set to enable in-source build. # Set to enable in-source build.
# @ECLASS-VARIABLE: CMAKE_MAKEFILE_GENERATOR # @ECLASS_VARIABLE: CMAKE_MAKEFILE_GENERATOR
# @PRE_INHERIT # @PRE_INHERIT
# @DEFAULT_UNSET # @DEFAULT_UNSET
# @DESCRIPTION: # @DESCRIPTION:
@ -71,7 +71,7 @@ inherit flag-o-matic multiprocessing ninja-utils toolchain-funcs xdg-utils
# The default is set to "ninja". # The default is set to "ninja".
: ${CMAKE_MAKEFILE_GENERATOR:=ninja} : ${CMAKE_MAKEFILE_GENERATOR:=ninja}
# @ECLASS-VARIABLE: CMAKE_REMOVE_MODULES_LIST # @ECLASS_VARIABLE: CMAKE_REMOVE_MODULES_LIST
# @PRE_INHERIT # @PRE_INHERIT
# @DEFAULT_UNSET # @DEFAULT_UNSET
# @DESCRIPTION: # @DESCRIPTION:
@ -90,25 +90,25 @@ else
fi fi
fi fi
# @ECLASS-VARIABLE: CMAKE_USE_DIR # @ECLASS_VARIABLE: CMAKE_USE_DIR
# @DESCRIPTION: # @DESCRIPTION:
# Sets the directory where we are working with cmake, for example when # Sets the directory where we are working with cmake, for example when
# application uses autotools and only one plugin needs to be done by cmake. # application uses autotools and only one plugin needs to be done by cmake.
# By default it uses current working directory (in EAPI-7: ${S}). # By default it uses current working directory (in EAPI-7: ${S}).
# @ECLASS-VARIABLE: CMAKE_VERBOSE # @ECLASS_VARIABLE: CMAKE_VERBOSE
# @DESCRIPTION: # @DESCRIPTION:
# Set to OFF to disable verbose messages during compilation # Set to OFF to disable verbose messages during compilation
: ${CMAKE_VERBOSE:=ON} : ${CMAKE_VERBOSE:=ON}
# @ECLASS-VARIABLE: CMAKE_WARN_UNUSED_CLI # @ECLASS_VARIABLE: CMAKE_WARN_UNUSED_CLI
# @DESCRIPTION: # @DESCRIPTION:
# Warn about variables that are declared on the command line # Warn about variables that are declared on the command line
# but not used. Might give false-positives. # but not used. Might give false-positives.
# "no" to disable (default) or anything else to enable. # "no" to disable (default) or anything else to enable.
: ${CMAKE_WARN_UNUSED_CLI:=yes} : ${CMAKE_WARN_UNUSED_CLI:=yes}
# @ECLASS-VARIABLE: CMAKE_EXTRA_CACHE_FILE # @ECLASS_VARIABLE: CMAKE_EXTRA_CACHE_FILE
# @USER_VARIABLE # @USER_VARIABLE
# @DEFAULT_UNSET # @DEFAULT_UNSET
# @DESCRIPTION: # @DESCRIPTION:
@ -116,7 +116,7 @@ fi
# for econf and is needed to pass TRY_RUN results when cross-compiling. # for econf and is needed to pass TRY_RUN results when cross-compiling.
# Should be set by user in a per-package basis in /etc/portage/package.env. # Should be set by user in a per-package basis in /etc/portage/package.env.
# @ECLASS-VARIABLE: CMAKE_QA_SRC_DIR_READONLY # @ECLASS_VARIABLE: CMAKE_QA_SRC_DIR_READONLY
# @USER_VARIABLE # @USER_VARIABLE
# @DEFAULT_UNSET # @DEFAULT_UNSET
# @DESCRIPTION: # @DESCRIPTION:
@ -136,7 +136,7 @@ case ${CMAKE_MAKEFILE_GENERATOR} in
BDEPEND="sys-devel/make" BDEPEND="sys-devel/make"
;; ;;
ninja) ninja)
BDEPEND="dev-util/ninja" BDEPEND="${NINJA_DEPEND}"
;; ;;
*) *)
eerror "Unknown value for \${CMAKE_MAKEFILE_GENERATOR}" eerror "Unknown value for \${CMAKE_MAKEFILE_GENERATOR}"
@ -363,13 +363,6 @@ cmake_src_prepare() {
die "FATAL: Unable to find CMakeLists.txt" die "FATAL: Unable to find CMakeLists.txt"
fi fi
# if ninja is enabled but not installed, the build could fail
# this could happen if ninja is manually enabled (eg. make.conf) but not installed
if [[ ${CMAKE_MAKEFILE_GENERATOR} == ninja ]] && ! has_version -b dev-util/ninja; then
eerror "CMAKE_MAKEFILE_GENERATOR is set to ninja, but ninja is not installed."
die "Please install dev-util/ninja or unset CMAKE_MAKEFILE_GENERATOR."
fi
local modules_list local modules_list
if [[ ${EAPI} == 7 && $(declare -p CMAKE_REMOVE_MODULES_LIST) != "declare -a"* ]]; then if [[ ${EAPI} == 7 && $(declare -p CMAKE_REMOVE_MODULES_LIST) != "declare -a"* ]]; then
modules_list=( ${CMAKE_REMOVE_MODULES_LIST} ) modules_list=( ${CMAKE_REMOVE_MODULES_LIST} )
@ -406,6 +399,12 @@ cmake_src_prepare() {
_CMAKE_SRC_PREPARE_HAS_RUN=1 _CMAKE_SRC_PREPARE_HAS_RUN=1
} }
# @VARIABLE: MYCMAKEARGS
# @DEFAULT_UNSET
# @DESCRIPTION:
# User-controlled environment variable containing arguments to be passed to
# cmake in cmake_src_configure.
# @FUNCTION: cmake_src_configure # @FUNCTION: cmake_src_configure
# @DESCRIPTION: # @DESCRIPTION:
# General function for configuring with cmake. Default behaviour is to start an # General function for configuring with cmake. Default behaviour is to start an
@ -593,9 +592,12 @@ cmake_src_configure() {
"${mycmakeargs_local[@]}" "${mycmakeargs_local[@]}"
-DCMAKE_BUILD_TYPE="${CMAKE_BUILD_TYPE}" -DCMAKE_BUILD_TYPE="${CMAKE_BUILD_TYPE}"
-DCMAKE_TOOLCHAIN_FILE="${toolchain_file}" -DCMAKE_TOOLCHAIN_FILE="${toolchain_file}"
"${MYCMAKEARGS}"
) )
if [[ -n ${MYCMAKEARGS} ]] ; then
cmakeargs+=( "${MYCMAKEARGS}" )
fi
if [[ -n "${CMAKE_EXTRA_CACHE_FILE}" ]] ; then if [[ -n "${CMAKE_EXTRA_CACHE_FILE}" ]] ; then
cmakeargs+=( -C "${CMAKE_EXTRA_CACHE_FILE}" ) cmakeargs+=( -C "${CMAKE_EXTRA_CACHE_FILE}" )
fi fi
@ -665,7 +667,8 @@ cmake_src_test() {
[[ -n ${TEST_VERBOSE} ]] && myctestargs+=( --extra-verbose --output-on-failure ) [[ -n ${TEST_VERBOSE} ]] && myctestargs+=( --extra-verbose --output-on-failure )
set -- ctest -j "$(makeopts_jobs)" --test-load "$(makeopts_loadavg)" "${myctestargs[@]}" "$@" set -- ctest -j "$(makeopts_jobs "${MAKEOPTS}" 999)" \
--test-load "$(makeopts_loadavg)" "${myctestargs[@]}" "$@"
echo "$@" >&2 echo "$@" >&2
if "$@" ; then if "$@" ; then
einfo "Tests succeeded." einfo "Tests succeeded."
@ -695,11 +698,7 @@ cmake_src_test() {
cmake_src_install() { cmake_src_install() {
debug-print-function ${FUNCNAME} "$@" debug-print-function ${FUNCNAME} "$@"
_cmake_check_build_dir DESTDIR="${D}" cmake_build install "$@"
pushd "${BUILD_DIR}" > /dev/null || die
DESTDIR="${D}" ${CMAKE_MAKEFILE_GENERATOR} install "$@" ||
die "died running ${CMAKE_MAKEFILE_GENERATOR} install"
popd > /dev/null || die
if [[ ${EAPI} == 7 ]]; then if [[ ${EAPI} == 7 ]]; then
pushd "${S}" > /dev/null || die pushd "${S}" > /dev/null || die