cmGlobalUnixMakefileGenerator.cxx 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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 "cmGlobalUnixMakefileGenerator.h"
  14. #include "cmLocalUnixMakefileGenerator.h"
  15. #include "cmMakefile.h"
  16. #include "cmake.h"
  17. void cmGlobalUnixMakefileGenerator::EnableLanguage(const char* lang,
  18. cmMakefile *mf)
  19. {
  20. // only do for global runs
  21. if (!m_CMakeInstance->GetLocal())
  22. {
  23. std::string output;
  24. std::string root
  25. = cmSystemTools::ConvertToOutputPath(mf->GetDefinition("CMAKE_ROOT"));
  26. // if no lang specified use CXX
  27. if(!lang )
  28. {
  29. lang = "CXX";
  30. }
  31. // if CXX or C, then enable C
  32. if((!this->GetLanguageEnabled("C") && lang[0] == 'C'))
  33. {
  34. static char envCC[5000];
  35. if(mf->GetDefinition("CMAKE_C_COMPILER"))
  36. {
  37. std::string env = "CC=${CMAKE_C_COMPILER}";
  38. mf->ExpandVariablesInString(env);
  39. strncpy(envCC, env.c_str(), 4999);
  40. envCC[4999] = 0;
  41. putenv(envCC);
  42. }
  43. if (m_CMakeInstance->GetIsInTryCompile())
  44. {
  45. cmSystemTools::Error("This should not have happen. "
  46. "If you see this message, you are probably using a "
  47. "broken CMakeLists.txt file or a problematic release of "
  48. "CMake");
  49. }
  50. std::string cmd = root;
  51. cmd += "/Templates/cconfigure";
  52. cmSystemTools::RunCommand(cmd.c_str(), output,
  53. cmSystemTools::ConvertToOutputPath(
  54. mf->GetHomeOutputDirectory()).c_str());
  55. std::string fpath = mf->GetHomeOutputDirectory();
  56. fpath += "/CCMakeSystemConfig.cmake";
  57. mf->ReadListFile(0,fpath.c_str());
  58. this->SetLanguageEnabled("C");
  59. if (!m_CMakeInstance->GetIsInTryCompile())
  60. {
  61. // for old versions of CMake ListFiles
  62. const char* versionValue
  63. = mf->GetDefinition("CMAKE_MINIMUM_REQUIRED_VERSION");
  64. if (!versionValue || atof(versionValue) <= 1.4)
  65. {
  66. std::string ifpath = root + "/Modules/CMakeBackwardCompatibilityC.cmake";
  67. mf->ReadListFile(0,ifpath.c_str());
  68. }
  69. }
  70. }
  71. // if CXX
  72. if(!this->GetLanguageEnabled("CXX") && strcmp(lang, "CXX") == 0)
  73. {
  74. // see man putenv for explaination of this stupid code....
  75. static char envCXX[5000];
  76. if(mf->GetDefinition("CMAKE_CXX_COMPILER"))
  77. {
  78. std::string env = "CXX=${CMAKE_CXX_COMPILER}";
  79. mf->ExpandVariablesInString(env);
  80. strncpy(envCXX, env.c_str(), 4999);
  81. envCXX[4999] = 0;
  82. putenv(envCXX);
  83. }
  84. std::string cmd = root;
  85. if (m_CMakeInstance->GetIsInTryCompile())
  86. {
  87. cmSystemTools::Error("This should not have happen. "
  88. "If you see this message, you are probably using a "
  89. "broken CMakeLists.txt file or a problematic release of "
  90. "CMake");
  91. }
  92. cmd += "/Templates/cxxconfigure";
  93. cmSystemTools::RunCommand(cmd.c_str(), output,
  94. cmSystemTools::ConvertToOutputPath(
  95. mf->GetHomeOutputDirectory()).c_str());
  96. std::string fpath = mf->GetHomeOutputDirectory();
  97. fpath += "/CXXCMakeSystemConfig.cmake";
  98. mf->ReadListFile(0,fpath.c_str());
  99. this->SetLanguageEnabled("CXX");
  100. if (!m_CMakeInstance->GetIsInTryCompile())
  101. {
  102. // for old versions of CMake ListFiles
  103. const char* versionValue
  104. = mf->GetDefinition("CMAKE_MINIMUM_REQUIRED_VERSION");
  105. if (!versionValue || atof(versionValue) <= 1.4)
  106. {
  107. fpath = root + "/Modules/CMakeBackwardCompatibilityCXX.cmake";
  108. mf->ReadListFile(0,fpath.c_str());
  109. }
  110. }
  111. }
  112. // if we are from the top, always define this
  113. mf->AddDefinition("RUN_CONFIGURE", true);
  114. }
  115. }
  116. ///! Create a local generator appropriate to this Global Generator
  117. cmLocalGenerator *cmGlobalUnixMakefileGenerator::CreateLocalGenerator()
  118. {
  119. cmLocalGenerator *lg = new cmLocalUnixMakefileGenerator;
  120. lg->SetGlobalGenerator(this);
  121. return lg;
  122. }
  123. void cmGlobalUnixMakefileGenerator::EnableLanguagesFromGenerator(
  124. cmGlobalGenerator *gen, cmMakefile *mf)
  125. {
  126. // for UNIX we just want to read in the configured files
  127. cmLocalGenerator *lg = this->CreateLocalGenerator();
  128. // set the Start directories
  129. lg->GetMakefile()->SetStartDirectory(m_CMakeInstance->GetStartDirectory());
  130. lg->GetMakefile()->SetStartOutputDirectory(m_CMakeInstance->GetStartOutputDirectory());
  131. lg->GetMakefile()->MakeStartDirectoriesCurrent();
  132. // if C, then enable C
  133. if(gen->GetLanguageEnabled("C"))
  134. {
  135. std::string fpath = mf->GetHomeOutputDirectory();
  136. fpath += "/CCMakeSystemConfig.cmake";
  137. lg->GetMakefile()->ReadListFile(0,fpath.c_str());
  138. this->SetLanguageEnabled("C");
  139. }
  140. // if CXX
  141. if(gen->GetLanguageEnabled("CXX"))
  142. {
  143. std::string fpath = mf->GetHomeOutputDirectory();
  144. fpath += "/CXXCMakeSystemConfig.cmake";
  145. lg->GetMakefile()->ReadListFile(0,fpath.c_str());
  146. this->SetLanguageEnabled("CXX");
  147. }
  148. delete lg;
  149. }