1
0

cmGlobalGenerator.cxx 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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 "cmGlobalGenerator.h"
  14. #include "cmLocalGenerator.h"
  15. #include "cmake.h"
  16. #include "cmMakefile.h"
  17. cmGlobalGenerator::cmGlobalGenerator()
  18. {
  19. m_LanguagesEnabled = false;
  20. }
  21. cmGlobalGenerator::~cmGlobalGenerator()
  22. {
  23. // Delete any existing cmLocalGenerators
  24. int i;
  25. for (i = 0; i < m_LocalGenerators.size(); ++i)
  26. {
  27. delete m_LocalGenerators[i];
  28. }
  29. m_LocalGenerators.clear();
  30. }
  31. void cmGlobalGenerator::SetLanguageEnabled(const char* l)
  32. {
  33. m_LanguageEnabled[l] = true;
  34. }
  35. bool cmGlobalGenerator::GetLanguageEnabled(const char* l)
  36. {
  37. return (m_LanguageEnabled.count(l) > 0);
  38. }
  39. void cmGlobalGenerator::ClearEnabledLanguages()
  40. {
  41. m_LanguageEnabled.clear();
  42. }
  43. void cmGlobalGenerator::Configure()
  44. {
  45. // reset theLanguages
  46. m_LanguagesEnabled = false;
  47. // Delete any existing cmLocalGenerators
  48. int i;
  49. for (i = 0; i < m_LocalGenerators.size(); ++i)
  50. {
  51. delete m_LocalGenerators[i];
  52. }
  53. m_LocalGenerators.clear();
  54. // start with this directory
  55. cmLocalGenerator *lg = this->CreateLocalGenerator();
  56. m_LocalGenerators.push_back(lg);
  57. // set the Start directories
  58. lg->GetMakefile()->SetStartDirectory(m_CMakeInstance->GetStartDirectory());
  59. lg->GetMakefile()->SetStartOutputDirectory(m_CMakeInstance->GetStartOutputDirectory());
  60. lg->GetMakefile()->MakeStartDirectoriesCurrent();
  61. // now do it
  62. this->RecursiveConfigure(lg);
  63. }
  64. // loop through the directories creating cmLocalGenerators and Configure()
  65. void cmGlobalGenerator::RecursiveConfigure(cmLocalGenerator *lg)
  66. {
  67. // configure the current directory
  68. lg->Configure();
  69. // get all the subdirectories
  70. std::vector<std::string> subdirs = lg->GetMakefile()->GetSubDirectories();
  71. // for each subdir recurse
  72. int i;
  73. for (i = 0; i < subdirs.size(); ++i)
  74. {
  75. cmLocalGenerator *lg2 = this->CreateLocalGenerator();
  76. m_LocalGenerators.push_back(lg2);
  77. // add the subdir to the start output directory
  78. std::string outdir = lg->GetMakefile()->GetStartOutputDirectory();
  79. outdir += "/";
  80. outdir += subdirs[i];
  81. lg2->GetMakefile()->SetStartOutputDirectory(outdir.c_str());
  82. // add the subdir to the start source directory
  83. std::string currentDir = lg->GetMakefile()->GetStartDirectory();
  84. currentDir += "/";
  85. currentDir += subdirs[i];
  86. lg2->GetMakefile()->SetStartDirectory(currentDir.c_str());
  87. lg2->GetMakefile()->MakeStartDirectoriesCurrent();
  88. this->RecursiveConfigure(lg2);
  89. }
  90. }
  91. void cmGlobalGenerator::Generate()
  92. {
  93. // For each existing cmLocalGenerator
  94. int i;
  95. for (i = 0; i < m_LocalGenerators.size(); ++i)
  96. {
  97. m_LocalGenerators[i]->Generate(true);
  98. }
  99. }
  100. void cmGlobalGenerator::LocalGenerate()
  101. {
  102. // for this case we create one LocalGenerator
  103. // configure it, and then Generate it
  104. // start with this directory
  105. cmLocalGenerator *lg = this->CreateLocalGenerator();
  106. // set the Start directories
  107. lg->GetMakefile()->SetStartDirectory(m_CMakeInstance->GetStartDirectory());
  108. lg->GetMakefile()->SetStartOutputDirectory(m_CMakeInstance->GetStartOutputDirectory());
  109. lg->GetMakefile()->MakeStartDirectoriesCurrent();
  110. // now do trhe configure
  111. lg->Configure();
  112. lg->Generate(false);
  113. delete lg;
  114. }
  115. int cmGlobalGenerator::TryCompile(const char *, const char *bindir,
  116. const char *)
  117. {
  118. // now build the test
  119. std::string makeCommand =
  120. m_CMakeInstance->GetCacheManager()->GetCacheValue("CMAKE_MAKE_PROGRAM");
  121. if(makeCommand.size() == 0)
  122. {
  123. cmSystemTools::Error(
  124. "Generator cannot find the appropriate make command.");
  125. return 1;
  126. }
  127. makeCommand = cmSystemTools::ConvertToOutputPath(makeCommand.c_str());
  128. /**
  129. * Run an executable command and put the stdout in output.
  130. */
  131. std::string output;
  132. std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
  133. cmSystemTools::ChangeDirectory(bindir);
  134. // now build
  135. makeCommand += " all";
  136. if (!cmSystemTools::RunCommand(makeCommand.c_str(), output))
  137. {
  138. cmSystemTools::Error("Generator: execution of make failed.");
  139. // return to the original directory
  140. cmSystemTools::ChangeDirectory(cwd.c_str());
  141. return 1;
  142. }
  143. cmSystemTools::ChangeDirectory(cwd.c_str());
  144. return 0;
  145. }
  146. cmLocalGenerator *cmGlobalGenerator::CreateLocalGenerator()
  147. {
  148. cmLocalGenerator *lg = new cmLocalGenerator;
  149. lg->SetGlobalGenerator(this);
  150. return lg;
  151. }