Create CMP0014 to require CMakeLists.txt files
Until now CMake accidentally accepted add_subdirectory() and subdirs() calls referring to directories that do not contain a CMakeLists.txt file. We introduce CMake Policy CMP0014 to make this case an error.
This commit is contained in:
parent
3fda5c6463
commit
e308621382
|
@ -167,9 +167,49 @@ void cmLocalGenerator::ComputeObjectMaxPath()
|
|||
//----------------------------------------------------------------------------
|
||||
void cmLocalGenerator::ReadInputFile()
|
||||
{
|
||||
// Look for the CMakeLists.txt file.
|
||||
std::string currentStart = this->Makefile->GetStartDirectory();
|
||||
currentStart += "/CMakeLists.txt";
|
||||
this->Makefile->ReadListFile(currentStart.c_str());
|
||||
if(cmSystemTools::FileExists(currentStart.c_str(), true))
|
||||
{
|
||||
this->Makefile->ReadListFile(currentStart.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
if(!this->Parent)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// The file is missing. Check policy CMP0014.
|
||||
cmMakefile* mf = this->Parent->GetMakefile();
|
||||
cmOStringStream e;
|
||||
e << "The source directory\n"
|
||||
<< " " << this->Makefile->GetStartDirectory() << "\n"
|
||||
<< "does not contain a CMakeLists.txt file.";
|
||||
switch (mf->GetPolicyStatus(cmPolicies::CMP0014))
|
||||
{
|
||||
case cmPolicies::WARN:
|
||||
// Print the warning.
|
||||
e << "\n"
|
||||
<< "CMake does not support this case but it used "
|
||||
<< "to work accidentally and is being allowed for "
|
||||
<< "compatibility."
|
||||
<< "\n"
|
||||
<< mf->GetPolicies()->GetPolicyWarning(cmPolicies::CMP0014);
|
||||
mf->IssueMessage(cmake::AUTHOR_WARNING, e.str());
|
||||
case cmPolicies::OLD:
|
||||
// OLD behavior does not warn.
|
||||
return;
|
||||
case cmPolicies::REQUIRED_IF_USED:
|
||||
case cmPolicies::REQUIRED_ALWAYS:
|
||||
e << "\n"
|
||||
<< mf->GetPolicies()->GetRequiredPolicyError(cmPolicies::CMP0014);
|
||||
case cmPolicies::NEW:
|
||||
// NEW behavior prints the error.
|
||||
mf->IssueMessage(cmake::FATAL_ERROR, e.str());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void cmLocalGenerator::SetupPathConversions()
|
||||
|
|
|
@ -387,6 +387,18 @@ cmPolicies::cmPolicies()
|
|||
"The NEW behavior for this policy is to disallow duplicate binary "
|
||||
"directories with an error.",
|
||||
2,6,5, cmPolicies::WARN);
|
||||
|
||||
this->DefinePolicy(
|
||||
CMP0014, "CMP0014",
|
||||
"Input directories must have CMakeLists.txt.",
|
||||
"CMake versions before 2.8 silently ignored missing CMakeLists.txt "
|
||||
"files in directories referenced by add_subdirectory() or subdirs(), "
|
||||
"treating them as if present but empty. "
|
||||
"In CMake 2.8.0 and above this policy determines whether or not "
|
||||
"the case is an error. "
|
||||
"The OLD behavior for this policy is to silently ignore the problem. "
|
||||
"The NEW behavior for this policy is to report an error.",
|
||||
2,7,20090902, cmPolicies::WARN);
|
||||
}
|
||||
|
||||
cmPolicies::~cmPolicies()
|
||||
|
|
|
@ -54,6 +54,7 @@ public:
|
|||
CMP0011, // Strong policy scope for include and find_package
|
||||
CMP0012, // Strong handling of boolean constants
|
||||
CMP0013, // Duplicate binary directories not allowed
|
||||
CMP0014, // Input directories must have CMakeLists.txt
|
||||
|
||||
// Always the last entry. Useful mostly to avoid adding a comma
|
||||
// the last policy when adding a new one.
|
||||
|
|
Loading…
Reference in New Issue