cmAddSubDirectoryCommand.cxx 2.4 KB

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