cmAddSubDirectoryCommand.cxx 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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 intoplevel = true;
  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. intoplevel = false;
  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. // check for relative arguments
  48. std::string binPath = binArg;
  49. std::string srcPath = std::string(this->Makefile->GetCurrentDirectory()) +
  50. "/" + srcArg;
  51. // if the path does not exist then the arg was relative
  52. if (!cmSystemTools::FileIsDirectory(srcPath.c_str()))
  53. {
  54. srcPath = srcArg;
  55. if (!cmSystemTools::FileIsDirectory(srcPath.c_str()))
  56. {
  57. std::string error = "Incorrect ADD_SUBDIRECTORY command. Directory: ";
  58. error += srcArg + " does not exists.";
  59. this->SetError(error.c_str());
  60. return false;
  61. }
  62. }
  63. // at this point srcPath has the full path to the source directory
  64. // now we need to compute the binPath if it was not provided
  65. srcPath = cmSystemTools::CollapseFullPath(srcPath.c_str());
  66. // if the argument was provided then use it
  67. if (binArg.size())
  68. {
  69. if (!cmSystemTools::FileIsFullPath(binPath.c_str()))
  70. {
  71. binPath = std::string(this->Makefile->GetCurrentOutputDirectory()) +
  72. "/" + binArg.c_str();
  73. }
  74. }
  75. // otherwise compute the binPath from the srcPath
  76. else
  77. {
  78. // we try to remove the CurrentDirectory from the srcPath and
  79. // replace it with the CurrentOutputDirectory. This may not really work
  80. // because the source dir they provided may not be "in" the source
  81. // tree. This is an error if this happens.
  82. // try replacing the home dir with the home output dir
  83. binPath = srcPath;
  84. if(!cmSystemTools::FindLastString(binPath.c_str(),
  85. this->Makefile->GetHomeDirectory()))
  86. {
  87. this->SetError("A full source directory was specified that is not "
  88. "in the source tree but no binary directory was "
  89. "specified. If you specify an out of tree source "
  90. "directory then you must provide the binary "
  91. "directory as well.");
  92. return false;
  93. }
  94. cmSystemTools::ReplaceString(binPath,
  95. this->Makefile->GetHomeDirectory(),
  96. this->Makefile->GetHomeOutputDirectory());
  97. }
  98. // now we have all the arguments
  99. this->Makefile->AddSubDirectory(srcPath.c_str(), binPath.c_str(),
  100. intoplevel, false, true);
  101. return true;
  102. }