ENH: Enforce unique binary directories
The second argument of add_subdirectory must name a unique binary directory or the build files will clobber each other. This enforces uniqueness with an error message.
This commit is contained in:
parent
99b37665c9
commit
1d3308156e
|
@ -732,18 +732,22 @@ void cmGlobalGenerator::Configure()
|
|||
this->ProjectMap.clear();
|
||||
this->RuleHashes.clear();
|
||||
this->DirectoryContentMap.clear();
|
||||
this->BinaryDirectories.clear();
|
||||
|
||||
// start with this directory
|
||||
cmLocalGenerator *lg = this->CreateLocalGenerator();
|
||||
this->LocalGenerators.push_back(lg);
|
||||
|
||||
// set the Start directories
|
||||
cmMakefile* mf = lg->GetMakefile();
|
||||
lg->GetMakefile()->SetStartDirectory
|
||||
(this->CMakeInstance->GetStartDirectory());
|
||||
lg->GetMakefile()->SetStartOutputDirectory
|
||||
(this->CMakeInstance->GetStartOutputDirectory());
|
||||
lg->GetMakefile()->MakeStartDirectoriesCurrent();
|
||||
|
||||
this->BinaryDirectories.insert(mf->GetStartOutputDirectory());
|
||||
|
||||
// now do it
|
||||
lg->Configure();
|
||||
|
||||
|
|
|
@ -253,6 +253,12 @@ public:
|
|||
void AddRuleHash(const std::vector<std::string>& outputs,
|
||||
std::string const& content);
|
||||
|
||||
/** Return whether the given binary directory is unused. */
|
||||
bool BinaryDirectoryIsNew(const char* dir)
|
||||
{
|
||||
return this->BinaryDirectories.insert(dir).second;
|
||||
}
|
||||
|
||||
protected:
|
||||
// for a project collect all its targets by following depend
|
||||
// information, and also collect all the targets
|
||||
|
@ -350,6 +356,9 @@ private:
|
|||
derived(dc), LoadedFromDisk(dc.LoadedFromDisk) {}
|
||||
};
|
||||
std::map<cmStdString, DirectoryContent> DirectoryContentMap;
|
||||
|
||||
// Set of binary directories on disk.
|
||||
std::set<cmStdString> BinaryDirectories;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1536,6 +1536,21 @@ void cmMakefile::AddSubDirectory(const char* srcPath, const char *binPath,
|
|||
}
|
||||
}
|
||||
|
||||
// Make sure the binary directory is unique.
|
||||
cmGlobalGenerator* gg = this->LocalGenerator->GetGlobalGenerator();
|
||||
if(!gg->BinaryDirectoryIsNew(binPath))
|
||||
{
|
||||
cmOStringStream e;
|
||||
e << "The binary directory\n"
|
||||
<< " " << binPath << "\n"
|
||||
<< "is already used to build another source directory, so it cannot "
|
||||
<< "be used to build source directory\n"
|
||||
<< " " << srcPath << "\n"
|
||||
<< "Specify a unique binary directory name.";
|
||||
this->IssueMessage(cmake::FATAL_ERROR, e.str());
|
||||
return;
|
||||
}
|
||||
|
||||
// create a new local generator and set its parent
|
||||
cmLocalGenerator *lg2 =
|
||||
this->LocalGenerator->GetGlobalGenerator()->CreateLocalGenerator();
|
||||
|
|
Loading…
Reference in New Issue