find_*: Add support for REQUIRED keyword

In the same spirit as the REQUIRED keyword on find_package, this will
stop cmake execution with an error on a failed find_program, find_file,
find_path or find_library.
This commit is contained in:
Sylvain Joubert
2020-03-06 14:30:01 +01:00
parent cc070e66cd
commit dc00809596
27 changed files with 121 additions and 2 deletions
+8
View File
@@ -3,6 +3,7 @@
#include "cmFindProgramCommand.h"
#include "cmMakefile.h"
#include "cmMessageType.h"
#include "cmStateTypes.h"
#include "cmStringAlgorithms.h"
#include "cmSystemTools.h"
@@ -136,6 +137,13 @@ bool cmFindProgramCommand::InitialPass(std::vector<std::string> const& argsIn)
this->Makefile->AddCacheDefinition(
this->VariableName, (this->VariableName + "-NOTFOUND").c_str(),
this->VariableDocumentation.c_str(), cmStateEnums::FILEPATH);
if (this->Required) {
this->Makefile->IssueMessage(
MessageType::FATAL_ERROR,
"Could not find " + this->VariableName +
" using the following names: " + cmJoin(this->Names, ", "));
cmSystemTools::SetFatalErrorOccured();
}
return true;
}