cmAddSubDirectoryCommand.cxx 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 binArg = args[0];
  24. std::string srcArg;
  25. bool intoplevel = true;
  26. bool preorder = 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. intoplevel = false;
  35. continue;
  36. }
  37. else if(*i == "PREORDER")
  38. {
  39. preorder = true;
  40. continue;
  41. }
  42. else if (!srcArg.size())
  43. {
  44. srcArg = *i;
  45. }
  46. else
  47. {
  48. this->SetError("called with incorrect number of arguments");
  49. return false;
  50. }
  51. }
  52. // if srcArg not provided use binArg
  53. if (!srcArg.size())
  54. {
  55. srcArg = binArg;
  56. }
  57. // now we have all the arguments
  58. // if they specified a relative path then compute the full
  59. std::string srcPath = std::string(m_Makefile->GetCurrentDirectory()) +
  60. "/" + srcArg;
  61. if (!cmSystemTools::FileIsDirectory(srcPath.c_str()))
  62. {
  63. srcPath = srcArg;
  64. if (!cmSystemTools::FileIsDirectory(srcPath.c_str()))
  65. {
  66. std::string error = "Incorrect ADD_SUBDIRECTORY command. Directory: ";
  67. error += srcArg + " does not exists.";
  68. this->SetError(error.c_str());
  69. return false;
  70. }
  71. }
  72. std::string binPath = binArg;
  73. if (!cmSystemTools::FileIsFullPath(binPath.c_str()))
  74. {
  75. binPath = std::string(m_Makefile->GetCurrentOutputDirectory()) +
  76. "/" + binArg.c_str();
  77. }
  78. m_Makefile->AddSubDirectory(srcPath.c_str(), binPath.c_str(),
  79. intoplevel, preorder, true);
  80. return true;
  81. }