cmVariableRequiresCommand.cxx 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 "cmVariableRequiresCommand.h"
  14. #include "cmCacheManager.h"
  15. // cmLibraryCommand
  16. bool cmVariableRequiresCommand::InitialPass(std::vector<std::string> const& args)
  17. {
  18. if(args.size() < 3 )
  19. {
  20. this->SetError("called with incorrect number of arguments");
  21. return false;
  22. }
  23. m_Arguments = args;
  24. return true;
  25. }
  26. void cmVariableRequiresCommand::FinalPass()
  27. {
  28. std::string testVariable = m_Arguments[0];
  29. if(!m_Makefile->IsOn(testVariable.c_str()))
  30. {
  31. return;
  32. }
  33. std::string resultVariable = m_Arguments[1];
  34. bool requirementsMet = true;
  35. std::string notSet;
  36. bool hasAdvanced = false;
  37. for(unsigned int i = 2; i < m_Arguments.size(); ++i)
  38. {
  39. if(!m_Makefile->IsOn(m_Arguments[i].c_str()))
  40. {
  41. requirementsMet = false;
  42. notSet += m_Arguments[i];
  43. notSet += "\n";
  44. cmCacheManager::CacheIterator it =
  45. m_Makefile->GetCacheManager()->GetCacheIterator(m_Arguments[i].c_str());
  46. if(!it.IsAtEnd() && it.GetPropertyAsBool("ADVANCED"))
  47. {
  48. hasAdvanced = true;
  49. }
  50. }
  51. }
  52. const char* reqVar = m_Makefile->GetDefinition(resultVariable.c_str());
  53. // if reqVar is unset, then set it to requirementsMet
  54. // if reqVar is set to true, but requirementsMet is false , then
  55. // set reqVar to false.
  56. if(!reqVar || (!requirementsMet && m_Makefile->IsOn(reqVar)))
  57. {
  58. m_Makefile->AddDefinition(resultVariable.c_str(), requirementsMet);
  59. }
  60. if(!requirementsMet)
  61. {
  62. std::string message = "Variable assertion failed:\n";
  63. message += testVariable + " Requires that the following unset variables are set:\n";
  64. message += notSet;
  65. message += "\nPlease set them, or set ";
  66. message += testVariable + " to false, and re-configure.\n";
  67. if(hasAdvanced)
  68. {
  69. message += "One or more of the required variables is advanced. To set the variable, you must turn on advanced mode in cmake.";
  70. }
  71. cmSystemTools::Error(message.c_str());
  72. }
  73. }