cmIncludeCommand.cxx 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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 ignore 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(!cmSystemTools::FileIsFullPath(fname.c_str()))
  68. {
  69. // Not a path. Maybe module.
  70. std::string module = fname;
  71. module += ".cmake";
  72. std::string mfile = this->Makefile->GetModulesFile(module.c_str());
  73. if ( mfile.size() )
  74. {
  75. fname = mfile.c_str();
  76. }
  77. }
  78. std::string fullFilePath;
  79. bool readit =
  80. this->Makefile->ReadListFile( this->Makefile->GetCurrentListFile(),
  81. fname.c_str(), &fullFilePath,
  82. noPolicyScope);
  83. // add the location of the included file if a result variable was given
  84. if (resultVarName.size())
  85. {
  86. this->Makefile->AddDefinition(resultVarName.c_str(),
  87. readit?fullFilePath.c_str():"NOTFOUND");
  88. }
  89. if(!optional && !readit && !cmSystemTools::GetFatalErrorOccured())
  90. {
  91. std::string m =
  92. "could not find load file:\n"
  93. " ";
  94. m += fname;
  95. this->SetError(m.c_str());
  96. return false;
  97. }
  98. return true;
  99. }