cmGlobalUnixMakefileGenerator.cxx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. std::string env = "CXX=${CMAKE_CXX_COMPILER}";
  32. mf->ExpandVariablesInString(env);
  33. strncpy(envCXX, env.c_str(), 4999);
  34. envCXX[4999] = 0;
  35. putenv(envCXX);
  36. }
  37. if(mf->GetDefinition("CMAKE_C_COMPILER"))
  38. {
  39. std::string env = "CC=${CMAKE_C_COMPILER}";
  40. mf->ExpandVariablesInString(env);
  41. strncpy(envCC, env.c_str(), 4999);
  42. envCC[4999] = 0;
  43. putenv(envCC);
  44. }
  45. std::string output;
  46. std::string root
  47. = cmSystemTools::ConvertToOutputPath(mf->GetDefinition("CMAKE_ROOT"));
  48. // if no lang specified use CXX
  49. if(!lang )
  50. {
  51. lang = "CXX";
  52. }
  53. // if CXX or C, then enable C
  54. if((!this->GetLanguageEnabled(lang) && lang[0] == 'C'))
  55. {
  56. std::string cmd = root;
  57. cmd += "/Templates/cconfigure";
  58. cmSystemTools::RunCommand(cmd.c_str(), output,
  59. cmSystemTools::ConvertToOutputPath(mf->GetHomeOutputDirectory()).c_str());
  60. std::string fpath = mf->GetHomeOutputDirectory();
  61. fpath += "/CCMakeSystemConfig.cmake";
  62. mf->ReadListFile(NULL,fpath.c_str());
  63. this->SetLanguageEnabled("C");
  64. }
  65. // if CXX
  66. if(!this->GetLanguageEnabled(lang) || strcmp(lang, "CXX") == 0)
  67. {
  68. std::string cmd = root;
  69. cmd += "/Templates/cxxconfigure";
  70. cmSystemTools::RunCommand(cmd.c_str(), output,
  71. cmSystemTools::ConvertToOutputPath(mf->GetHomeOutputDirectory()).c_str());
  72. std::string fpath = mf->GetHomeOutputDirectory();
  73. fpath += "/CXXCMakeSystemConfig.cmake";
  74. mf->ReadListFile(NULL,fpath.c_str());
  75. this->SetLanguageEnabled("CXX");
  76. }
  77. }
  78. }
  79. if (!m_CMakeInstance->GetLocal())
  80. {
  81. // if we are from the top, always define this
  82. mf->AddDefinition("RUN_CONFIGURE", true);
  83. }
  84. }
  85. ///! Create a local generator appropriate to this Global Generator
  86. cmLocalGenerator *cmGlobalUnixMakefileGenerator::CreateLocalGenerator()
  87. {
  88. cmLocalGenerator *lg = new cmLocalUnixMakefileGenerator;
  89. lg->SetGlobalGenerator(this);
  90. return lg;
  91. }