浏览代码

Re-factor Mac OS X content directory computation.

Nicolas Despres 13 年之前
父节点
当前提交
f36c7b0bbe
共有 4 个文件被更改,包括 106 次插入77 次删除
  1. 28 32
      Source/cmOSXBundleGenerator.cxx
  2. 3 0
      Source/cmOSXBundleGenerator.h
  3. 62 45
      Source/cmTarget.cxx
  4. 13 0
      Source/cmTarget.h

+ 28 - 32
Source/cmOSXBundleGenerator.cxx

@@ -39,49 +39,36 @@ cmOSXBundleGenerator(cmTarget* target,
  , FrameworkVersion()
  , FrameworkVersion()
  , MacContentFolders(0)
  , MacContentFolders(0)
 {
 {
-  if(this->Target->IsAppBundleOnApple())
-    {
-    this->MacContentDirectory = this->Target->GetDirectory(this->ConfigName);
-    this->MacContentDirectory += "/";
-    this->MacContentDirectory += this->TargetNameOut;
-    this->MacContentDirectory += ".app/Contents/";
-    }
-  else if(this->Target->IsFrameworkOnApple())
-    {
+  if (this->MustSkip())
+    return;
+
+  this->MacContentDirectory =
+    this->Target->GetMacContentDirectory(this->ConfigName,
+                                         /*implib*/ false,
+                                         /*includeMacOS*/ false);
+  if(this->Target->IsFrameworkOnApple())
     this->FrameworkVersion = this->Target->GetFrameworkVersion();
     this->FrameworkVersion = this->Target->GetFrameworkVersion();
-    this->MacContentDirectory = this->Target->GetDirectory(this->ConfigName);
-    this->MacContentDirectory += "/";
-    this->MacContentDirectory += this->TargetNameOut;
-    this->MacContentDirectory += ".framework/Versions/";
-    this->MacContentDirectory += this->FrameworkVersion;
-    this->MacContentDirectory += "/";
-    }
-  else if(this->Target->IsCFBundleOnApple())
-    {
-    this->MacContentDirectory = this->Target->GetDirectory(this->ConfigName);
-    this->MacContentDirectory += "/";
-    this->MacContentDirectory += this->TargetNameOut;
-    this->MacContentDirectory += ".";
-    const char *ext = this->Target->GetProperty("BUNDLE_EXTENSION");
-    if (!ext)
-      {
-      ext = "bundle";
-      }
-    this->MacContentDirectory += ext;
-    this->MacContentDirectory += "/Contents/";
-    }
+}
+
+//----------------------------------------------------------------------------
+bool cmOSXBundleGenerator::MustSkip()
+{
+  return !this->Target->HaveWellDefinedOutputFiles();
 }
 }
 
 
 //----------------------------------------------------------------------------
 //----------------------------------------------------------------------------
 void cmOSXBundleGenerator::CreateAppBundle(std::string& targetName,
 void cmOSXBundleGenerator::CreateAppBundle(std::string& targetName,
                                            std::string& outpath)
                                            std::string& outpath)
 {
 {
+  if (this->MustSkip())
+    return;
+
   // Compute bundle directory names.
   // Compute bundle directory names.
   outpath = this->MacContentDirectory;
   outpath = this->MacContentDirectory;
   outpath += "MacOS";
   outpath += "MacOS";
   cmSystemTools::MakeDirectory(outpath.c_str());
   cmSystemTools::MakeDirectory(outpath.c_str());
-  this->Makefile->AddCMakeOutputFile(outpath.c_str());
   outpath += "/";
   outpath += "/";
+  this->Makefile->AddCMakeOutputFile(outpath.c_str());
 
 
   // Configure the Info.plist file.  Note that it needs the executable name
   // Configure the Info.plist file.  Note that it needs the executable name
   // to be set.
   // to be set.
@@ -95,6 +82,9 @@ void cmOSXBundleGenerator::CreateAppBundle(std::string& targetName,
 //----------------------------------------------------------------------------
 //----------------------------------------------------------------------------
 void cmOSXBundleGenerator::CreateFramework(std::string const& targetName)
 void cmOSXBundleGenerator::CreateFramework(std::string const& targetName)
 {
 {
+  if (this->MustSkip())
+    return;
+
   assert(this->MacContentFolders);
   assert(this->MacContentFolders);
 
 
   // Configure the Info.plist file into the Resources directory.
   // Configure the Info.plist file into the Resources directory.
@@ -184,12 +174,15 @@ void cmOSXBundleGenerator::CreateFramework(std::string const& targetName)
 void cmOSXBundleGenerator::CreateCFBundle(std::string& targetName,
 void cmOSXBundleGenerator::CreateCFBundle(std::string& targetName,
                                           std::string& outpath)
                                           std::string& outpath)
 {
 {
+  if (this->MustSkip())
+    return;
+
   // Compute bundle directory names.
   // Compute bundle directory names.
   outpath = this->MacContentDirectory;
   outpath = this->MacContentDirectory;
   outpath += "MacOS";
   outpath += "MacOS";
   cmSystemTools::MakeDirectory(outpath.c_str());
   cmSystemTools::MakeDirectory(outpath.c_str());
-  this->Makefile->AddCMakeOutputFile(outpath.c_str());
   outpath += "/";
   outpath += "/";
+  this->Makefile->AddCMakeOutputFile(outpath.c_str());
 
 
   // Configure the Info.plist file.  Note that it needs the executable name
   // Configure the Info.plist file.  Note that it needs the executable name
   // to be set.
   // to be set.
@@ -207,6 +200,9 @@ cmOSXBundleGenerator::
 GenerateMacOSXContentStatements(std::vector<cmSourceFile*> const& sources,
 GenerateMacOSXContentStatements(std::vector<cmSourceFile*> const& sources,
                                 MacOSXContentGeneratorType* generator)
                                 MacOSXContentGeneratorType* generator)
 {
 {
+  if (this->MustSkip())
+    return;
+
   for(std::vector<cmSourceFile*>::const_iterator
   for(std::vector<cmSourceFile*>::const_iterator
         si = sources.begin(); si != sources.end(); ++si)
         si = sources.begin(); si != sources.end(); ++si)
     {
     {

+ 3 - 0
Source/cmOSXBundleGenerator.h

@@ -52,6 +52,9 @@ public:
   void SetMacContentFolders(std::set<cmStdString>* macContentFolders)
   void SetMacContentFolders(std::set<cmStdString>* macContentFolders)
   { this->MacContentFolders = macContentFolders; }
   { this->MacContentFolders = macContentFolders; }
 
 
+private:
+  bool MustSkip();
+
 private:
 private:
   cmTarget* Target;
   cmTarget* Target;
   cmMakefile* Makefile;
   cmMakefile* Makefile;

+ 62 - 45
Source/cmTarget.cxx

@@ -2482,6 +2482,16 @@ void cmTarget::MarkAsImported()
   this->IsImportedTarget = true;
   this->IsImportedTarget = true;
 }
 }
 
 
+//----------------------------------------------------------------------------
+bool cmTarget::HaveWellDefinedOutputFiles()
+{
+  return
+    this->GetType() == cmTarget::STATIC_LIBRARY ||
+    this->GetType() == cmTarget::SHARED_LIBRARY ||
+    this->GetType() == cmTarget::MODULE_LIBRARY ||
+    this->GetType() == cmTarget::EXECUTABLE;
+}
+
 //----------------------------------------------------------------------------
 //----------------------------------------------------------------------------
 cmTarget::OutputInfo const* cmTarget::GetOutputInfo(const char* config)
 cmTarget::OutputInfo const* cmTarget::GetOutputInfo(const char* config)
 {
 {
@@ -2492,10 +2502,7 @@ cmTarget::OutputInfo const* cmTarget::GetOutputInfo(const char* config)
     }
     }
 
 
   // Only libraries and executables have well-defined output files.
   // Only libraries and executables have well-defined output files.
-  if(this->GetType() != cmTarget::STATIC_LIBRARY &&
-     this->GetType() != cmTarget::SHARED_LIBRARY &&
-     this->GetType() != cmTarget::MODULE_LIBRARY &&
-     this->GetType() != cmTarget::EXECUTABLE)
+  if(!this->HaveWellDefinedOutputFiles())
     {
     {
     std::string msg = "cmTarget::GetOutputInfo called for ";
     std::string msg = "cmTarget::GetOutputInfo called for ";
     msg += this->GetName();
     msg += this->GetName();
@@ -2586,18 +2593,7 @@ const char* cmTarget::NormalGetLocation(const char* config)
     this->Location += cfgid;
     this->Location += cfgid;
     this->Location += "/";
     this->Location += "/";
     }
     }
-  if(this->IsAppBundleOnApple())
-    {
-    this->Location += this->GetFullName(config, false);
-    this->Location += ".app/Contents/MacOS/";
-    }
-   if(this->IsFrameworkOnApple())
-    {
-    this->Location += this->GetFullName(config, false);
-    this->Location += ".framework/Versions/";
-    this->Location += this->GetFrameworkVersion();
-    this->Location += "/";
-    }
+  this->Location = this->BuildMacContentDirectory(this->Location, config);
   this->Location += this->GetFullName(config, false);
   this->Location += this->GetFullName(config, false);
   return this->Location.c_str();
   return this->Location.c_str();
 }
 }
@@ -3169,35 +3165,7 @@ std::string cmTarget::GetFullPath(const char* config, bool implib,
 std::string cmTarget::NormalGetFullPath(const char* config, bool implib,
 std::string cmTarget::NormalGetFullPath(const char* config, bool implib,
                                         bool realname)
                                         bool realname)
 {
 {
-  // TODO: Re-factor with cmOSXBundleGenerator's constructor.
-  // Start with the output directory for the target.
-  std::string fpath = this->GetDirectory(config, implib);
-  fpath += "/";
-
-  if(this->IsAppBundleOnApple())
-    {
-    fpath += this->GetFullName(config, false);
-    fpath += ".app/Contents/MacOS/";
-    }
-  if(this->IsFrameworkOnApple())
-    {
-    fpath += this->GetFullName(config, false);
-    fpath += ".framework/Versions/";
-    fpath += this->GetFrameworkVersion();
-    fpath += "/";
-    }
-  if(this->IsCFBundleOnApple())
-    {
-    fpath += this->GetFullName(config, false);
-    fpath += ".";
-    const char *ext = this->GetProperty("BUNDLE_EXTENSION");
-    if (!ext)
-      {
-      ext = "bundle";
-      }
-    fpath += ext;
-    fpath += "/Contents/MacOS/";
-    }
+  std::string fpath = this->GetMacContentDirectory(config, implib);
 
 
   // Add the full name of the target.
   // Add the full name of the target.
   if(implib)
   if(implib)
@@ -4746,6 +4714,55 @@ std::vector<std::string> cmTarget::GetIncludeDirectories()
   return orderedAndUniqueIncludes;
   return orderedAndUniqueIncludes;
 }
 }
 
 
+//----------------------------------------------------------------------------
+std::string cmTarget::BuildMacContentDirectory(const std::string& base,
+                                               const char* config,
+                                               bool includeMacOS)
+{
+  std::string fpath = base;
+  if(this->IsAppBundleOnApple())
+    {
+    fpath += this->GetFullName(config, false);
+    fpath += ".app/Contents/";
+    if(includeMacOS)
+      fpath += "MacOS/";
+    }
+  if(this->IsFrameworkOnApple())
+    {
+    fpath += this->GetFullName(config, false);
+    fpath += ".framework/Versions/";
+    fpath += this->GetFrameworkVersion();
+    fpath += "/";
+    }
+  if(this->IsCFBundleOnApple())
+    {
+    fpath += this->GetFullName(config, false);
+    fpath += ".";
+    const char *ext = this->GetProperty("BUNDLE_EXTENSION");
+    if (!ext)
+      {
+      ext = "bundle";
+      }
+    fpath += ext;
+    fpath += "/Contents/";
+    if(includeMacOS)
+      fpath += "MacOS/";
+    }
+  return fpath;
+}
+
+//----------------------------------------------------------------------------
+std::string cmTarget::GetMacContentDirectory(const char* config,
+                                             bool implib,
+                                             bool includeMacOS)
+{
+  // Start with the output directory for the target.
+  std::string fpath = this->GetDirectory(config, implib);
+  fpath += "/";
+  fpath = this->BuildMacContentDirectory(fpath, config, includeMacOS);
+  return fpath;
+}
+
 //----------------------------------------------------------------------------
 //----------------------------------------------------------------------------
 cmTargetLinkInformationMap
 cmTargetLinkInformationMap
 ::cmTargetLinkInformationMap(cmTargetLinkInformationMap const& r): derived()
 ::cmTargetLinkInformationMap(cmTargetLinkInformationMap const& r): derived()

+ 13 - 0
Source/cmTarget.h

@@ -465,6 +465,19 @@ public:
   /** Get the include directories for this target.  */
   /** Get the include directories for this target.  */
   std::vector<std::string> GetIncludeDirectories();
   std::vector<std::string> GetIncludeDirectories();
 
 
+  /** Append to @a base the mac content directory and return it. */
+  std::string BuildMacContentDirectory(const std::string& base,
+                                       const char* config = 0,
+                                       bool includeMacOS = true);
+
+  /** @return the mac content directory for this target. */
+  std::string GetMacContentDirectory(const char* config = 0,
+                                     bool implib = false,
+                                     bool includeMacOS = true);
+
+  /** @return whether this target have a well defined output file name. */
+  bool HaveWellDefinedOutputFiles();
+
 private:
 private:
   /**
   /**
    * A list of direct dependencies. Use in conjunction with DependencyMap.
    * A list of direct dependencies. Use in conjunction with DependencyMap.