cmGlobalUnixMakefileGenerator.cxx 6.2 KB

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