From 7b1440ab9fef6d240eb5beb333ac606f966486a4 Mon Sep 17 00:00:00 2001 From: Bill Hoffman Date: Thu, 5 Jan 2006 09:13:06 -0500 Subject: [PATCH] ENH: fix bundles for Mac and Xcode --- Source/cmAddExecutableCommand.cxx | 23 ------------------- Source/cmGlobalXCodeGenerator.cxx | 28 ++++++++++++++++++++++++ Source/cmLocalUnixMakefileGenerator3.cxx | 21 ++++++++++++++++++ Source/cmMakefile.cxx | 1 + 4 files changed, 50 insertions(+), 23 deletions(-) diff --git a/Source/cmAddExecutableCommand.cxx b/Source/cmAddExecutableCommand.cxx index f70e790d3..71e338dc2 100644 --- a/Source/cmAddExecutableCommand.cxx +++ b/Source/cmAddExecutableCommand.cxx @@ -64,29 +64,6 @@ bool cmAddExecutableCommand::InitialPass(std::vector const& args) if ( use_macbundle) { tgt->SetProperty("MACOSX_BUNDLE", "ON"); -#ifdef __APPLE__ - std::string f1 = m_Makefile->GetModulesFile("MacOSXBundleInfo.plist.in"); - if ( f1.size() == 0 ) - { - this->SetError("could not find Mac OSX bundle template file."); - return false; - } - std::string macdir = m_Makefile->GetSafeDefinition("EXECUTABLE_OUTPUT_PATH"); - if ( macdir.size() == 0 ) - { - macdir = m_Makefile->GetCurrentOutputDirectory(); - } - if(macdir.size() && macdir[macdir.size()-1] != '/') - { - macdir += "/"; - } - macdir += exename + ".app/Contents/"; - std::string f2 = macdir + "Info.plist"; - macdir += "MacOS"; - cmSystemTools::MakeDirectory(macdir.c_str()); - m_Makefile->AddDefinition("MACOSX_BUNDLE_EXECUTABLE_NAME", exename.c_str()); - m_Makefile->ConfigureFile(f1.c_str(), f2.c_str(), false, false, false); -#endif } return true; diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index e4754b3f2..f8c4f5aad 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -505,6 +505,10 @@ cmGlobalXCodeGenerator::CreateXCodeSourceFile(cmLocalGenerator* lg, { sourcecode += ".cpp.objc"; } + else if(ext == "plist") + { + sourcecode += ".text.plist"; + } else if(!lang) { sourcecode += ext; @@ -1146,7 +1150,20 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target, fileType = "compiled.mach-o.executable"; if(target.GetPropertyAsBool("MACOSX_BUNDLE")) { + std::string f1 = m_CurrentMakefile->GetModulesFile("MacOSXBundleInfo.plist.in"); + if ( f1.size() == 0 ) + { + cmSystemTools::Error("could not find Mac OSX bundle template file."); + } + std::string f2 = m_CurrentMakefile->GetCurrentOutputDirectory(); + f2 += "/Info.plist"; + m_CurrentMakefile->ConfigureFile(f1.c_str(), f2.c_str(), false, false, false); productType = "com.apple.product-type.application"; + std::string path = + this->ConvertToRelativeForXCode(f2.c_str()); + buildSettings->AddAttribute("INFOPLIST_FILE", + this->CreateString(path.c_str())); + } else { @@ -1777,6 +1794,17 @@ void cmGlobalXCodeGenerator::CreateGroups(cmLocalGenerator* root, for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); l++) { cmTarget& cmtarget = l->second; + // add the soon to be generated Info.plist file as a source for a MACOSX_BUNDLE + // file + if(cmtarget.GetPropertyAsBool("MACOSX_BUNDLE")) + { + cmSourceFile file; + file.SetName("Info.plist", m_CurrentMakefile->GetCurrentOutputDirectory(), + m_CurrentMakefile->GetSourceExtensions(), + m_CurrentMakefile->GetHeaderExtensions()); + cmtarget.GetSourceFiles().push_back(m_CurrentMakefile->AddSource(file)); + } + std::vector & classes = cmtarget.GetSourceFiles(); for(std::vector::const_iterator s = classes.begin(); s != classes.end(); s++) diff --git a/Source/cmLocalUnixMakefileGenerator3.cxx b/Source/cmLocalUnixMakefileGenerator3.cxx index 7eb32d2b7..b8d080a68 100644 --- a/Source/cmLocalUnixMakefileGenerator3.cxx +++ b/Source/cmLocalUnixMakefileGenerator3.cxx @@ -1373,6 +1373,27 @@ cmLocalUnixMakefileGenerator3 // Make bundle directories outpath += target.GetName(); outpath += ".app/Contents/MacOS/"; + std::string f1 = m_Makefile->GetModulesFile("MacOSXBundleInfo.plist.in"); + if ( f1.size() == 0 ) + { + cmSystemTools::Error("could not find Mac OSX bundle template file."); + } + std::string macdir = m_Makefile->GetSafeDefinition("EXECUTABLE_OUTPUT_PATH"); + if ( macdir.size() == 0 ) + { + macdir = m_Makefile->GetCurrentOutputDirectory(); + } + if(macdir.size() && macdir[macdir.size()-1] != '/') + { + macdir += "/"; + } + macdir += target.GetName(); + macdir += ".app/Contents/"; + std::string f2 = macdir + "Info.plist"; + macdir += "MacOS"; + cmSystemTools::MakeDirectory(macdir.c_str()); + m_Makefile->AddDefinition("MACOSX_BUNDLE_EXECUTABLE_NAME", target.GetName()); + m_Makefile->ConfigureFile(f1.c_str(), f2.c_str(), false, false, false); } #endif std::string targetFullPath = outpath + targetName; diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 2745905e7..dc4c2ea11 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -73,6 +73,7 @@ cmMakefile::cmMakefile() "\\.(C|M|c|c\\+\\+|cc|cpp|cxx|m|mm|rc|def|r|odl|idl|hpj|bat)$"); this->AddSourceGroup("Header Files", "\\.(h|h\\+\\+|hm|hpp|hxx|in|txx|inl)$"); this->AddSourceGroup("CMake Rules", "\\.rule$"); + this->AddSourceGroup("Resources", "\\.plist$"); this->AddDefaultDefinitions(); m_cmDefineRegex.compile("#cmakedefine[ \t]+([A-Za-z_0-9]*)"); m_cmDefine01Regex.compile("#cmakedefine01[ \t]+([A-Za-z_0-9]*)");