From f89dae7a9473a05ecd2ccbfe409b6f33523da603 Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 2 Sep 2008 12:06:32 -0400 Subject: [PATCH] ENH: Create Info.plist files in OS X Frameworks A Mac OS X Framework should provide a Resources/Info.plist file containing meta-data about the framework. This change generates a default Info.plist for frameworks and provides an interface for users to customize it. --- Modules/MacOSXFrameworkInfo.plist.in | 26 ++++++++++++++ Source/cmGlobalXCodeGenerator.cxx | 12 +++++++ Source/cmLocalGenerator.cxx | 40 +++++++++++++++++++++ Source/cmLocalGenerator.h | 7 ++++ Source/cmMakefileLibraryTargetGenerator.cxx | 13 +++++-- Source/cmMakefileLibraryTargetGenerator.h | 2 +- Source/cmTarget.cxx | 20 +++++++++++ 7 files changed, 117 insertions(+), 3 deletions(-) create mode 100644 Modules/MacOSXFrameworkInfo.plist.in diff --git a/Modules/MacOSXFrameworkInfo.plist.in b/Modules/MacOSXFrameworkInfo.plist.in new file mode 100644 index 000000000..18eaef2f7 --- /dev/null +++ b/Modules/MacOSXFrameworkInfo.plist.in @@ -0,0 +1,26 @@ + + + + + CFBundleDevelopmentRegion + English + CFBundleExecutable + ${MACOSX_FRAMEWORK_NAME} + CFBundleIconFile + ${MACOSX_FRAMEWORK_ICON_FILE} + CFBundleIdentifier + ${MACOSX_FRAMEWORK_IDENTIFIER} + CFBundleInfoDictionaryVersion + 6.0 + CFBundlePackageType + FMWK + CFBundleSignature + ???? + CFBundleVersion + ${MACOSX_FRAMEWORK_BUNDLE_VERSION} + CFBundleShortVersionString + ${MACOSX_FRAMEWORK_SHORT_VERSION_STRING} + CSResourcesFileMapped + + + diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index 2e00d1358..f9d444557 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -1436,6 +1436,18 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target, std::string version = target.GetFrameworkVersion(); buildSettings->AddAttribute("FRAMEWORK_VERSION", this->CreateString(version.c_str())); + + std::string plist = this->ComputeInfoPListLocation(target); + // Xcode will create the final version of Info.plist at build time, + // so let it replace the framework name. This avoids creating + // a per-configuration Info.plist file. + this->CurrentLocalGenerator + ->GenerateFrameworkInfoPList(&target, "$(EXECUTABLE_NAME)", + plist.c_str()); + std::string path = + this->ConvertToRelativeForXCode(plist.c_str()); + buildSettings->AddAttribute("INFOPLIST_FILE", + this->CreateString(path.c_str())); } else { diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index 52322ff01..c1922631b 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -2863,3 +2863,43 @@ void cmLocalGenerator::GenerateAppleInfoPList(cmTarget* target, mf->ConfigureFile(inFile.c_str(), fname, false, false, false); mf->PopScope(); } + +//---------------------------------------------------------------------------- +void cmLocalGenerator::GenerateFrameworkInfoPList(cmTarget* target, + const char* targetName, + const char* fname) +{ + // Find the Info.plist template. + const char* in = target->GetProperty("MACOSX_FRAMEWORK_INFO_PLIST"); + std::string inFile = (in && *in)? in : "MacOSXFrameworkInfo.plist.in"; + if(!cmSystemTools::FileIsFullPath(inFile.c_str())) + { + std::string inMod = this->Makefile->GetModulesFile(inFile.c_str()); + if(!inMod.empty()) + { + inFile = inMod; + } + } + if(!cmSystemTools::FileExists(inFile.c_str(), true)) + { + cmOStringStream e; + e << "Target " << target->GetName() << " Info.plist template \"" + << inFile << "\" could not be found."; + cmSystemTools::Error(e.str().c_str()); + return; + } + + // Convert target properties to variables in an isolated makefile + // scope to configure the file. If properties are set they will + // override user make variables. If not the configuration will fall + // back to the directory-level values set by the user. + cmMakefile* mf = this->Makefile; + mf->PushScope(); + mf->AddDefinition("MACOSX_FRAMEWORK_NAME", targetName); + cmLGInfoProp(mf, target, "MACOSX_FRAMEWORK_ICON_FILE"); + cmLGInfoProp(mf, target, "MACOSX_FRAMEWORK_IDENTIFIER"); + cmLGInfoProp(mf, target, "MACOSX_FRAMEWORK_SHORT_VERSION_STRING"); + cmLGInfoProp(mf, target, "MACOSX_FRAMEWORK_BUNDLE_VERSION"); + mf->ConfigureFile(inFile.c_str(), fname, false, false, false); + mf->PopScope(); +} diff --git a/Source/cmLocalGenerator.h b/Source/cmLocalGenerator.h index 1be0aa47b..d528d2fcc 100644 --- a/Source/cmLocalGenerator.h +++ b/Source/cmLocalGenerator.h @@ -275,6 +275,13 @@ public: */ void GenerateAppleInfoPList(cmTarget* target, const char* targetName, const char* fname); + + /** + * Generate a Mac OS X framework Info.plist file. + */ + void GenerateFrameworkInfoPList(cmTarget* target, + const char* targetName, + const char* fname); protected: /** Construct a comment for a custom command. */ std::string ConstructComment(const cmCustomCommand& cc, diff --git a/Source/cmMakefileLibraryTargetGenerator.cxx b/Source/cmMakefileLibraryTargetGenerator.cxx index 7bd12a04e..9c0cc3848 100644 --- a/Source/cmMakefileLibraryTargetGenerator.cxx +++ b/Source/cmMakefileLibraryTargetGenerator.cxx @@ -235,8 +235,17 @@ void cmMakefileLibraryTargetGenerator::WriteFrameworkRules(bool relink) } //---------------------------------------------------------------------------- -void cmMakefileLibraryTargetGenerator::CreateFramework() +void +cmMakefileLibraryTargetGenerator +::CreateFramework(std::string const& targetName) { + // Configure the Info.plist file into the Resources directory. + this->MacContentFolders.insert("Resources"); + std::string plist = this->MacContentDirectory + "Resources/Info.plist"; + this->LocalGenerator->GenerateFrameworkInfoPList(this->Target, + targetName.c_str(), + plist.c_str()); + // TODO: Use the cmMakefileTargetGenerator::ExtraFiles vector to // drive rules to create these files at build time. std::string oldName; @@ -388,7 +397,7 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules if(this->Target->IsFrameworkOnApple()) { outpath = this->MacContentDirectory; - this->CreateFramework(); + this->CreateFramework(targetName); } else if(relink) { diff --git a/Source/cmMakefileLibraryTargetGenerator.h b/Source/cmMakefileLibraryTargetGenerator.h index e5f9482fa..8aa17cd2c 100644 --- a/Source/cmMakefileLibraryTargetGenerator.h +++ b/Source/cmMakefileLibraryTargetGenerator.h @@ -37,7 +37,7 @@ protected: bool relink); // MacOSX Framework support methods void WriteFrameworkRules(bool relink); - void CreateFramework(); + void CreateFramework(std::string const& targetName); // Store the computd framework version for OS X Frameworks. std::string FrameworkVersion; diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index e4d7307cd..0fbae69b8 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -588,6 +588,26 @@ void cmTarget::DefineProperties(cmake *cm) "If a custom Info.plist is specified by this property it may of course " "hard-code all the settings instead of using the target properties."); + cm->DefineProperty + ("MACOSX_FRAMEWORK_INFO_PLIST", cmProperty::TARGET, + "Specify a custom Info.plist template for a Mac OS X Framework.", + "An library target with FRAMEWORK enabled will be built as a " + "framework on Mac OS X. " + "By default its Info.plist file is created by configuring a template " + "called MacOSXFrameworkInfo.plist.in located in the CMAKE_MODULE_PATH. " + "This property specifies an alternative template file name which " + "may be a full path.\n" + "The following target properties may be set to specify content to " + "be configured into the file:\n" + " MACOSX_FRAMEWORK_ICON_FILE\n" + " MACOSX_FRAMEWORK_IDENTIFIER\n" + " MACOSX_FRAMEWORK_SHORT_VERSION_STRING\n" + " MACOSX_FRAMEWORK_BUNDLE_VERSION\n" + "CMake variables of the same name may be set to affect all targets " + "in a directory that do not have each specific property set. " + "If a custom Info.plist is specified by this property it may of course " + "hard-code all the settings instead of using the target properties."); + cm->DefineProperty ("ENABLE_EXPORTS", cmProperty::TARGET, "Specify whether an executable exports symbols for loadable modules.",