mirror of
https://github.com/reactos/CMake.git
synced 2024-11-24 03:59:58 +00:00
cmIfCommand: Reject duplicate else() and misplaced elseif()
Closes: #14335
This commit is contained in:
parent
3be5896e01
commit
edac95b955
@ -57,8 +57,19 @@ bool cmIfFunctionBlocker::IsFunctionBlocked(const cmListFileFunction& lff,
|
||||
// watch for our state change
|
||||
if (scopeDepth == 0 &&
|
||||
!cmSystemTools::Strucmp(this->Functions[c].Name.c_str(), "else")) {
|
||||
|
||||
if (this->ElseSeen) {
|
||||
cmListFileBacktrace bt = mf.GetBacktrace(this->Functions[c]);
|
||||
mf.GetCMakeInstance()->IssueMessage(
|
||||
cmake::FATAL_ERROR,
|
||||
"A duplicate ELSE command was found inside an IF block.", bt);
|
||||
cmSystemTools::SetFatalErrorOccured();
|
||||
return true;
|
||||
}
|
||||
|
||||
this->IsBlocking = this->HasRun;
|
||||
this->HasRun = true;
|
||||
this->ElseSeen = true;
|
||||
|
||||
// if trace is enabled, print a (trivially) evaluated "else"
|
||||
// statement
|
||||
@ -68,6 +79,15 @@ bool cmIfFunctionBlocker::IsFunctionBlocked(const cmListFileFunction& lff,
|
||||
} else if (scopeDepth == 0 &&
|
||||
!cmSystemTools::Strucmp(this->Functions[c].Name.c_str(),
|
||||
"elseif")) {
|
||||
if (this->ElseSeen) {
|
||||
cmListFileBacktrace bt = mf.GetBacktrace(this->Functions[c]);
|
||||
mf.GetCMakeInstance()->IssueMessage(
|
||||
cmake::FATAL_ERROR,
|
||||
"An ELSEIF command was found after an ELSE command.", bt);
|
||||
cmSystemTools::SetFatalErrorOccured();
|
||||
return true;
|
||||
}
|
||||
|
||||
if (this->HasRun) {
|
||||
this->IsBlocking = true;
|
||||
} else {
|
||||
|
@ -21,6 +21,7 @@ public:
|
||||
cmIfFunctionBlocker()
|
||||
{
|
||||
this->HasRun = false;
|
||||
this->ElseSeen = false;
|
||||
this->ScopeDepth = 0;
|
||||
}
|
||||
~cmIfFunctionBlocker() CM_OVERRIDE {}
|
||||
@ -32,6 +33,7 @@ public:
|
||||
std::vector<cmListFileFunction> Functions;
|
||||
bool IsBlocking;
|
||||
bool HasRun;
|
||||
bool ElseSeen;
|
||||
unsigned int ScopeDepth;
|
||||
};
|
||||
|
||||
|
@ -3,7 +3,11 @@ include(RunCMake)
|
||||
run_cmake(InvalidArgument1)
|
||||
run_cmake(IsDirectory)
|
||||
run_cmake(IsDirectoryLong)
|
||||
run_cmake(duplicate-deep-else)
|
||||
run_cmake(duplicate-else)
|
||||
run_cmake(duplicate-else-after-elseif)
|
||||
run_cmake(elseif-message)
|
||||
run_cmake(misplaced-elseif)
|
||||
|
||||
run_cmake(MatchesSelf)
|
||||
|
||||
|
1
Tests/RunCMake/if/duplicate-deep-else-result.txt
Normal file
1
Tests/RunCMake/if/duplicate-deep-else-result.txt
Normal file
@ -0,0 +1 @@
|
||||
1
|
4
Tests/RunCMake/if/duplicate-deep-else-stderr.txt
Normal file
4
Tests/RunCMake/if/duplicate-deep-else-stderr.txt
Normal file
@ -0,0 +1,4 @@
|
||||
CMake Error at duplicate-deep-else.cmake:[0-9]+ \(else\):
|
||||
A duplicate ELSE command was found inside an IF block.
|
||||
Call Stack \(most recent call first\):
|
||||
CMakeLists.txt:3 \(include\)
|
7
Tests/RunCMake/if/duplicate-deep-else.cmake
Normal file
7
Tests/RunCMake/if/duplicate-deep-else.cmake
Normal file
@ -0,0 +1,7 @@
|
||||
if(0)
|
||||
else()
|
||||
if(0)
|
||||
else()
|
||||
else()
|
||||
endif()
|
||||
endif()
|
1
Tests/RunCMake/if/duplicate-else-after-elseif-result.txt
Normal file
1
Tests/RunCMake/if/duplicate-else-after-elseif-result.txt
Normal file
@ -0,0 +1 @@
|
||||
1
|
4
Tests/RunCMake/if/duplicate-else-after-elseif-stderr.txt
Normal file
4
Tests/RunCMake/if/duplicate-else-after-elseif-stderr.txt
Normal file
@ -0,0 +1,4 @@
|
||||
CMake Error at duplicate-else-after-elseif.cmake:[0-9]+ \(else\):
|
||||
A duplicate ELSE command was found inside an IF block.
|
||||
Call Stack \(most recent call first\):
|
||||
CMakeLists.txt:3 \(include\)
|
5
Tests/RunCMake/if/duplicate-else-after-elseif.cmake
Normal file
5
Tests/RunCMake/if/duplicate-else-after-elseif.cmake
Normal file
@ -0,0 +1,5 @@
|
||||
if(0)
|
||||
elseif(0)
|
||||
else()
|
||||
else()
|
||||
endif()
|
1
Tests/RunCMake/if/duplicate-else-result.txt
Normal file
1
Tests/RunCMake/if/duplicate-else-result.txt
Normal file
@ -0,0 +1 @@
|
||||
1
|
4
Tests/RunCMake/if/duplicate-else-stderr.txt
Normal file
4
Tests/RunCMake/if/duplicate-else-stderr.txt
Normal file
@ -0,0 +1,4 @@
|
||||
CMake Error at duplicate-else.cmake:[0-9]+ \(else\):
|
||||
A duplicate ELSE command was found inside an IF block.
|
||||
Call Stack \(most recent call first\):
|
||||
CMakeLists.txt:3 \(include\)
|
4
Tests/RunCMake/if/duplicate-else.cmake
Normal file
4
Tests/RunCMake/if/duplicate-else.cmake
Normal file
@ -0,0 +1,4 @@
|
||||
if(0)
|
||||
else()
|
||||
else()
|
||||
endif()
|
1
Tests/RunCMake/if/misplaced-elseif-result.txt
Normal file
1
Tests/RunCMake/if/misplaced-elseif-result.txt
Normal file
@ -0,0 +1 @@
|
||||
1
|
4
Tests/RunCMake/if/misplaced-elseif-stderr.txt
Normal file
4
Tests/RunCMake/if/misplaced-elseif-stderr.txt
Normal file
@ -0,0 +1,4 @@
|
||||
CMake Error at misplaced-elseif.cmake:[0-9]+ \(elseif\):
|
||||
An ELSEIF command was found after an ELSE command.
|
||||
Call Stack \(most recent call first\):
|
||||
CMakeLists.txt:3 \(include\)
|
4
Tests/RunCMake/if/misplaced-elseif.cmake
Normal file
4
Tests/RunCMake/if/misplaced-elseif.cmake
Normal file
@ -0,0 +1,4 @@
|
||||
if(0)
|
||||
else()
|
||||
elseif(1)
|
||||
endif()
|
Loading…
Reference in New Issue
Block a user