Ninja: ensure output directories exist

This commit is contained in:
Peter Kuemmel 2012-04-06 17:40:22 +02:00
parent 15f238fd6e
commit 8217c26813
2 changed files with 25 additions and 6 deletions

View File

@ -47,8 +47,7 @@ cmNinjaNormalTargetGenerator(cmTarget* target)
{ {
// on Windows the output dir is already needed at compile time // on Windows the output dir is already needed at compile time
// ensure the directory exists (OutDir test) // ensure the directory exists (OutDir test)
std::string outpath = target->GetDirectory(this->GetConfigName()); EnsureDirectoryExists(target->GetDirectory(this->GetConfigName()));
cmSystemTools::MakeDirectory(outpath.c_str());
} }
} }
@ -56,6 +55,18 @@ cmNinjaNormalTargetGenerator::~cmNinjaNormalTargetGenerator()
{ {
} }
void cmNinjaNormalTargetGenerator::EnsureDirectoryExists(const std::string& dir)
{
cmSystemTools::MakeDirectory(dir.c_str());
}
void cmNinjaNormalTargetGenerator::EnsureParentDirectoryExists(const std::string& path)
{
EnsureDirectoryExists(cmSystemTools::GetParentDirectory(path.c_str()));
}
void cmNinjaNormalTargetGenerator::Generate() void cmNinjaNormalTargetGenerator::Generate()
{ {
if (!this->TargetLinkLanguage) { if (!this->TargetLinkLanguage) {
@ -380,13 +391,18 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement()
} }
} }
std::string path;
if (!this->TargetNameImport.empty()) { if (!this->TargetNameImport.empty()) {
vars["TARGET_IMPLIB"] = this->GetLocalGenerator()->ConvertToOutputFormat( path = this->GetLocalGenerator()->ConvertToOutputFormat(
targetOutputImplib.c_str(), cmLocalGenerator::SHELL); targetOutputImplib.c_str(), cmLocalGenerator::SHELL);
vars["TARGET_IMPLIB"] = path;
EnsureParentDirectoryExists(path);
} }
vars["TARGET_PDB"] = this->GetLocalGenerator()->ConvertToOutputFormat( path = this->GetLocalGenerator()->ConvertToOutputFormat(
this->GetTargetPDB().c_str(), cmLocalGenerator::SHELL); this->GetTargetPDB().c_str(), cmLocalGenerator::SHELL);
vars["TARGET_PDB"] = path;
EnsureParentDirectoryExists(path);
std::vector<cmCustomCommand> *cmdLists[3] = { std::vector<cmCustomCommand> *cmdLists[3] = {
&this->GetTarget()->GetPreBuildCommands(), &this->GetTarget()->GetPreBuildCommands(),

View File

@ -35,6 +35,9 @@ private:
void WriteObjectLibStatement(); void WriteObjectLibStatement();
std::vector<std::string> ComputeLinkCmd(); std::vector<std::string> ComputeLinkCmd();
void EnsureDirectoryExists(const std::string& dir);
void EnsureParentDirectoryExists(const std::string& path);
private: private:
// Target name info. // Target name info.
std::string TargetNameOut; std::string TargetNameOut;