cmUtilitySourceCommand.cxx 4.4 KB

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