cmAddSubDirectoryCommand.cxx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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(std::vector<std::string> const& args)
  16. {
  17. if(args.size() < 1 )
  18. {
  19. this->SetError("called with incorrect number of arguments");
  20. return false;
  21. }
  22. // store the binpath
  23. std::string srcArg = args[0];
  24. std::string binArg;
  25. bool intoplevel = true;
  26. // process the rest of the arguments looking for optional args
  27. std::vector<std::string>::const_iterator i = args.begin();
  28. ++i;
  29. for(;i != args.end(); ++i)
  30. {
  31. if(*i == "EXCLUDE_FROM_ALL")
  32. {
  33. intoplevel = false;
  34. continue;
  35. }
  36. else if (!binArg.size())
  37. {
  38. binArg = *i;
  39. }
  40. else
  41. {
  42. this->SetError("called with incorrect number of arguments");
  43. return false;
  44. }
  45. }
  46. // check for relative arguments
  47. bool relativeSource = true;
  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. relativeSource = false;
  55. srcPath = srcArg;
  56. if (!cmSystemTools::FileIsDirectory(srcPath.c_str()))
  57. {
  58. std::string error = "Incorrect ADD_SUBDIRECTORY command. Directory: ";
  59. error += srcArg + " does not exists.";
  60. this->SetError(error.c_str());
  61. return false;
  62. }
  63. }
  64. // at this point srcPath has the full path to the source directory
  65. // now we need to compute the binPath if it was not provided
  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. // if the srcArg was relative then we just do the same for the binPath
  79. if (relativeSource)
  80. {
  81. binPath = std::string(this->Makefile->GetCurrentOutputDirectory()) +
  82. "/" + srcArg;
  83. }
  84. // otherwise we try to remove the CurrentDirectory from the srcPath and
  85. // replace it with the CurrentOutputDirectory. This may not really work
  86. // because the source dir they provided may not be "in" the source
  87. // tree. This is an error if this happens.
  88. else
  89. {
  90. // try replacing the home dir with the home output dir
  91. binPath = srcPath;
  92. if (!cmSystemTools::FindLastString(binPath.c_str(),
  93. this->Makefile->GetHomeDirectory()))
  94. {
  95. this->SetError("A full source directory was specified that is not in the source tree but no binary directory was specified. If you specify an out of tree source directory then you must provide the binary directory as well.");
  96. return false;
  97. }
  98. cmSystemTools::ReplaceString(binPath,this->Makefile->GetHomeDirectory(),
  99. this->Makefile->GetHomeOutputDirectory());
  100. }
  101. }
  102. // now we have all the arguments
  103. this->Makefile->AddSubDirectory(srcPath.c_str(), binPath.c_str(),
  104. intoplevel, false, true);
  105. return true;
  106. }