summaryrefslogtreecommitdiff
path: root/eclass/cmake.eclass
diff options
context:
space:
mode:
authorAndreas Sturmlechner <asturm@gentoo.org>2025-06-04 00:50:47 +0200
committerAndreas Sturmlechner <asturm@gentoo.org>2025-06-04 17:05:29 +0200
commit214b2fec7c840691b5b6599c07b6f3c3d6c1ff28 (patch)
tree8e151ad3c51214d7fdf4adcb89c5cb6a48899956 /eclass/cmake.eclass
parent454f11cdcb02ddb944c9595ef47ed659ecd13070 (diff)
downloadkde-214b2fec7c840691b5b6599c07b6f3c3d6c1ff28.tar.gz
kde-214b2fec7c840691b5b6599c07b6f3c3d6c1ff28.tar.bz2
kde-214b2fec7c840691b5b6599c07b6f3c3d6c1ff28.zip
cmake.eclass: Improve _cmake_modify-cmakelists()
50% less find 50% less grep 100% less cut Signed-off-by: Andreas Sturmlechner <asturm@gentoo.org>
Diffstat (limited to 'eclass/cmake.eclass')
-rw-r--r--eclass/cmake.eclass28
1 files changed, 17 insertions, 11 deletions
diff --git a/eclass/cmake.eclass b/eclass/cmake.eclass
index 987c6e4c6ee..e200b39432f 100644
--- a/eclass/cmake.eclass
+++ b/eclass/cmake.eclass
@@ -250,17 +250,23 @@ _cmake_modify-cmakelists() {
grep -qs "<<< Gentoo configuration >>>" "${CMAKE_USE_DIR}"/CMakeLists.txt && return 0
# Comment out all set (<some_should_be_user_defined_variable> value)
- find "${CMAKE_USE_DIR}" -name CMakeLists.txt -exec sed \
- -e '/^[[:space:]]*set[[:space:]]*([[:space:]]*CMAKE_BUILD_TYPE\([[:space:]].*)\|)\)/I{s/^/#_cmake_modify_IGNORE /g}' \
- -e '/^[[:space:]]*set[[:space:]]*([[:space:]]*CMAKE_COLOR_MAKEFILE[[:space:]].*)/I{s/^/#_cmake_modify_IGNORE /g}' \
- -e '/^[[:space:]]*set[[:space:]]*([[:space:]]*CMAKE_INSTALL_PREFIX[[:space:]].*)/I{s/^/#_cmake_modify_IGNORE /g}' \
- -e '/^[[:space:]]*set[[:space:]]*([[:space:]]*CMAKE_VERBOSE_MAKEFILE[[:space:]].*)/I{s/^/#_cmake_modify_IGNORE /g}' \
- -i {} + || die "${LINENO}: failed to disable hardcoded settings"
- local x
- for x in $(find "${CMAKE_USE_DIR}" -name CMakeLists.txt -exec grep -l "^#_cmake_modify_IGNORE" {} +;); do
- einfo "Hardcoded definition(s) removed in $(echo "${x}" | cut -c $((${#CMAKE_USE_DIR}+2))-):"
- einfo "$(grep -se '^#_cmake_modify_IGNORE' ${x} | cut -c 22-99)"
- done
+ local file
+ while read -d '' -r file ; do
+ sed \
+ -e '/^[[:space:]]*set[[:space:]]*([[:space:]]*CMAKE_BUILD_TYPE\([[:space:]].*)\|)\)/I{s/^/#_cmake_modify_IGNORE /g}' \
+ -e '/^[[:space:]]*set[[:space:]]*([[:space:]]*CMAKE_COLOR_MAKEFILE[[:space:]].*)/I{s/^/#_cmake_modify_IGNORE /g}' \
+ -e '/^[[:space:]]*set[[:space:]]*([[:space:]]*CMAKE_INSTALL_PREFIX[[:space:]].*)/I{s/^/#_cmake_modify_IGNORE /g}' \
+ -e '/^[[:space:]]*set[[:space:]]*([[:space:]]*CMAKE_VERBOSE_MAKEFILE[[:space:]].*)/I{s/^/#_cmake_modify_IGNORE /g}' \
+ -i ${file} || die "${LINENO}: failed to disable hardcoded settings"
+ readarray -t mod_lines < <(grep -se "^#_cmake_modify_IGNORE" ${file})
+ if [[ ${#mod_lines[*]} -gt 0 ]]; then
+ einfo "Hardcoded definition(s) removed in ${file/${CMAKE_USE_DIR%\/}\//}:"
+ local mod_line
+ for mod_line in "${mod_lines[@]}"; do
+ einfo "${mod_line:22:99}"
+ done
+ fi
+ done < <(find "${CMAKE_USE_DIR}" -type f -iname "CMakeLists.txt" -print0)
# NOTE Append some useful summary here
cat >> "${CMAKE_USE_DIR}"/CMakeLists.txt <<- _EOF_ || die