cmUtilitySourceCommand.cxx 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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 "cmUtilitySourceCommand.h"
  11. // cmUtilitySourceCommand
  12. bool cmUtilitySourceCommand
  13. ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
  14. {
  15. if(this->Disallowed(cmPolicies::CMP0034,
  16. "The utility_source command should not be called; see CMP0034."))
  17. { return true; }
  18. if(args.size() < 3)
  19. {
  20. this->SetError("called with incorrect number of arguments");
  21. return false;
  22. }
  23. std::vector<std::string>::const_iterator arg = args.begin();
  24. // The first argument is the cache entry name.
  25. std::string cacheEntry = *arg++;
  26. const char* cacheValue =
  27. this->Makefile->GetDefinition(cacheEntry.c_str());
  28. // If it exists already and appears up to date then we are done. If
  29. // the string contains "(IntDir)" but that is not the
  30. // CMAKE_CFG_INTDIR setting then the value is out of date.
  31. const char* intDir =
  32. this->Makefile->GetRequiredDefinition("CMAKE_CFG_INTDIR");
  33. bool haveCacheValue = false;
  34. if (this->Makefile->IsOn("CMAKE_CROSSCOMPILING"))
  35. {
  36. haveCacheValue = (cacheValue != 0);
  37. if (!haveCacheValue)
  38. {
  39. std::string msg = "UTILITY_SOURCE is used in cross compiling mode for ";
  40. msg += cacheEntry;
  41. msg += ". If your intention is to run this executable, you need to "
  42. "preload the cache with the full path to a version of that "
  43. "program, which runs on this build machine.";
  44. cmSystemTools::Message(msg.c_str() ,"Warning");
  45. }
  46. }
  47. else
  48. {
  49. haveCacheValue = (cacheValue &&
  50. (strstr(cacheValue, "(IntDir)") == 0 ||
  51. (intDir && strcmp(intDir, "$(IntDir)") == 0)) &&
  52. (this->Makefile->GetCacheMajorVersion() != 0 &&
  53. this->Makefile->GetCacheMinorVersion() != 0 ));
  54. }
  55. if(haveCacheValue)
  56. {
  57. return true;
  58. }
  59. // The second argument is the utility's executable name, which will be
  60. // needed later.
  61. std::string utilityName = *arg++;
  62. // The third argument specifies the relative directory of the source
  63. // of the utility.
  64. std::string relativeSource = *arg++;
  65. std::string utilitySource = this->Makefile->GetCurrentDirectory();
  66. utilitySource = utilitySource+"/"+relativeSource;
  67. // If the directory doesn't exist, the source has not been included.
  68. if(!cmSystemTools::FileExists(utilitySource.c_str()))
  69. { return true; }
  70. // Make sure all the files exist in the source directory.
  71. while(arg != args.end())
  72. {
  73. std::string file = utilitySource+"/"+*arg++;
  74. if(!cmSystemTools::FileExists(file.c_str()))
  75. { return true; }
  76. }
  77. // The source exists.
  78. std::string cmakeCFGout =
  79. this->Makefile->GetRequiredDefinition("CMAKE_CFG_INTDIR");
  80. std::string utilityDirectory = this->Makefile->GetCurrentOutputDirectory();
  81. std::string exePath;
  82. if (this->Makefile->GetDefinition("EXECUTABLE_OUTPUT_PATH"))
  83. {
  84. exePath = this->Makefile->GetDefinition("EXECUTABLE_OUTPUT_PATH");
  85. }
  86. if(exePath.size())
  87. {
  88. utilityDirectory = exePath;
  89. }
  90. else
  91. {
  92. utilityDirectory += "/"+relativeSource;
  93. }
  94. // Construct the cache entry for the executable's location.
  95. std::string utilityExecutable =
  96. utilityDirectory+"/"+cmakeCFGout+"/"
  97. +utilityName+this->Makefile->GetDefinition("CMAKE_EXECUTABLE_SUFFIX");
  98. // make sure we remove any /./ in the name
  99. cmSystemTools::ReplaceString(utilityExecutable, "/./", "/");
  100. // Enter the value into the cache.
  101. this->Makefile->AddCacheDefinition(cacheEntry.c_str(),
  102. utilityExecutable.c_str(),
  103. "Path to an internal program.",
  104. cmCacheManager::FILEPATH);
  105. // add a value into the cache that maps from the
  106. // full path to the name of the project
  107. cmSystemTools::ConvertToUnixSlashes(utilityExecutable);
  108. this->Makefile->AddCacheDefinition(utilityExecutable.c_str(),
  109. utilityName.c_str(),
  110. "Executable to project name.",
  111. cmCacheManager::INTERNAL);
  112. return true;
  113. }