You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

128 lines
3.8 KiB

  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 "cmAddSubDirectoryCommand.h"
  14. // cmAddSubDirectoryCommand
  15. bool cmAddSubDirectoryCommand::InitialPass
  16. (std::vector<std::string> const& args)
  17. {
  18. if(args.size() < 1 )
  19. {
  20. this->SetError("called with incorrect number of arguments");
  21. return false;
  22. }
  23. // store the binpath
  24. std::string srcArg = args[0];
  25. std::string binArg;
  26. bool excludeFromAll = false;
  27. // process the rest of the arguments looking for optional args
  28. std::vector<std::string>::const_iterator i = args.begin();
  29. ++i;
  30. for(;i != args.end(); ++i)
  31. {
  32. if(*i == "EXCLUDE_FROM_ALL")
  33. {
  34. excludeFromAll = true;
  35. continue;
  36. }
  37. else if (!binArg.size())
  38. {
  39. binArg = *i;
  40. }
  41. else
  42. {
  43. this->SetError("called with incorrect number of arguments");
  44. return false;
  45. }
  46. }
  47. // Compute the full path to the specified source directory.
  48. // Interpret a relative path with respect to the current source directory.
  49. std::string srcPath;
  50. if(cmSystemTools::FileIsFullPath(srcArg.c_str()))
  51. {
  52. srcPath = srcArg;
  53. }
  54. else
  55. {
  56. srcPath = this->Makefile->GetCurrentDirectory();
  57. srcPath += "/";
  58. srcPath += srcArg;
  59. }
  60. if(!cmSystemTools::FileIsDirectory(srcPath.c_str()))
  61. {
  62. std::string error = "given source \"";
  63. error += srcArg;
  64. error += "\" which is not an existing directory.";
  65. this->SetError(error.c_str());
  66. return false;
  67. }
  68. srcPath = cmSystemTools::CollapseFullPath(srcPath.c_str());
  69. // Compute the full path to the binary directory.
  70. std::string binPath;
  71. if(binArg.empty())
  72. {
  73. // No binary directory was specified. If the source directory is
  74. // not a subdirectory of the current directory then it is an
  75. // error.
  76. if(!cmSystemTools::FindLastString(srcPath.c_str(),
  77. this->Makefile->GetCurrentDirectory()))
  78. {
  79. cmOStringStream e;
  80. e << "not given a binary directory but the given source directory "
  81. << "\"" << srcPath << "\" is not a subdirectory of \""
  82. << this->Makefile->GetCurrentDirectory() << "\". "
  83. << "When specifying an out-of-tree source a binary directory "
  84. << "must be explicitly specified.";
  85. this->SetError(e.str().c_str());
  86. return false;
  87. }
  88. // Remove the CurrentDirectory from the srcPath and replace it
  89. // with the CurrentOutputDirectory.
  90. binPath = srcPath;
  91. cmSystemTools::ReplaceString(binPath,
  92. this->Makefile->GetCurrentDirectory(),
  93. this->Makefile->GetCurrentOutputDirectory());
  94. }
  95. else
  96. {
  97. // Use the binary directory specified.
  98. // Interpret a relative path with respect to the current binary directory.
  99. if(cmSystemTools::FileIsFullPath(binArg.c_str()))
  100. {
  101. binPath = binArg;
  102. }
  103. else
  104. {
  105. binPath = this->Makefile->GetCurrentOutputDirectory();
  106. binPath += "/";
  107. binPath += binArg;
  108. }
  109. }
  110. binPath = cmSystemTools::CollapseFullPath(binPath.c_str());
  111. // Add the subdirectory using the computed full paths.
  112. this->Makefile->AddSubDirectory(srcPath.c_str(), binPath.c_str(),
  113. excludeFromAll, false, true);
  114. return true;
  115. }