cmGlobalUnixMakefileGenerator.cxx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. if (!m_LanguagesEnabled)
  21. {
  22. m_LanguagesEnabled = true;
  23. // only do for global runs
  24. if (!m_CMakeInstance->GetLocal())
  25. {
  26. // see man putenv for explaination of this stupid code....
  27. static char envCXX[5000];
  28. static char envCC[5000];
  29. if(mf->GetDefinition("CMAKE_CXX_COMPILER"))
  30. {
  31. #if !defined(_WIN32) && defined(__COMO__)
  32. std::string env = "${CMAKE_CXX_COMPILER}";
  33. mf->ExpandVariablesInString(env);
  34. strncpy(envCXX, env.c_str(), 4999);
  35. envCXX[4999] = 0;
  36. setenv("CXX", envCXX, 1);
  37. #else
  38. std::string env = "CXX=${CMAKE_CXX_COMPILER}";
  39. mf->ExpandVariablesInString(env);
  40. strncpy(envCXX, env.c_str(), 4999);
  41. envCXX[4999] = 0;
  42. putenv(envCXX);
  43. #endif
  44. }
  45. if(mf->GetDefinition("CMAKE_C_COMPILER"))
  46. {
  47. #if !defined(_WIN32) && defined(__COMO__)
  48. std::string env = "${CMAKE_C_COMPILER}";
  49. mf->ExpandVariablesInString(env);
  50. strncpy(envCC, env.c_str(), 4999);
  51. envCC[4999] = 0;
  52. setenv("CC", envCC, 1);
  53. #else
  54. std::string env = "CC=${CMAKE_C_COMPILER}";
  55. mf->ExpandVariablesInString(env);
  56. strncpy(envCC, env.c_str(), 4999);
  57. envCC[4999] = 0;
  58. putenv(envCC);
  59. #endif
  60. }
  61. std::string output;
  62. std::string root
  63. = cmSystemTools::ConvertToOutputPath(mf->GetDefinition("CMAKE_ROOT"));
  64. // if no lang specified use CXX
  65. if(!lang )
  66. {
  67. lang = "CXX";
  68. }
  69. // if CXX or C, then enable C
  70. if((!this->GetLanguageEnabled(lang) && lang[0] == 'C'))
  71. {
  72. std::string cmd = root;
  73. cmd += "/Templates/cconfigure";
  74. cmSystemTools::RunCommand(cmd.c_str(), output,
  75. cmSystemTools::ConvertToOutputPath(mf->GetHomeOutputDirectory()).c_str());
  76. std::string fpath = mf->GetHomeOutputDirectory();
  77. fpath += "/CCMakeSystemConfig.cmake";
  78. mf->ReadListFile(0,fpath.c_str());
  79. this->SetLanguageEnabled("C");
  80. }
  81. // if CXX
  82. if(!this->GetLanguageEnabled(lang) || strcmp(lang, "CXX") == 0)
  83. {
  84. std::string cmd = root;
  85. cmd += "/Templates/cxxconfigure";
  86. cmSystemTools::RunCommand(cmd.c_str(), output,
  87. cmSystemTools::ConvertToOutputPath(mf->GetHomeOutputDirectory()).c_str());
  88. std::string fpath = mf->GetHomeOutputDirectory();
  89. fpath += "/CXXCMakeSystemConfig.cmake";
  90. mf->ReadListFile(0,fpath.c_str());
  91. this->SetLanguageEnabled("CXX");
  92. }
  93. }
  94. }
  95. if (!m_CMakeInstance->GetLocal())
  96. {
  97. // if we are from the top, always define this
  98. mf->AddDefinition("RUN_CONFIGURE", true);
  99. }
  100. }
  101. ///! Create a local generator appropriate to this Global Generator
  102. cmLocalGenerator *cmGlobalUnixMakefileGenerator::CreateLocalGenerator()
  103. {
  104. cmLocalGenerator *lg = new cmLocalUnixMakefileGenerator;
  105. lg->SetGlobalGenerator(this);
  106. return lg;
  107. }