cmUtilitySourceCommand.cxx 3.4 KB

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