cmUtilitySourceCommand.cxx 3.8 KB

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