File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -247,6 +247,34 @@ cmake_punt_find_package() {
247247 fi
248248}
249249
250+ # @FUNCTION: cmake_unrequire_find_package
251+ # @USAGE: <pkg>
252+ # @DESCRIPTION:
253+ # Remove REQUIRED attribute from a given find_package(<pkg>) call inside CMakeLists.txt
254+ cmake_unrequire_find_package () {
255+ local cmpnt=" REQUIRED"
256+ if [[ -z ${1} ]]; then
257+ die " ${FUNCNAME[0]} must be passed exactly one argument"
258+ fi
259+
260+ [[ -e " CMakeLists.txt" ]] || return
261+
262+ pcre2grep -Mni " (?s)find_package\s*\(\s*${1} .*?REQUIRED.*?\)" \
263+ CMakeLists.txt > " ${T} /bogus${cmpnt} "
264+
265+ # pcre2grep returns non-zero on no matches/error
266+ if [[ $? -ne 0 ]]; then
267+ eqawarn " QA Notice: ${FUNCNAME} (${1} ) called, but no matches found!"
268+ return
269+ fi
270+
271+ local length=$( wc -l " ${T} /bogus${cmpnt} " | cut -d " " -f 1)
272+ local first=$( head -n 1 " ${T} /bogus${cmpnt} " | cut -d " :" -f 1)
273+ local last=$(( length + first - 1 ))
274+
275+ sed -e " ${first} ,${last} s/${cmpnt} //" -i CMakeLists.txt || die
276+ }
277+
250278# @FUNCTION: cmake_use_find_package
251279# @USAGE: <USE flag> <package name>
252280# @DESCRIPTION:
You can’t perform that action at this time.
0 commit comments