File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed
Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff 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:
You can’t perform that action at this time.
0 commit comments