diff options
| author | Andreas Sturmlechner <asturm@gentoo.org> | 2025-06-13 16:42:37 +0200 |
|---|---|---|
| committer | Andreas Sturmlechner <asturm@gentoo.org> | 2025-06-14 12:47:42 +0200 |
| commit | 3ad02c872f5ebaa5903411e81a74670a7f93ab73 (patch) | |
| tree | 31f7351be4fa633b6d70e25af69a5dda4f8858c4 /eclass | |
| parent | d88d09e64c447e14f072956e45605765cb29268e (diff) | |
| download | kde-3ad02c872f5ebaa5903411e81a74670a7f93ab73.tar.gz kde-3ad02c872f5ebaa5903411e81a74670a7f93ab73.tar.bz2 kde-3ad02c872f5ebaa5903411e81a74670a7f93ab73.zip | |
cmake.eclass: mv _CMAKE_MINREQVER_UNSUPPORTED detection to src_prepare
- _cmake_minverreq-lt(): New function for reusability of regex
- Optimise #1: Reuse existing loop over CMakeLists.txt files
- Optimise #2: If _CMAKE_MINREQVER_UNSUPPORTED is already set, then no
further run of _cmake_minverreq-lt is necessary since we currently throw
away the info on affected files
- Relegate "CMake 4 detected; ..." to be a non-QA Notice, it is just an
addendum
Signed-off-by: Andreas Sturmlechner <asturm@gentoo.org>
Diffstat (limited to 'eclass')
| -rw-r--r-- | eclass/cmake.eclass | 72 |
1 files changed, 43 insertions, 29 deletions
diff --git a/eclass/cmake.eclass b/eclass/cmake.eclass index 47f96227d3e..0ad1ca821be 100644 --- a/eclass/cmake.eclass +++ b/eclass/cmake.eclass @@ -126,7 +126,8 @@ fi # @ECLASS_VARIABLE: _CMAKE_MINREQVER_UNSUPPORTED # @DEFAULT_UNSET # @DESCRIPTION: -# Is set to true if an unsupported cmake_minimum_required value was detected. +# Internal status set by _cmake_minreqver-lt(); is true if an unsupported +# cmake_minimum_required value was detected. # @ECLASS_VARIABLE: CMAKE_QA_SRC_DIR_READONLY # @USER_VARIABLE @@ -243,6 +244,25 @@ _cmake_check_build_dir() { mkdir -p "${BUILD_DIR}" || die } +# @FUNCTION: _cmake_minreqver-lt +# @USAGE: <lt-version> <path> +# @INTERNAL +# @DESCRIPTION: +# Internal function for detecting occurrence of lower-than-specified +# <lt-version> in cmake_minimum_required of a given CMake file <path>. +# Returns 0 if the regex matched (a lower-than-specified version found). +_cmake_minreqver-lt() { + local ver chk=1 + ver=$(sed -ne "/cmake_minimum_required/I{s/.*\(\.\.\.*\|\s\)\([0-9.]*\)\([)]\|\s\).*$/\2/p;q}" \ + "${2}" 2>/dev/null \ + ) + if [[ -n ${ver} ]] && ver_test "${ver}" -lt "${1}"; then + _CMAKE_MINREQVER_UNSUPPORTED=true + chk=0 + fi + return ${chk} +} + # @FUNCTION: _cmake_modify-cmakelists # @INTERNAL # @DESCRIPTION: @@ -254,9 +274,9 @@ _cmake_modify-cmakelists() { # Only edit the files once grep -qs "<<< Gentoo configuration >>>" "${CMAKE_USE_DIR}"/CMakeLists.txt && return 0 - # Comment out all set (<some_should_be_user_defined_variable> value) local file while read -d '' -r file ; do + # Comment out all set (<some_should_be_user_defined_variable> value) sed \ -e '/^[[:space:]]*set[[:space:]]*([[:space:]]*CMAKE_BUILD_TYPE\([[:space:]].*)\|)\)/I{s/^/#_cmake_modify_IGNORE /g}' \ -e '/^[[:space:]]*set[[:space:]]*([[:space:]]*CMAKE_\(COLOR_MAKEFILE\|INSTALL_PREFIX\|VERBOSE_MAKEFILE\)[[:space:]].*)/I{s/^/#_cmake_modify_IGNORE /g}' \ @@ -269,7 +289,11 @@ _cmake_modify-cmakelists() { einfo "${mod_line:22:99}" done fi - done < <(find "${CMAKE_USE_DIR}" -type f -iname "CMakeLists.txt" -print0) + # Detect unsupported minimum CMake versions unless CMAKE_QA_COMPAT_SKIP is set + if [[ -z ${_CMAKE_MINREQVER_UNSUPPORTED} ]] && ! [[ ${CMAKE_QA_COMPAT_SKIP} ]]; then + _cmake_minreqver-lt "3.5" "${file}" + fi + done < <(find "${CMAKE_USE_DIR}" -type f -iname "CMakeLists.txt" -print0 || die) # NOTE Append some useful summary here cat >> "${CMAKE_USE_DIR}"/CMakeLists.txt <<- _EOF_ || die @@ -329,6 +353,20 @@ cmake_src_prepare() { # Remove dangerous things. _cmake_modify-cmakelists + if [[ ${_CMAKE_MINREQVER_UNSUPPORTED} ]]; then + eqawarn "QA Notice: Compatibility with CMake < 3.5 has been removed from CMake 4," + eqawarn "${CATEGORY}/${PN} will fail to build w/o a fix." + eqawarn "See also tracker bug #951350; check existing bug or file a new one for" + eqawarn "this package, and take it upstream." + if has_version -b ">=dev-build/cmake-4"; then + eqawarn "CMake 4 detected; building with -DCMAKE_POLICY_VERSION_MINIMUM=3.5" + eqawarn "This is merely a workaround and *not* a permanent fix." + fi + if [[ ${EAPI} == 7 ]]; then + eqawarn "QA Notice: EAPI=7 detected; this package is now a prime last-rites target." + fi + fi + if [[ ${EAPI} == 7 ]]; then popd > /dev/null || die fi @@ -377,19 +415,6 @@ cmake_src_configure() { # Fix xdg collision with sandbox xdg_environment_reset - local file ver - if ! [[ ${CMAKE_QA_COMPAT_SKIP} ]]; then - while read -d '' -r file ; do - ver=$(sed -ne "/cmake_minimum_required/I{s/.*\(\.\.\.*\|\s\)\([0-9.]*\)\([)]\|\s\).*$/\2/p;q}" \ - "${file}" 2>/dev/null \ - ) - - if [[ -n $ver ]] && ver_test $ver -lt "3.5"; then - _CMAKE_MINREQVER_UNSUPPORTED=true - fi - done < <(find "${CMAKE_USE_DIR}" -type f -iname "CMakeLists.txt" -print0) - fi - # Prepare Gentoo override rules (set valid compiler, append CPPFLAGS etc.) local build_rules=${BUILD_DIR}/gentoo_rules.cmake @@ -571,19 +596,8 @@ cmake_src_configure() { cmakeargs+=( -C "${CMAKE_EXTRA_CACHE_FILE}" ) fi - if [[ ${_CMAKE_MINREQVER_UNSUPPORTED} ]]; then - eqawarn "QA Notice: Compatibility with CMake < 3.5 has been removed from CMake 4," - eqawarn "${CATEGORY}/${PN} will fail to build w/o a fix." - eqawarn "See also tracker bug #951350; check existing bug or file a new one for" - eqawarn "this package, and take it upstream." - if has_version -b ">=dev-build/cmake-4"; then - eqawarn "QA Notice: CMake 4 detected; building with -DCMAKE_POLICY_VERSION_MINIMUM=3.5" - eqawarn "This is merely a workaround and *not* a permanent fix." - cmakeargs+=( -DCMAKE_POLICY_VERSION_MINIMUM=3.5 ) - fi - if [[ ${EAPI} == 7 ]]; then - eqawarn "QA Notice: EAPI=7 detected; this package is now a prime last-rites target." - fi + if [[ ${_CMAKE_MINREQVER_UNSUPPORTED} ]] && has_version -b ">=dev-build/cmake-4"; then + cmakeargs+=( -DCMAKE_POLICY_VERSION_MINIMUM=3.5 ) fi pushd "${BUILD_DIR}" > /dev/null || die |
