Sfoglia il codice sorgente

ENH: Allow multiple OS X applications bundles to be created in a single build directory. Converted Info.plist files to be generated directly instead of configured with make variables. The MACOSX_BUNDLE_* variables are now properties (and vars for compatibility).

Brad King 17 anni fa
parent
commit
67f8c0fd10

+ 0 - 36
Modules/MacOSXBundleInfo.plist.in

@@ -1,36 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
-<plist version="1.0">
-<dict>
-	<key>CFBundleDevelopmentRegion</key>
-	<string>English</string>
-	<key>CFBundleExecutable</key>
-	<string>${MACOSX_BUNDLE_EXECUTABLE_NAME}</string>
-	<key>CFBundleGetInfoString</key>
-	<string>${MACOSX_BUNDLE_INFO_STRING}</string>
-	<key>CFBundleIconFile</key>
-	<string>${MACOSX_BUNDLE_ICON_FILE}</string>
-	<key>CFBundleIdentifier</key>
-	<string>${MACOSX_BUNDLE_GUI_IDENTIFIER}</string>
-	<key>CFBundleInfoDictionaryVersion</key>
-	<string>6.0</string>
-	<key>CFBundleLongVersionString</key>
-	<string>${MACOSX_BUNDLE_LONG_VERSION_STRING}</string>
-	<key>CFBundleName</key>
-	<string>${MACOSX_BUNDLE_BUNDLE_NAME}</string>
-	<key>CFBundlePackageType</key>
-	<string>APPL</string>
-	<key>CFBundleShortVersionString</key>
-	<string>${MACOSX_BUNDLE_SHORT_VERSION_STRING}</string>
-	<key>CFBundleSignature</key>
-	<string>????</string>
-	<key>CFBundleVersion</key>
-	<string>${MACOSX_BUNDLE_BUNDLE_VERSION}</string>
-	<key>CSResourcesFileMapped</key>
-	<true/>
-	<key>LSRequiresCarbon</key>
-	<true/>
-	<key>NSHumanReadableCopyright</key>
-	<string>${MACOSX_BUNDLE_COPYRIGHT}</string>
-</dict>
-</plist>

+ 0 - 28
Modules/MacOSXFrameworkInfo.plist.in

@@ -1,28 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
-<plist version="1.0">
-<dict>
-	<key>CFBundleDevelopmentRegion</key>
-	<string>English</string>
-	<key>CFBundleExecutable</key>
-	<string>${MACOSX_FRAMEWORK_NAME}</string>
-	<key>CFBundleGetInfoString</key>
-	<string>${MACOSX_FRAMEWORK_INFO_STRING}</string>
-	<key>CFBundleIdentifier</key>
-	<string>${MACOSX_FRAMEWORK_IDENTIFIER}</string>
-	<key>CFBundleInfoDictionaryVersion</key>
-	<string>6.0</string>
-	<key>CFBundlePackageType</key>
-	<string>FMWK</string>
-	<key>CFBundleShortVersionString</key>
-	<string>${MACOSX_FRAMEWORK_SHORT_VERSION_STRING}</string>
-	<key>CFBundleSignature</key>
-	<string>????</string>
-	<key>CFBundleVersion</key>
-	<string>${MACOSX_FRAMEWORK_BUNDLE_VERSION}</string>
-	<key>CSResourcesFileMapped</key>
-	<true/>
-	<key>NSHumanReadableCopyright</key>
-	<string>${MACOSX_FRAMEWORK_COPYRIGHT}</string>
-</dict>
-</plist>

+ 9 - 12
Source/cmGlobalXCodeGenerator.cxx

@@ -1482,18 +1482,15 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target,
     if(target.GetPropertyAsBool("MACOSX_BUNDLE"))
       {
       productType = "com.apple.product-type.application";
-      std::string f1 =
-        this->CurrentMakefile->GetModulesFile("MacOSXBundleInfo.plist.in");
-      if ( f1.size() == 0 )
-        {
-        cmSystemTools::Error("could not find Mac OSX bundle template file.");
-        }
-      std::string f2 = this->CurrentMakefile->GetCurrentOutputDirectory();
-      f2 += "/Info.plist";
-      this->CurrentMakefile->ConfigureFile(f1.c_str(), f2.c_str(),
-                                       false, false, false);
-      std::string path = 
-        this->ConvertToRelativeForXCode(f2.c_str());
+      std::string plist = this->CurrentMakefile->GetCurrentOutputDirectory();
+      plist += cmake::GetCMakeFilesDirectory();
+      plist += "/";
+      plist += target.GetName();
+      plist += "Info.plist";
+      this->CurrentLocalGenerator
+        ->GenerateAppleInfoPList(&target, productName.c_str(), plist.c_str());
+      std::string path =
+        this->ConvertToRelativeForXCode(plist.c_str());
       buildSettings->AddAttribute("INFOPLIST_FILE", 
                                   this->CreateString(path.c_str()));
 

+ 83 - 0
Source/cmLocalGenerator.cxx

@@ -2732,3 +2732,86 @@ bool cmLocalGenerator::CheckDefinition(std::string const& define) const
   // Assume it is supported.
   return true;
 }
