cmIncludeCommand.cxx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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 "cmIncludeCommand.h"
  14. // cmIncludeCommand
  15. bool cmIncludeCommand
  16. ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
  17. {
  18. if (args.size()< 1 || args.size() > 4)
  19. {
  20. this->SetError("called with wrong number of arguments. "
  21. "Include only takes one file.");
  22. return false;
  23. }
  24. bool optional = false;
  25. bool noPolicyScope = false;
  26. std::string fname = args[0];
  27. std::string resultVarName;
  28. for (unsigned int i=1; i<args.size(); i++)
  29. {
  30. if (args[i] == "OPTIONAL")
  31. {
  32. if (optional)
  33. {
  34. this->SetError("called with invalid arguments: OPTIONAL used twice");
  35. return false;
  36. }
  37. optional = true;
  38. }
  39. else if(args[i] == "RESULT_VARIABLE")
  40. {
  41. if (resultVarName.size() > 0)
  42. {
  43. this->SetError("called with invalid arguments: "
  44. "only one result variable allowed");
  45. return false;
  46. }
  47. if(++i < args.size())
  48. {
  49. resultVarName = args[i];
  50. }
  51. else
  52. {
  53. this->SetError("called with no value for RESULT_VARIABLE.");
  54. return false;
  55. }
  56. }
  57. else if(args[i] == "NO_POLICY_SCOPE")
  58. {
  59. noPolicyScope = true;
  60. }
  61. else if(i > 1) // compat.: in previous cmake versions the second
  62. // parameter was ignore if it wasn't "OPTIONAL"
  63. {
  64. std::string errorText = "called with invalid argument: ";
  65. errorText += args[i];
  66. this->SetError(errorText.c_str());
  67. return false;
  68. }
  69. }
  70. if(!cmSystemTools::FileIsFullPath(fname.c_str()))
  71. {
  72. // Not a path. Maybe module.
  73. std::string module = fname;
  74. module += ".cmake";
  75. std::string mfile = this->Makefile->GetModulesFile(module.c_str());
  76. if ( mfile.size() )
  77. {
  78. fname = mfile.c_str();
  79. }
  80. }
  81. std::string fullFilePath;
  82. bool readit =
  83. this->Makefile->ReadListFile( this->Makefile->GetCurrentListFile(),
  84. fname.c_str(), &fullFilePath,
  85. noPolicyScope);
  86. // add the location of the included file if a result variable was given
  87. if (resultVarName.size())
  88. {
  89. this->Makefile->AddDefinition(resultVarName.c_str(),
  90. readit?fullFilePath.c_str():"NOTFOUND");
  91. }
  92. if(!optional && !readit && !cmSystemTools::GetFatalErrorOccured())
  93. {
  94. std::string m =
  95. "could not find load file:\n"
  96. " ";
  97. m += fname;
  98. this->SetError(m.c_str());
  99. return false;
  100. }
  101. return true;
  102. }