cmAddSubDirectoryCommand.cxx 3.8 KB

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