+
+//----------------------------------------------------------------------------
+static std::string cmLGInfoProp(cmTarget* target, const char* prop)
+{
+  if(const char* val = target->GetProperty(prop))
+    {
+    return val;
+    }
+  else
+    {
+    // For compatibility check for a variable.
+    return target->GetMakefile()->GetSafeDefinition(prop);
+    }
+}
+
+//----------------------------------------------------------------------------
+void cmLocalGenerator::GenerateAppleInfoPList(cmTarget* target,
+                                              const char* targetName,
+                                              const char* fname)
+{
+  std::string info_EXECUTABLE_NAME = targetName;
+
+  // Lookup the properties.
+  std::string info_INFO_STRING =
+    cmLGInfoProp(target, "MACOSX_BUNDLE_INFO_STRING");
+  std::string info_ICON_FILE =
+    cmLGInfoProp(target, "MACOSX_BUNDLE_ICON_FILE");
+  std::string info_GUI_IDENTIFIER =
+    cmLGInfoProp(target, "MACOSX_BUNDLE_GUI_IDENTIFIER");
+  std::string info_LONG_VERSION_STRING =
+    cmLGInfoProp(target, "MACOSX_BUNDLE_LONG_VERSION_STRING");
+  std::string info_BUNDLE_NAME =
+    cmLGInfoProp(target, "MACOSX_BUNDLE_BUNDLE_NAME");
+  std::string info_SHORT_VERSION_STRING =
+    cmLGInfoProp(target, "MACOSX_BUNDLE_SHORT_VERSION_STRING");
+  std::string info_BUNDLE_VERSION =
+    cmLGInfoProp(target, "MACOSX_BUNDLE_BUNDLE_VERSION");
+  std::string info_COPYRIGHT =
+    cmLGInfoProp(target, "MACOSX_BUNDLE_COPYRIGHT");
+
+  // Generate the file.
+  cmGeneratedFileStream fout(fname);
+  fout.SetCopyIfDifferent(true);
+  fout <<
+    "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+    "<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\"\n"
+    "  \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n"
+    "<plist version=\"1.0\">\n"
+    "<dict>\n"
+    "\t<key>CFBundleDevelopmentRegion</key>\n"
+    "\t<string>English</string>\n"
+    "\t<key>CFBundleExecutable</key>\n"
+    "\t<string>" << info_EXECUTABLE_NAME << "</string>\n"
+    "\t<key>CFBundleGetInfoString</key>\n"
+    "\t<string>" << info_INFO_STRING << "</string>\n"
+    "\t<key>CFBundleIconFile</key>\n"
+    "\t<string>" << info_ICON_FILE << "</string>\n"
+    "\t<key>CFBundleIdentifier</key>\n"
+    "\t<string>" << info_GUI_IDENTIFIER << "</string>\n"
+    "\t<key>CFBundleInfoDictionaryVersion</key>\n"
+    "\t<string>6.0</string>\n"
+    "\t<key>CFBundleLongVersionString</key>\n"
+    "\t<string>" << info_LONG_VERSION_STRING << "</string>\n"
+    "\t<key>CFBundleName</key>\n"
+    "\t<string>" << info_BUNDLE_NAME << "</string>\n"
+    "\t<key>CFBundlePackageType</key>\n"
+    "\t<string>APPL</string>\n"
+    "\t<key>CFBundleShortVersionString</key>\n"
+    "\t<string>" << info_SHORT_VERSION_STRING << "</string>\n"
+    "\t<key>CFBundleSignature</key>\n"
+    "\t<string>????" /* break string to avoid trigraph */ "</string>\n"
+    "\t<key>CFBundleVersion</key>\n"
+    "\t<string>" << info_BUNDLE_VERSION << "</string>\n"
+    "\t<key>CSResourcesFileMapped</key>\n"
+    "\t<true/>\n"
+    "\t<key>LSRequiresCarbon</key>\n"
+    "\t<true/>\n"
+    "\t<key>NSHumanReadableCopyright</key>\n"
+    "\t<string>" << info_COPYRIGHT << "</string>\n"
+    "</dict>\n"
+    "</plist>\n"
+    ;
+}

