cmMSProjectGenerator.cxx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*=========================================================================
  2. Program: Insight Segmentation & Registration Toolkit
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Insight Consortium. All rights reserved.
  8. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm 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 "cmMSProjectGenerator.h"
  14. #include "cmDSWWriter.h"
  15. #include "cmDSPWriter.h"
  16. #include "cmCacheManager.h"
  17. cmMSProjectGenerator::cmMSProjectGenerator()
  18. {
  19. m_DSWWriter = 0;
  20. m_DSPWriter = 0;
  21. BuildDSWOn();
  22. }
  23. void cmMSProjectGenerator::GenerateMakefile()
  24. {
  25. this->EnableLanguage("CXX");
  26. if(m_BuildDSW)
  27. {
  28. delete m_DSWWriter;
  29. m_DSWWriter = 0;
  30. m_DSWWriter = new cmDSWWriter(m_Makefile);
  31. m_DSWWriter->OutputDSWFile();
  32. }
  33. else
  34. {
  35. delete m_DSPWriter;
  36. m_DSPWriter = 0;
  37. m_DSPWriter = new cmDSPWriter(m_Makefile);
  38. m_DSPWriter->OutputDSPFile();
  39. }
  40. }
  41. cmMSProjectGenerator::~cmMSProjectGenerator()
  42. {
  43. delete m_DSPWriter;
  44. delete m_DSWWriter;
  45. }
  46. void cmMSProjectGenerator::SetLocal(bool local)
  47. {
  48. m_BuildDSW = !local;
  49. }
  50. void cmMSProjectGenerator::EnableLanguage(const char*)
  51. {
  52. // now load the settings
  53. if(!m_Makefile->GetDefinition("CMAKE_ROOT"))
  54. {
  55. cmSystemTools::Error(
  56. "CMAKE_ROOT has not been defined, bad GUI or driver program");
  57. return;
  58. }
  59. if(!this->GetLanguageEnabled("CXX"))
  60. {
  61. std::string fpath =
  62. m_Makefile->GetDefinition("CMAKE_ROOT");
  63. fpath += "/Templates/CMakeWindowsSystemConfig.cmake";
  64. m_Makefile->ReadListFile(NULL,fpath.c_str());
  65. this->SetLanguageEnabled("CXX");
  66. }
  67. }
  68. int cmMSProjectGenerator::TryCompile(const char *srcdir,
  69. const char *bindir,
  70. const char *projectName)
  71. {
  72. // now build the test
  73. std::string makeCommand = m_Makefile->GetDefinition("CMAKE_MAKE_PROGRAM");
  74. if(makeCommand.size() == 0)
  75. {
  76. cmSystemTools::Error(
  77. "Generator cannot find the appropriate make command.");
  78. return 1;
  79. }
  80. makeCommand = cmSystemTools::ConvertToOutputPath(makeCommand.c_str());
  81. std::string lowerCaseCommand = makeCommand;
  82. cmSystemTools::LowerCase(lowerCaseCommand);
  83. /**
  84. * Run an executable command and put the stdout in output.
  85. */
  86. std::string output;
  87. std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
  88. cmSystemTools::ChangeDirectory(bindir);
  89. // if there are spaces in the makeCommand, assume a full path
  90. // and convert it to a path with no spaces in it as the
  91. // RunCommand does not like spaces
  92. #if defined(_WIN32) && !defined(__CYGWIN__)
  93. if(makeCommand.find(' ') != std::string::npos)
  94. {
  95. cmSystemTools::GetShortPath(makeCommand.c_str(), makeCommand);
  96. }
  97. #endif
  98. makeCommand += " ";
  99. makeCommand += projectName;
  100. makeCommand += ".dsw /MAKE \"ALL_BUILD - Debug\" /REBUILD";
  101. if (!cmSystemTools::RunCommand(makeCommand.c_str(), output))
  102. {
  103. cmSystemTools::Error("Generator: execution of msdev failed.");
  104. // return to the original directory
  105. cmSystemTools::ChangeDirectory(cwd.c_str());
  106. return 1;
  107. }
  108. cmSystemTools::ChangeDirectory(cwd.c_str());
  109. return 0;
  110. }