cmLocalGenerator.cxx 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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 "cmLocalGenerator.h"
  14. #include "cmGlobalGenerator.h"
  15. #include "cmake.h"
  16. #include "cmMakefile.h"
  17. cmLocalGenerator::cmLocalGenerator()
  18. {
  19. m_Makefile = new cmMakefile;
  20. m_Makefile->SetLocalGenerator(this);
  21. }
  22. cmLocalGenerator::~cmLocalGenerator()
  23. {
  24. delete m_Makefile;
  25. }
  26. void cmLocalGenerator::Configure()
  27. {
  28. // set the PROJECT_SOURCE_DIR and PROJECT_BIN_DIR to default values
  29. // just in case the project does not include a PROJECT command
  30. m_Makefile->AddDefinition("PROJECT_BINARY_DIR",
  31. m_Makefile->GetHomeOutputDirectory());
  32. m_Makefile->AddDefinition("PROJECT_SOURCE_DIR",
  33. m_Makefile->GetHomeDirectory());
  34. // find & read the list file
  35. std::string currentStart = m_Makefile->GetStartDirectory();
  36. currentStart += "/CMakeLists.txt";
  37. m_Makefile->ReadListFile(currentStart.c_str());
  38. }
  39. void cmLocalGenerator::SetGlobalGenerator(cmGlobalGenerator *gg)
  40. {
  41. m_GlobalGenerator = gg;
  42. // setup the home directories
  43. m_Makefile->SetHomeDirectory(
  44. gg->GetCMakeInstance()->GetHomeDirectory());
  45. m_Makefile->SetHomeOutputDirectory(
  46. gg->GetCMakeInstance()->GetHomeOutputDirectory());
  47. }
  48. void cmLocalGenerator::ConfigureFinalPass()
  49. {
  50. m_Makefile->ConfigureFinalPass();
  51. }
  52. std::string cmLocalGenerator::ConvertToRelativeOutputPath(const char* p)
  53. {
  54. // The first time this is called, initialize all
  55. // the path ivars that are used. This can not
  56. // be moved to the constructor because all the paths are not set yet.
  57. if(m_CurrentOutputDirectory.size() == 0)
  58. {
  59. m_CurrentOutputDirectory = m_Makefile->GetCurrentOutputDirectory();
  60. m_HomeOutputDirectory = m_Makefile->GetHomeOutputDirectory();
  61. m_HomeDirectory = m_Makefile->GetHomeDirectory();
  62. #if defined(_WIN32) || defined(__APPLE__)
  63. m_CurrentOutputDirectory = cmSystemTools::LowerCase(m_CurrentOutputDirectory);
  64. m_HomeOutputDirectory = cmSystemTools::LowerCase(m_HomeOutputDirectory);
  65. m_HomeDirectory = cmSystemTools::LowerCase(m_HomeDirectory);
  66. #endif
  67. if(m_RelativePathToSourceDir.size() == 0)
  68. {
  69. m_RelativePathToSourceDir = cmSystemTools::RelativePath(
  70. m_CurrentOutputDirectory.c_str(),
  71. m_HomeDirectory.c_str());
  72. std::string path = m_CurrentOutputDirectory;
  73. cmSystemTools::ReplaceString(path, m_HomeOutputDirectory.c_str(), "");
  74. unsigned i;
  75. m_RelativePathToBinaryDir = "";
  76. for(i =0; i < path.size(); ++i)
  77. {
  78. if(path[i] == '/')
  79. {
  80. m_RelativePathToBinaryDir += "../";
  81. }
  82. }
  83. }
  84. m_HomeOutputDirectoryNoSlash = m_HomeOutputDirectory;
  85. m_HomeOutputDirectory += "/";
  86. m_CurrentOutputDirectory += "/";
  87. }
  88. // Do the work of converting to a relative path
  89. std::string pathIn = p;
  90. #if defined(_WIN32) || defined(__APPLE__)
  91. pathIn = cmSystemTools::LowerCase(pathIn);
  92. #endif
  93. std::string ret = pathIn;
  94. cmSystemTools::ReplaceString(ret, m_CurrentOutputDirectory.c_str(), "");
  95. cmSystemTools::ReplaceString(ret, m_HomeDirectory.c_str(),
  96. m_RelativePathToSourceDir.c_str());
  97. cmSystemTools::ReplaceString(ret, m_HomeOutputDirectory.c_str(),
  98. m_RelativePathToBinaryDir.c_str());
  99. std::string relpath = m_RelativePathToBinaryDir;
  100. if(relpath.size())
  101. {
  102. relpath.erase(relpath.size()-1, 1);
  103. }
  104. else
  105. {
  106. relpath = ".";
  107. }
  108. cmSystemTools::ReplaceString(ret, m_HomeOutputDirectoryNoSlash.c_str(),
  109. relpath.c_str());
  110. ret = cmSystemTools::ConvertToOutputPath(ret.c_str());
  111. return ret;
  112. }