+ 6 - 0
Source/cmLocalGenerator.h

@@ -269,6 +269,12 @@ public:
   bool NeedBackwardsCompatibility(unsigned int major,
                                   unsigned int minor,
                                   unsigned int patch = 0xFFu);
+
+  /**
+   * Generate a Mac OS X application bundle Info.plist file.
+   */
+  void GenerateAppleInfoPList(cmTarget* target, const char* targetName,
+                              const char* fname);
 protected:
   /** Construct a comment for a custom command.  */
   std::string ConstructComment(const cmCustomCommand& cc,

+ 4 - 12
Source/cmMakefileExecutableTargetGenerator.cxx

@@ -133,13 +133,6 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink)
     outpath += "/";
 
     // Make bundle directories
-    std::string f1 =
-      this->Makefile->GetModulesFile("MacOSXBundleInfo.plist.in");
-    if ( f1.size() == 0 )
-      {
-      cmSystemTools::Error("could not find Mac OSX bundle template file.");
-      }
-
     std::vector<cmSourceFile*>::const_iterator sourceIt;
     for ( sourceIt = this->Target->GetSourceFiles().begin();
       sourceIt != this->Target->GetSourceFiles().end();
@@ -162,11 +155,10 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink)
 
     // Configure the Info.plist file.  Note that it needs the executable name
     // to be set.
-    std::string f2 = macdir + "Info.plist";
-    this->Makefile->AddDefinition("MACOSX_BUNDLE_EXECUTABLE_NAME",
-                                  targetName.c_str());
-    this->Makefile->ConfigureFile(f1.c_str(), f2.c_str(), 
-                                  false, false, false);
+    std::string plist = macdir + "Info.plist";
+    this->LocalGenerator->GenerateAppleInfoPList(this->Target,
+                                                 targetName.c_str(),
+                                                 plist.c_str());
     }
 #endif
   std::string outpathImp;

+ 0 - 16
Source/cmMakefileLibraryTargetGenerator.cxx

@@ -364,22 +364,6 @@ void cmMakefileLibraryTargetGenerator::CreateFramework(
 
   //cmSystemTools::MakeDirectory((macdir + "Libraries").c_str());
   cmSystemTools::MakeDirectory((macdir + "Headers").c_str());
-  // Configure the Info.plist file.  Note that it needs the executable name
-  // to be set
-  std::string rsrcDir = macdir + "Resources/";
-  cmSystemTools::MakeDirectory(rsrcDir.c_str());
-  this->Makefile->AddDefinition("MACOSX_FRAMEWORK_NAME",
-                                targetName.c_str());
-  std::string f1 = 
-    this->Makefile->GetModulesFile("MacOSXFrameworkInfo.plist.in");
-  if ( f1.size() == 0 )
-    {
-    cmSystemTools::Error(
-      "could not find Mac OSX framework Info.plist template file.");
-    }
-  std::string f2 = rsrcDir + "Info.plist";
-  this->Makefile->ConfigureFile(f1.c_str(), f2.c_str(),
-                                false, false, false);
 
   this->CopyFrameworkSources(targetName, outpath, version,
     "PRIVATE_HEADER", "PrivateHeaders");

+ 13 - 1
Source/cmTarget.cxx

@@ -510,7 +510,19 @@ void cmTarget::DefineProperties(cmake *cm)
      "When this property is set to true the executable when built "
      "on Mac OS X will be created as an application bundle.  "
      "This makes it a GUI executable that can be launched from "
-     "the Finder.");
+     "the Finder.\n"
+     "The bundle Info.plist file is generated automatically.  "
+     "The following target properties may be set to specify "
+     "its content:"
+     "  MACOSX_BUNDLE_INFO_STRING\n"
+     "  MACOSX_BUNDLE_ICON_FILE\n"
+     "  MACOSX_BUNDLE_GUI_IDENTIFIER\n"
+     "  MACOSX_BUNDLE_LONG_VERSION_STRING\n"
+     "  MACOSX_BUNDLE_BUNDLE_NAME\n"
+     "  MACOSX_BUNDLE_SHORT_VERSION_STRING\n"
+     "  MACOSX_BUNDLE_BUNDLE_VERSION\n"
+     "  MACOSX_BUNDLE_COPYRIGHT\n"
+      );
 
   cm->DefineProperty
     ("ENABLE_EXPORTS", cmProperty::TARGET,