Skip to content

Commit 69580a0

Browse files
committed
cmake.eclass: First (hackish) version of cmake_unrequire_find_package()
Signed-off-by: Andreas Sturmlechner <asturm@gentoo.org>
1 parent a911880 commit 69580a0

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

eclass/cmake.eclass

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,34 @@ cmake_punt_find_package() {
259259
fi
260260
}
261261

262+
# @FUNCTION: cmake_unrequire_find_package
263+
# @USAGE: <pkg>
264+
# @DESCRIPTION:
265+
# Remove REQUIRED attribute from a given find_package(<pkg>) call inside CMakeLists.txt
266+
cmake_unrequire_find_package() {
267+
local cmpnt="REQUIRED"
268+
if [[ -z ${1} ]]; then
269+
die "${FUNCNAME[0]} must be passed exactly one argument"
270+
fi
271+
272+
[[ -e "CMakeLists.txt" ]] || return
273+
274+
pcre2grep -Mni "(?s)find_package\s*\(\s*${1}.*?REQUIRED.*?\)" \
275+
CMakeLists.txt > "${T}/bogus${cmpnt}"
276+
277+
# pcre2grep returns non-zero on no matches/error
278+
if [[ $? -ne 0 ]]; then
279+
eqawarn "QA Notice: ${FUNCNAME}(${1}) called, but no matches found!"
280+
return
281+
fi
282+
283+
local length=$(wc -l "${T}/bogus${cmpnt}" | cut -d " " -f 1)
284+
local first=$(head -n 1 "${T}/bogus${cmpnt}" | cut -d ":" -f 1)
285+
local last=$(( length + first - 1))
286+
287+
sed -e "${first},${last}s/${cmpnt}//" -i CMakeLists.txt || die
288+
}
289+
262290
# @FUNCTION: cmake_use_find_package
263291
# @USAGE: <USE flag> <package name>
264292
# @DESCRIPTION:

0 commit comments

Comments
 (0)