cmCPackNSISGenerator.cxx 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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 "cmCPackNSISGenerator.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. cmCPackNSISGenerator::cmCPackNSISGenerator()
  24. {
  25. }
  26. //----------------------------------------------------------------------
  27. cmCPackNSISGenerator::~cmCPackNSISGenerator()
  28. {
  29. }
  30. //----------------------------------------------------------------------
  31. int cmCPackNSISGenerator::ProcessGenerator()
  32. {
  33. return this->Superclass::ProcessGenerator();
  34. }
  35. //----------------------------------------------------------------------
  36. int cmCPackNSISGenerator::CompressFiles(const char* outFileName, const char* toplevel,
  37. const std::vector<std::string>& files)
  38. {
  39. (void)outFileName; // TODO: Fix nsis to force out file name
  40. (void)toplevel;
  41. (void)files;
  42. std::string nsisInFileName = this->FindTemplate("NSIS.template.in");
  43. if ( nsisInFileName.size() == 0 )
  44. {
  45. std::cerr << "CPack error: Could not find NSIS installer template file." << std::endl;
  46. return false;
  47. }
  48. std::string nsisFileName = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
  49. std::string tmpFile = nsisFileName;
  50. tmpFile += "/NSISOutput.log";
  51. nsisFileName += "/project.nsi";
  52. std::cout << "Configure file: " << nsisInFileName << " to " << nsisFileName << std::endl;
  53. this->ConfigureFile(nsisInFileName.c_str(), nsisFileName.c_str());
  54. std::string nsisCmd = "\"";
  55. nsisCmd += this->GetOption("CPACK_INSTALLER_PROGRAM");
  56. nsisCmd += "\" \"" + nsisFileName + "\"";
  57. std::cout << "Execute: " << nsisCmd.c_str() << std::endl;
  58. std::string output;
  59. int retVal = 1;
  60. bool res = cmSystemTools::RunSingleCommand(nsisCmd.c_str(), &output, &retVal, 0, m_GeneratorVerbose, 0);
  61. if ( !res || retVal )
  62. {
  63. cmGeneratedFileStream ofs(tmpFile.c_str());
  64. ofs << "# Run command: " << nsisCmd.c_str() << std::endl
  65. << "# Output:" << std::endl
  66. << output.c_str() << std::endl;
  67. std::cerr << "Problem running NSIS command: " << nsisCmd.c_str() << std::endl;
  68. std::cerr << "Please check " << tmpFile.c_str() << " for errors" << std::endl;
  69. return 0;
  70. }
  71. return 1;
  72. }
  73. //----------------------------------------------------------------------
  74. int cmCPackNSISGenerator::Initialize(const char* name)
  75. {
  76. std::cout << "cmCPackNSISGenerator::Initialize()" << std::endl;
  77. int res = this->Superclass::Initialize(name);
  78. std::vector<std::string> path;
  79. std::string nsisPath;
  80. if ( !cmsys::SystemTools::ReadRegistryValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\NSIS",
  81. nsisPath) )
  82. {
  83. std::cerr << "Cannot find NSIS registry value" << std::endl;
  84. return 0;
  85. }
  86. path.push_back(nsisPath);
  87. nsisPath = cmSystemTools::FindProgram("makensis", path, false);
  88. if ( nsisPath.empty() )
  89. {
  90. std::cerr << "Cannot find NSIS compiler" << std::endl;
  91. return 0;
  92. }
  93. this->SetOption("CPACK_INSTALLER_PROGRAM", nsisPath.c_str());
  94. return res;
  95. }