cmGlobalUnixMakefileGenerator.cxx 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. std::string cmd = root;
  52. cmd += "/Templates/cconfigure";
  53. cmSystemTools::RunCommand(cmd.c_str(), output,
  54. cmSystemTools::ConvertToOutputPath(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. }
  60. // if CXX
  61. if(!this->GetLanguageEnabled("CXX") && strcmp(lang, "CXX") == 0)
  62. {
  63. // see man putenv for explaination of this stupid code....
  64. static char envCXX[5000];
  65. if(mf->GetDefinition("CMAKE_CXX_COMPILER"))
  66. {
  67. #if !defined(_WIN32) && defined(__COMO__)
  68. std::string env = "${CMAKE_CXX_COMPILER}";
  69. mf->ExpandVariablesInString(env);
  70. strncpy(envCXX, env.c_str(), 4999);
  71. envCXX[4999] = 0;
  72. setenv("CXX", envCXX, 1);
  73. #else
  74. std::string env = "CXX=${CMAKE_CXX_COMPILER}";
  75. mf->ExpandVariablesInString(env);
  76. strncpy(envCXX, env.c_str(), 4999);
  77. envCXX[4999] = 0;
  78. putenv(envCXX);
  79. #endif
  80. }
  81. std::string cmd = root;
  82. cmd += "/Templates/cxxconfigure";
  83. cmSystemTools::RunCommand(cmd.c_str(), output,
  84. cmSystemTools::ConvertToOutputPath(mf->GetHomeOutputDirectory()).c_str());
  85. std::string fpath = mf->GetHomeOutputDirectory();
  86. fpath += "/CXXCMakeSystemConfig.cmake";
  87. mf->ReadListFile(0,fpath.c_str());
  88. this->SetLanguageEnabled("CXX");
  89. // for old versions of CMake ListFiles
  90. if (!m_CMakeInstance->GetIsInTryCompile())
  91. {
  92. const char* versionValue
  93. = mf->GetDefinition("CMAKE_MINIMUM_REQUIRED_VERSION");
  94. if (!versionValue || atof(versionValue) <= 1.4)
  95. {
  96. fpath = root + "/Modules/TestForANSIStreamHeaders.cmake";
  97. mf->ReadListFile(NULL,fpath.c_str());
  98. }
  99. }
  100. }
  101. // if we are from the top, always define this
  102. mf->AddDefinition("RUN_CONFIGURE", true);
  103. }
  104. }
  105. ///! Create a local generator appropriate to this Global Generator
  106. cmLocalGenerator *cmGlobalUnixMakefileGenerator::CreateLocalGenerator()
  107. {
  108. cmLocalGenerator *lg = new cmLocalUnixMakefileGenerator;
  109. lg->SetGlobalGenerator(this);
  110. return lg;
  111. }
  112. void cmGlobalUnixMakefileGenerator::EnableLanguagesFromGenerator(
  113. cmGlobalGenerator *gen, cmMakefile *mf)
  114. {
  115. // for UNIX we just want to read in the configured files
  116. cmLocalGenerator *lg = this->CreateLocalGenerator();
  117. // set the Start directories
  118. lg->GetMakefile()->SetStartDirectory(m_CMakeInstance->GetStartDirectory());
  119. lg->GetMakefile()->SetStartOutputDirectory(m_CMakeInstance->GetStartOutputDirectory());
  120. lg->GetMakefile()->MakeStartDirectoriesCurrent();
  121. // if C, then enable C
  122. if(gen->GetLanguageEnabled("C"))
  123. {
  124. std::string fpath = mf->GetHomeOutputDirectory();
  125. fpath += "/CCMakeSystemConfig.cmake";
  126. lg->GetMakefile()->ReadListFile(0,fpath.c_str());
  127. this->SetLanguageEnabled("C");
  128. }
  129. // if CXX
  130. if(gen->GetLanguageEnabled("CXX"))
  131. {
  132. std::string fpath = mf->GetHomeOutputDirectory();
  133. fpath += "/CXXCMakeSystemConfig.cmake";
  134. lg->GetMakefile()->ReadListFile(0,fpath.c_str());
  135. this->SetLanguageEnabled("CXX");
  136. }
  137. delete lg;
  138. }