cmCPackPackageMakerGenerator.cxx 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #include "cmCPackPackageMakerGenerator.h"
  14. #include "cmake.h"
  15. #include "cmGlobalGenerator.h"
  16. #include "cmLocalGenerator.h"
  17. #include "cmSystemTools.h"
  18. #include "cmMakefile.h"
  19. #include "cmGeneratedFileStream.h"
  20. #include <cmsys/SystemTools.hxx>
  21. #include <cmsys/Glob.hxx>
  22. //----------------------------------------------------------------------
  23. cmCPackPackageMakerGenerator::cmCPackPackageMakerGenerator()
  24. {
  25. }
  26. //----------------------------------------------------------------------
  27. cmCPackPackageMakerGenerator::~cmCPackPackageMakerGenerator()
  28. {
  29. }
  30. //----------------------------------------------------------------------
  31. int cmCPackPackageMakerGenerator::ProcessGenerator()
  32. {
  33. return this->Superclass::ProcessGenerator();
  34. }
  35. //----------------------------------------------------------------------
  36. int cmCPackPackageMakerGenerator::CompressFiles(const char* outFileName, const char* toplevel,
  37. const std::vector<std::string>& files)
  38. {
  39. // Create directory structure
  40. std::string resDir = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
  41. resDir += "/Resources";
  42. std::string preflightDirName = resDir + "/PreFlight";
  43. std::string postflightDirName = resDir + "/PostFlight";
  44. if ( !cmsys::SystemTools::MakeDirectory(preflightDirName.c_str())
  45. || !cmsys::SystemTools::MakeDirectory(postflightDirName.c_str()) )
  46. {
  47. std::cerr << "Problem creating installer directories: " << preflightDirName.c_str() << " and " << postflightDirName.c_str() << std::endl;
  48. return 0;
  49. }
  50. if ( !this->CopyCreateResourceFile("License")
  51. || !this->CopyCreateResourceFile("ReadMe")
  52. || !this->CopyCreateResourceFile("Welcome")
  53. || !this->CopyResourcePlistFile("Info.plist")
  54. || !this->CopyResourcePlistFile("Description.plist") )
  55. {
  56. std::cerr << "Problem copying the resource files" << std::endl;
  57. return 0;
  58. }
  59. std::string packageDirFileName = this->GetOption("CPACK_TEMPORARY_DIRECTORY");
  60. packageDirFileName += ".pkg";
  61. std::string tmpFile = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
  62. tmpFile += "/PackageMakerOutput.log";
  63. cmOStringStream pkgCmd;
  64. /*
  65. pkgCmd << "sh -c '\"" << this->GetOption("CPACK_INSTALLER_PROGRAM")
  66. << "\" -build -p \"" << packageDirFileName << "\" -f \"" << this->GetOption("CPACK_TEMPORARY_DIRECTORY")
  67. << "\" -r \"" << this->GetOption("CPACK_TOPLEVEL_DIRECTORY") << "/Resources\" -i \""
  68. << this->GetOption("CPACK_TOPLEVEL_DIRECTORY") << "/Info.plist\" -d \""
  69. << this->GetOption("CPACK_TOPLEVEL_DIRECTORY") << "/Description.plist\"'";
  70. */
  71. pkgCmd << "/Users/kitware/Andy/CMake-CPack/foo.sh";
  72. std::cout << "Execute: " << pkgCmd.str().c_str() << std::endl;
  73. std::string output;
  74. int retVal = 1;
  75. //bool res = cmSystemTools::RunSingleCommand(pkgCmd.str().c_str(), &output, &retVal, 0, m_GeneratorVerbose, 0);
  76. bool res = true;
  77. retVal = system(pkgCmd.str().c_str());
  78. std::cout << "Done running package maker" << std::endl;
  79. if ( !res || retVal )
  80. {
  81. cmGeneratedFileStream ofs(tmpFile.c_str());
  82. ofs << "# Run command: " << pkgCmd.str().c_str() << std::endl
  83. << "# Output:" << std::endl
  84. << output.c_str() << std::endl;
  85. std::cerr << "Problem running PackageMaker command: " << pkgCmd.str().c_str() << std::endl;
  86. std::cerr << "Please check " << tmpFile.c_str() << " for errors" << std::endl;
  87. return 0;
  88. }
  89. tmpFile = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
  90. tmpFile += "/hdiutilOutput.log";
  91. cmOStringStream dmgCmd;
  92. dmgCmd << "\"" << this->GetOption("CPACK_INSTALLER_PROGRAM_DISK_IMAGE") << "\" create -ov -format UDZO -srcfolder \"" << packageDirFileName
  93. << "\" \"" << outFileName << "\"";
  94. res = cmSystemTools::RunSingleCommand(dmgCmd.str().c_str(), &output, &retVal, 0, m_GeneratorVerbose, 0);
  95. if ( !res || retVal )
  96. {
  97. cmGeneratedFileStream ofs(tmpFile.c_str());
  98. ofs << "# Run command: " << dmgCmd.str().c_str() << std::endl
  99. << "# Output:" << std::endl
  100. << output.c_str() << std::endl;
  101. std::cerr << "Problem running hdiutil command: " << dmgCmd.str().c_str() << std::endl;
  102. std::cerr << "Please check " << tmpFile.c_str() << " for errors" << std::endl;
  103. return 0;
  104. }
  105. return 1;
  106. }
  107. //----------------------------------------------------------------------
  108. int cmCPackPackageMakerGenerator::Initialize(const char* name)
  109. {
  110. std::cout << "cmCPackPackageMakerGenerator::Initialize()" << std::endl;
  111. int res = this->Superclass::Initialize(name);
  112. std::vector<std::string> path;
  113. std::string pkgPath = "/Developer/Applications/Utilities/PackageMaker.app/Contents/MacOS";
  114. path.push_back(pkgPath);
  115. pkgPath = cmSystemTools::FindProgram("PackageMaker", path, false);
  116. if ( pkgPath.empty() )
  117. {
  118. std::cerr << "Cannot find PackageMaker compiler" << std::endl;
  119. return 0;
  120. }
  121. this->SetOption("CPACK_INSTALLER_PROGRAM", pkgPath.c_str());
  122. pkgPath = cmSystemTools::FindProgram("hdiutil", path, false);
  123. if ( pkgPath.empty() )
  124. {
  125. std::cerr << "Cannot find hdiutil compiler" << std::endl;
  126. return 0;
  127. }
  128. this->SetOption("CPACK_INSTALLER_PROGRAM_DISK_IMAGE", pkgPath.c_str());
  129. return res;
  130. }
  131. //----------------------------------------------------------------------
  132. bool cmCPackPackageMakerGenerator::CopyCreateResourceFile(const char* name)
  133. {
  134. std::string uname = cmSystemTools::UpperCase(name);
  135. std::string cpackVar = "CPACK_RESOURCE_FILE_" + uname;
  136. const char* inFileName = this->GetOption(cpackVar.c_str());
  137. if ( !inFileName )
  138. {
  139. std::cerr << "CPack option: " << cpackVar.c_str() << " not specified. It should point to " << name << ".rtf, " << name << ".html, or " << name << ".txt file" << std::endl;
  140. return false;
  141. }
  142. if ( !cmSystemTools::FileExists(inFileName) )
  143. {
  144. std::cerr << "Cannot find " << name << " resource file: " << inFileName << std::endl;
  145. return false;
  146. }
  147. std::string ext = cmSystemTools::GetFilenameLastExtension(inFileName);
  148. if ( ext != ".rtfd" && ext != ".rtf" && ext != ".html" && ext != ".txt" )
  149. {
  150. std::cerr << "Bad file extension specified: " << ext << ". Currently only .rtfd, .rtf, .html, and .txt files allowed." << std::endl;
  151. return false;
  152. }
  153. std::string destFileName = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
  154. destFileName += "/Resources/";
  155. destFileName += name + ext;
  156. std::cout << "Configure file: " << inFileName << " to " << destFileName.c_str() << std::endl;
  157. this->ConfigureFile(inFileName, destFileName.c_str());
  158. return true;
  159. }
  160. bool cmCPackPackageMakerGenerator::CopyResourcePlistFile(const char* name)
  161. {
  162. std::string inFName = "CPack.";
  163. inFName += name;
  164. inFName += ".in";
  165. std::string inFileName = this->FindTemplate(inFName.c_str());
  166. if ( inFileName.empty() )
  167. {
  168. std::cerr << "Cannot find input file: " << inFName << std::endl;
  169. return false;
  170. }
  171. std::string destFileName = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
  172. destFileName += "/";
  173. destFileName += name;
  174. std::cout << "Configure file: " << inFileName.c_str() << " to " << destFileName.c_str() << std::endl;
  175. this->ConfigureFile(inFileName.c_str(), destFileName.c_str());
  176. return true;
  177. }