cmIncludeCommand.cxx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include "cmIncludeCommand.h"
  11. // cmIncludeCommand
  12. bool cmIncludeCommand
  13. ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
  14. {
  15. if (args.size()< 1 || args.size() > 4)
  16. {
  17. this->SetError("called with wrong number of arguments. "
  18. "Include only takes one file.");
  19. return false;
  20. }
  21. bool optional = false;
  22. bool noPolicyScope = false;
  23. std::string fname = args[0];
  24. std::string resultVarName;
  25. for (unsigned int i=1; i<args.size(); i++)
  26. {
  27. if (args[i] == "OPTIONAL")
  28. {
  29. if (optional)
  30. {
  31. this->SetError("called with invalid arguments: OPTIONAL used twice");
  32. return false;
  33. }
  34. optional = true;
  35. }
  36. else if(args[i] == "RESULT_VARIABLE")
  37. {
  38. if (resultVarName.size() > 0)
  39. {
  40. this->SetError("called with invalid arguments: "
  41. "only one result variable allowed");
  42. return false;
  43. }
  44. if(++i < args.size())
  45. {
  46. resultVarName = args[i];
  47. }
  48. else
  49. {
  50. this->SetError("called with no value for RESULT_VARIABLE.");
  51. return false;
  52. }
  53. }
  54. else if(args[i] == "NO_POLICY_SCOPE")
  55. {
  56. noPolicyScope = true;
  57. }
  58. else if(i > 1) // compat.: in previous cmake versions the second
  59. // parameter was ignored if it wasn't "OPTIONAL"
  60. {
  61. std::string errorText = "called with invalid argument: ";
  62. errorText += args[i];
  63. this->SetError(errorText.c_str());
  64. return false;
  65. }
  66. }
  67. if(fname.empty())
  68. {
  69. this->Makefile->IssueMessage(cmake::AUTHOR_WARNING,
  70. "include() given empty file name (ignored).");
  71. return true;
  72. }
  73. if(!cmSystemTools::FileIsFullPath(fname.c_str()))
  74. {
  75. // Not a path. Maybe module.
  76. std::string module = fname;
  77. module += ".cmake";
  78. std::string mfile = this->Makefile->GetModulesFile(module.c_str());
  79. if ( mfile.size() )
  80. {
  81. fname = mfile.c_str();
  82. }
  83. }
  84. std::string fullFilePath;
  85. bool readit =
  86. this->Makefile->ReadListFile( this->Makefile->GetCurrentListFile(),
  87. fname.c_str(), &fullFilePath,
  88. noPolicyScope);
  89. // add the location of the included file if a result variable was given
  90. if (resultVarName.size())
  91. {
  92. this->Makefile->AddDefinition(resultVarName.c_str(),
  93. readit?fullFilePath.c_str():"NOTFOUND");
  94. }
  95. if(!optional && !readit && !cmSystemTools::GetFatalErrorOccured())
  96. {
  97. std::string m =
  98. "could not find load file:\n"
  99. " ";
  100. m += fname;
  101. this->SetError(m.c_str());
  102. return false;
  103. }
  104. return true;
  105. }