[PATCH 1/2] Ninja: ensure output directories exist

Peter Kuemmel syntheticpp at gmx.net
Fri Apr 6 11:40:22 EDT 2012


---
 Source/cmNinjaNormalTargetGenerator.cxx |   28 ++++++++++++++++++++++------
 Source/cmNinjaNormalTargetGenerator.h   |    3 +++
 2 files changed, 25 insertions(+), 6 deletions(-)

diff --git a/Source/cmNinjaNormalTargetGenerator.cxx b/Source/cmNinjaNormalTargetGenerator.cxx
index 2bad32c..2bfe814 100644
--- a/Source/cmNinjaNormalTargetGenerator.cxx
+++ b/Source/cmNinjaNormalTargetGenerator.cxx
@@ -47,8 +47,7 @@ cmNinjaNormalTargetGenerator(cmTarget* target)
     {
     // on Windows the output dir is already needed at compile time
     // ensure the directory exists (OutDir test)
-    std::string outpath = target->GetDirectory(this->GetConfigName());
-    cmSystemTools::MakeDirectory(outpath.c_str());
+    EnsureDirectoryExists(target->GetDirectory(this->GetConfigName()));
     }
 }
 
@@ -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()
 {
   if (!this->TargetLinkLanguage) {
@@ -380,13 +391,18 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement()
     }
   }
 
+  std::string path;
   if (!this->TargetNameImport.empty()) {
-    vars["TARGET_IMPLIB"] = this->GetLocalGenerator()->ConvertToOutputFormat(
-      targetOutputImplib.c_str(), cmLocalGenerator::SHELL);
+    path = this->GetLocalGenerator()->ConvertToOutputFormat(
+                    targetOutputImplib.c_str(), cmLocalGenerator::SHELL);
+    vars["TARGET_IMPLIB"] = path;
+    EnsureParentDirectoryExists(path);
   }
 
-  vars["TARGET_PDB"] = this->GetLocalGenerator()->ConvertToOutputFormat(
-    this->GetTargetPDB().c_str(), cmLocalGenerator::SHELL);
+  path = this->GetLocalGenerator()->ConvertToOutputFormat(
+                   this->GetTargetPDB().c_str(), cmLocalGenerator::SHELL);
+  vars["TARGET_PDB"] = path;
+  EnsureParentDirectoryExists(path);
 
   std::vector<cmCustomCommand> *cmdLists[3] = {
     &this->GetTarget()->GetPreBuildCommands(),
diff --git a/Source/cmNinjaNormalTargetGenerator.h b/Source/cmNinjaNormalTargetGenerator.h
index 1702caf..7acbe8f 100644
--- a/Source/cmNinjaNormalTargetGenerator.h
+++ b/Source/cmNinjaNormalTargetGenerator.h
@@ -35,6 +35,9 @@ private:
   void WriteObjectLibStatement();
   std::vector<std::string> ComputeLinkCmd();
 
+  void EnsureDirectoryExists(const std::string& dir);
+  void EnsureParentDirectoryExists(const std::string& path);
+
 private:
   // Target name info.
   std::string TargetNameOut;
-- 
1.7.4.msysgit.0


--------------080103010908070303020502--


More information about the cmake-developers mailing list