cmUtilitySourceCommand.cxx 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 =
  31. this->Makefile->GetRequiredDefinition("CMAKE_CFG_INTDIR");
  32. if(cacheValue &&
  33. (strstr(cacheValue, "(IntDir)") == 0 ||
  34. intDir && strcmp(intDir, "$(IntDir)") == 0) &&
  35. (this->Makefile->GetCacheMajorVersion() != 0 &&
  36. this->Makefile->GetCacheMinorVersion() != 0 ))
  37. {
  38. return true;
  39. }
  40. // The second argument is the utility's executable name, which will be
  41. // needed later.
  42. std::string utilityName = *arg++;
  43. // The third argument specifies the relative directory of the source
  44. // of the utility.
  45. std::string relativeSource = *arg++;
  46. std::string utilitySource = this->Makefile->GetCurrentDirectory();
  47. utilitySource = utilitySource+"/"+relativeSource;
  48. // If the directory doesn't exist, the source has not been included.
  49. if(!cmSystemTools::FileExists(utilitySource.c_str()))
  50. { return true; }
  51. // Make sure all the files exist in the source directory.
  52. while(arg != args.end())
  53. {
  54. std::string file = utilitySource+"/"+*arg++;
  55. if(!cmSystemTools::FileExists(file.c_str()))
  56. { return true; }
  57. }
  58. // The source exists.
  59. std::string cmakeCFGout =
  60. this->Makefile->GetRequiredDefinition("CMAKE_CFG_INTDIR");
  61. std::string utilityDirectory = this->Makefile->GetCurrentOutputDirectory();
  62. std::string exePath;
  63. if (this->Makefile->GetDefinition("EXECUTABLE_OUTPUT_PATH"))
  64. {
  65. exePath = this->Makefile->GetDefinition("EXECUTABLE_OUTPUT_PATH");
  66. }
  67. if(exePath.size())
  68. {
  69. utilityDirectory = exePath;
  70. }
  71. else
  72. {
  73. utilityDirectory += "/"+relativeSource;
  74. }
  75. // Construct the cache entry for the executable's location.
  76. std::string utilityExecutable =
  77. utilityDirectory+"/"+cmakeCFGout+"/"
  78. +utilityName+this->Makefile->GetDefinition("CMAKE_EXECUTABLE_SUFFIX");
  79. // make sure we remove any /./ in the name
  80. cmSystemTools::ReplaceString(utilityExecutable, "/./", "/");
  81. // Enter the value into the cache.
  82. this->Makefile->AddCacheDefinition(cacheEntry.c_str(),
  83. utilityExecutable.c_str(),
  84. "Path to an internal program.",
  85. cmCacheManager::FILEPATH);
  86. // add a value into the cache that maps from the
  87. // full path to the name of the project
  88. cmSystemTools::ConvertToUnixSlashes(utilityExecutable);
  89. this->Makefile->AddCacheDefinition(utilityExecutable.c_str(),
  90. utilityName.c_str(),
  91. "Executable to project name.",
  92. cmCacheManager::INTERNAL);
  93. return true;
  94. }