Merge topic 'fix-CMAKE_MATCH-self-match'

6ffc4323 cmConditionEvaluator: Fix matching of `CMAKE_MATCH_*` values (#15944)
This commit is contained in:
Brad King 2016-02-02 08:33:20 -05:00 committed by CMake Topic Stage
commit f8e5e5bb03
3 changed files with 16 additions and 0 deletions

View File

@ -12,6 +12,7 @@
#include "cmConditionEvaluator.h" #include "cmConditionEvaluator.h"
#include "cmOutputConverter.h" #include "cmOutputConverter.h"
#include "cmAlgorithms.h"
cmConditionEvaluator::cmConditionEvaluator(cmMakefile& makefile, cmConditionEvaluator::cmConditionEvaluator(cmMakefile& makefile,
const cmListFileContext &context, const cmListFileContext &context,
@ -578,6 +579,7 @@ bool cmConditionEvaluator::HandleLevel2(cmArgumentList &newArgs,
cmake::MessageType &status) cmake::MessageType &status)
{ {
int reducible; int reducible;
std::string def_buf;
const char *def; const char *def;
const char *def2; const char *def2;
do do
@ -594,6 +596,14 @@ bool cmConditionEvaluator::HandleLevel2(cmArgumentList &newArgs,
IsKeyword("MATCHES", *argP1)) IsKeyword("MATCHES", *argP1))
{ {
def = this->GetVariableOrString(*arg); def = this->GetVariableOrString(*arg);
if (def != arg->c_str() // yes, we compare the pointer value
&& cmHasLiteralPrefix(arg->GetValue(), "CMAKE_MATCH_"))
{
// The string to match is owned by our match result variables.
// Move it to our own buffer before clearing them.
def_buf = def;
def = def_buf.c_str();
}
const char* rex = argP2->c_str(); const char* rex = argP2->c_str();
this->Makefile.ClearMatches(); this->Makefile.ClearMatches();
cmsys::RegularExpression regEntry; cmsys::RegularExpression regEntry;

View File

@ -0,0 +1,4 @@
foreach(n 0 1 2 3 4 5 6 7 8 9 COUNT)
if(CMAKE_MATCH_${n} MATCHES "x")
endif()
endforeach()

View File

@ -5,5 +5,7 @@ run_cmake(IsDirectory)
run_cmake(IsDirectoryLong) run_cmake(IsDirectoryLong)
run_cmake(elseif-message) run_cmake(elseif-message)
run_cmake(MatchesSelf)
run_cmake(TestNameThatExists) run_cmake(TestNameThatExists)
run_cmake(TestNameThatDoesNotExist) run_cmake(TestNameThatDoesNotExist)