cmGlobalUnixMakefileGenerator.cxx 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html 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. bool isLocal = m_CMakeInstance->GetLocal();
  21. // if no lang specified use CXX
  22. if(!lang )
  23. {
  24. lang = "CXX";
  25. }
  26. std::string root
  27. = cmSystemTools::ConvertToOutputPath(mf->GetDefinition("CMAKE_ROOT"));
  28. std::string rootBin = mf->GetHomeOutputDirectory();
  29. if(m_ConfiguredFilesPath.size())
  30. {
  31. rootBin = m_ConfiguredFilesPath;
  32. }
  33. bool needCBackwards = false;
  34. bool needCXXBackwards = false;
  35. // check for a C compiler and configure it
  36. if(!isLocal &&
  37. !this->GetLanguageEnabled("C") &&
  38. lang[0] == 'C')
  39. {
  40. if (m_CMakeInstance->GetIsInTryCompile())
  41. {
  42. cmSystemTools::Error("This should not have happen. "
  43. "If you see this message, you are probably using a "
  44. "broken CMakeLists.txt file or a problematic release of "
  45. "CMake");
  46. }
  47. needCBackwards = true;
  48. // Read the DetermineSystem file
  49. std::string systemFile = root;
  50. systemFile += "/Modules/CMakeDetermineSystem.cmake";
  51. mf->ReadListFile(0, systemFile.c_str());
  52. // read determine C compiler
  53. std::string determineCFile = root;
  54. determineCFile += "/Modules/CMakeDetermineCCompiler.cmake";
  55. mf->ReadListFile(0,determineCFile.c_str());
  56. this->SetLanguageEnabled("C");
  57. }
  58. // check for a CXX compiler and configure it
  59. if(!isLocal &&
  60. !this->GetLanguageEnabled("CXX") &&
  61. strcmp(lang, "CXX") == 0)
  62. {
  63. needCXXBackwards = true;
  64. std::string determineCFile = root;
  65. determineCFile += "/Modules/CMakeDetermineCXXCompiler.cmake";
  66. mf->ReadListFile(0,determineCFile.c_str());
  67. this->SetLanguageEnabled("CXX");
  68. }
  69. std::string fpath = rootBin;
  70. if(!mf->GetDefinition("CMAKE_SYSTEM_LOADED"))
  71. {
  72. fpath += "/CMakeSystem.cmake";
  73. mf->ReadListFile(0,fpath.c_str());
  74. }
  75. // if C, then enable C
  76. if(lang[0] == 'C' && !mf->GetDefinition("CMAKE_C_COMPILER_LOADED"))
  77. {
  78. fpath = rootBin;
  79. fpath += "/CMakeCCompiler.cmake";
  80. mf->ReadListFile(0,fpath.c_str());
  81. }
  82. if(strcmp(lang, "CXX") == 0 && !mf->GetDefinition("CMAKE_CXX_COMPILER_LOADED"))
  83. {
  84. fpath = rootBin;
  85. fpath += "/CMakeCXXCompiler.cmake";
  86. mf->ReadListFile(0,fpath.c_str());
  87. }
  88. if(!mf->GetDefinition("CMAKE_SYSTEM_SPECIFIC_INFORMATION_LOADED"))
  89. {
  90. fpath = root;
  91. fpath += "/Modules/CMakeSystemSpecificInformation.cmake";
  92. mf->ReadListFile(0,fpath.c_str());
  93. }
  94. if(!isLocal)
  95. {
  96. // At this point we should have enough info for a try compile
  97. // which is used in the backward stuff
  98. if(needCBackwards)
  99. {
  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. std::string ifpath = root + "/Modules/CMakeBackwardCompatibilityC.cmake";
  108. mf->ReadListFile(0,ifpath.c_str());
  109. }
  110. }
  111. }
  112. if(needCXXBackwards)
  113. {
  114. if (!m_CMakeInstance->GetIsInTryCompile())
  115. {
  116. // for old versions of CMake ListFiles
  117. const char* versionValue
  118. = mf->GetDefinition("CMAKE_MINIMUM_REQUIRED_VERSION");
  119. if (!versionValue || atof(versionValue) <= 1.4)
  120. {
  121. std::string fpath = root + "/Modules/CMakeBackwardCompatibilityCXX.cmake";
  122. mf->ReadListFile(0,fpath.c_str());
  123. }
  124. }
  125. }
  126. // if we are from the top, always define this
  127. mf->AddDefinition("RUN_CONFIGURE", true);
  128. }
  129. }
  130. ///! Create a local generator appropriate to this Global Generator
  131. cmLocalGenerator *cmGlobalUnixMakefileGenerator::CreateLocalGenerator()
  132. {
  133. cmLocalGenerator *lg = new cmLocalUnixMakefileGenerator;
  134. lg->SetGlobalGenerator(this);
  135. return lg;
  136. }
  137. void cmGlobalUnixMakefileGenerator::EnableLanguagesFromGenerator(cmGlobalGenerator *gen)
  138. {
  139. this->SetConfiguredFilesPath(gen->GetCMakeInstance()->GetHomeOutputDirectory());
  140. // if C, then enable C
  141. if(gen->GetLanguageEnabled("C"))
  142. {
  143. this->SetLanguageEnabled("C");
  144. }
  145. // if CXX
  146. if(gen->GetLanguageEnabled("CXX"))
  147. {
  148. this->SetLanguageEnabled("CXX");
  149. }
  150. }