FPHSA: Check _FOUND var name with STREQUAL
This change creates variables _FOUND_VAR_UPPER
and _FOUND_VAR_MIXED
to hold the constructed variable names, then compares them to FPHSA_FOUND_VAR
using STREQUAL
, instead of MATCHES
.
Using MATCHES "^${_Name}_FOUND$"
limits the name of the found variable, since it can't contain any regular expression special-chars (period, plus sign, etc.)
e.g. consider a find module called FindUnitTest++.cmake
. With the previous code, this FPHSA call:
find_package_handle_standard_args(UnitTest++ DEFAULT_MSG
UnitTest++_LIBRARY UnitTest++_INCLUDE_DIR)
will work fine. But this one:
find_package_handle_standard_args(UnitTest++
FOUND_VAR UnitTest++_FOUND
REQUIRED_VARS UnitTest++_LIBRARY UnitTest++_INCLUDE_DIR)
will result in a regexp error:
$ cmake -P ./FindUnitTest++.cmake
RegularExpression::compile(): Nested *?+.
RegularExpression::compile(): Error in compile.
CMake Error at /usr/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:242 (if):
if given arguments:
"FPHSA_FOUND_VAR" "MATCHES" "^UnitTest++_FOUND\$" "OR" "FPHSA_FOUND_VAR" "MATCHES" "^UNITTEST++_FOUND\$"
Regular expression "^UnitTest++_FOUND$" cannot compile
Call Stack (most recent call first):
FindUnitTest++.cmake:61 (find_package_handle_standard_args)
The modified code handles the FOUND_VAR
name correctly:
$ cmake -P ./FindUnitTest++.cmake
-- Found UnitTest++: /usr/lib64/libUnitTest++.so
Edited by Frank Dana