cmCPackPackageMakerGenerator.cxx 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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. (void) files; // TODO: Fix api to not need files.
  40. (void) toplevel; // TODO: Use toplevel
  41. // Create directory structure
  42. std::string resDir = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
  43. resDir += "/Resources";
  44. std::string preflightDirName = resDir + "/PreFlight";
  45. std::string postflightDirName = resDir + "/PostFlight";
  46. if ( !cmsys::SystemTools::MakeDirectory(preflightDirName.c_str())
  47. || !cmsys::SystemTools::MakeDirectory(postflightDirName.c_str()) )
  48. {
  49. std::cerr << "Problem creating installer directories: " << preflightDirName.c_str() << " and " << postflightDirName.c_str() << std::endl;
  50. return 0;
  51. }
  52. if ( !this->CopyCreateResourceFile("License")
  53. || !this->CopyCreateResourceFile("ReadMe")
  54. || !this->CopyCreateResourceFile("Welcome")
  55. || !this->CopyResourcePlistFile("Info.plist")
  56. || !this->CopyResourcePlistFile("Description.plist") )
  57. {
  58. std::cerr << "Problem copying the resource files" << std::endl;
  59. return 0;
  60. }
  61. std::string packageDirFileName = this->GetOption("CPACK_TEMPORARY_DIRECTORY");
  62. packageDirFileName += ".pkg";
  63. std::string tmpFile = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
  64. tmpFile += "/PackageMakerOutput.log";
  65. cmOStringStream pkgCmd;
  66. /*
  67. pkgCmd << "sh -c '\"" << this->GetOption("CPACK_INSTALLER_PROGRAM")
  68. << "\" -build -p \"" << packageDirFileName << "\" -f \"" << this->GetOption("CPACK_TEMPORARY_DIRECTORY")
  69. << "\" -r \"" << this->GetOption("CPACK_TOPLEVEL_DIRECTORY") << "/Resources\" -i \""
  70. << this->GetOption("CPACK_TOPLEVEL_DIRECTORY") << "/Info.plist\" -d \""
  71. << this->GetOption("CPACK_TOPLEVEL_DIRECTORY") << "/Description.plist\"'";
  72. */
  73. pkgCmd << "/Users/kitware/Andy/CMake-CPack/foo.sh";
  74. std::cout << "Execute: " << pkgCmd.str().c_str() << std::endl;
  75. std::string output;
  76. int retVal = 1;
  77. //bool res = cmSystemTools::RunSingleCommand(pkgCmd.str().c_str(), &output, &retVal, 0, m_GeneratorVerbose, 0);
  78. bool res = true;
  79. retVal = system(pkgCmd.str().c_str());
  80. std::cout << "Done running package maker" << std::endl;
  81. if ( !res || retVal )
  82. {
  83. cmGeneratedFileStream ofs(tmpFile.c_str());
  84. ofs << "# Run command: " << pkgCmd.str().c_str() << std::endl
  85. << "# Output:" << std::endl
  86. << output.c_str() << std::endl;
  87. std::cerr << "Problem running PackageMaker command: " << pkgCmd.str().c_str() << std::endl;
  88. std::cerr << "Please check " << tmpFile.c_str() << " for errors" << std::endl;
  89. return 0;
  90. }
  91. tmpFile = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
  92. tmpFile += "/hdiutilOutput.log";
  93. cmOStringStream dmgCmd;
  94. dmgCmd << "\"" << this->GetOption("CPACK_INSTALLER_PROGRAM_DISK_IMAGE") << "\" create -ov -format UDZO -srcfolder \"" << packageDirFileName
  95. << "\" \"" << outFileName << "\"";
  96. res = cmSystemTools::RunSingleCommand(dmgCmd.str().c_str(), &output, &retVal, 0, m_GeneratorVerbose, 0);
  97. if ( !res || retVal )
  98. {
  99. cmGeneratedFileStream ofs(tmpFile.c_str());
  100. ofs << "# Run command: " << dmgCmd.str().c_str() << std::endl
  101. << "# Output:" << std::endl
  102. << output.c_str() << std::endl;
  103. std::cerr << "Problem running hdiutil command: " << dmgCmd.str().c_str() << std::endl;
  104. std::cerr << "Please check " << tmpFile.c_str() << " for errors" << std::endl;
  105. return 0;
  106. }
  107. return 1;
  108. }
  109. //----------------------------------------------------------------------
  110. int cmCPackPackageMakerGenerator::Initialize(const char* name)
  111. {
  112. std::cout << "cmCPackPackageMakerGenerator::Initialize()" << std::endl;
  113. int res = this->Superclass::Initialize(name);
  114. std::vector<std::string> path;
  115. std::string pkgPath = "/Developer/Applications/Utilities/PackageMaker.app/Contents/MacOS";
  116. path.push_back(pkgPath);
  117. pkgPath = cmSystemTools::FindProgram("PackageMaker", path, false);
  118. if ( pkgPath.empty() )
  119. {
  120. std::cerr << "Cannot find PackageMaker compiler" << std::endl;
  121. return 0;
  122. }
  123. this->SetOption("CPACK_INSTALLER_PROGRAM", pkgPath.c_str());
  124. pkgPath = cmSystemTools::FindProgram("hdiutil", path, false);
  125. if ( pkgPath.empty() )
  126. {
  127. std::cerr << "Cannot find hdiutil compiler" << std::endl;
  128. return 0;
  129. }
  130. this->SetOption("CPACK_INSTALLER_PROGRAM_DISK_IMAGE", pkgPath.c_str());
  131. return res;
  132. }
  133. //----------------------------------------------------------------------
  134. bool cmCPackPackageMakerGenerator::CopyCreateResourceFile(const char* name)
  135. {
  136. std::string uname = cmSystemTools::UpperCase(name);
  137. std::string cpackVar = "CPACK_RESOURCE_FILE_" + uname;
  138. const char* inFileName = this->GetOption(cpackVar.c_str());
  139. if ( !inFileName )
  140. {
  141. std::cerr << "CPack option: " << cpackVar.c_str() << " not specified. It should point to " << name << ".rtf, " << name << ".html, or " << name << ".txt file" << std::endl;
  142. return false;
  143. }
  144. if ( !cmSystemTools::FileExists(inFileName) )
  145. {
  146. std::cerr << "Cannot find " << name << " resource file: " << inFileName << std::endl;
  147. return false;
  148. }
  149. std::string ext = cmSystemTools::GetFilenameLastExtension(inFileName);
  150. if ( ext != ".rtfd" && ext != ".rtf" && ext != ".html" && ext != ".txt" )
  151. {
  152. std::cerr << "Bad file extension specified: " << ext << ". Currently only .rtfd, .rtf, .html, and .txt files allowed." << std::endl;
  153. return false;
  154. }
  155. std::string destFileName = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
  156. destFileName += "/Resources/";
  157. destFileName += name + ext;
  158. std::cout << "Configure file: " << inFileName << " to " << destFileName.c_str() << std::endl;
  159. this->ConfigureFile(inFileName, destFileName.c_str());
  160. return true;
  161. }
  162. bool cmCPackPackageMakerGenerator::CopyResourcePlistFile(const char* name)
  163. {
  164. std::string inFName = "CPack.";
  165. inFName += name;
  166. inFName += ".in";
  167. std::string inFileName = this->FindTemplate(inFName.c_str());
  168. if ( inFileName.empty() )
  169. {
  170. std::cerr << "Cannot find input file: " << inFName << std::endl;
  171. return false;
  172. }
  173. std::string destFileName = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
  174. destFileName += "/";
  175. destFileName += name;
  176. std::cout << "Configure file: " << inFileName.c_str() << " to " << destFileName.c_str() << std::endl;
  177. this->ConfigureFile(inFileName.c_str(), destFileName.c_str());
  178. return true;
  179. }