cmUtilitySourceCommand.cxx 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*=========================================================================
  2. Program: Insight Segmentation & Registration Toolkit
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2000 National Library of Medicine
  8. All rights reserved.
  9. See COPYRIGHT.txt for copyright details.
  10. =========================================================================*/
  11. #include "cmUtilitySourceCommand.h"
  12. // cmUtilitySourceCommand
  13. bool cmUtilitySourceCommand::Invoke(std::vector<std::string>& args)
  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. cmCacheManager::GetInstance()->GetCacheValue(cacheEntry.c_str());
  25. // If it exists already, we are done.
  26. if(cacheValue)
  27. {
  28. // Set the makefile's definition with the cache value.
  29. m_Makefile->AddDefinition(cacheEntry.c_str(), cacheValue);
  30. return true;
  31. }
  32. // The second argument is the utility's executable name, which will be
  33. // needed later.
  34. std::string utilityName = *arg++;
  35. // The third argument specifies the relative directory of the source
  36. // of the utility.
  37. std::string relativeSource = *arg++;
  38. std::string utilitySource = m_Makefile->GetCurrentDirectory();
  39. utilitySource = utilitySource+"/"+relativeSource;
  40. // If the directory doesn't exist, the source has not been included.
  41. if(!cmSystemTools::FileExists(utilitySource.c_str()))
  42. { return true; }
  43. // Make sure all the files exist in the source directory.
  44. while(arg != args.end())
  45. {
  46. std::string file = utilitySource+"/"+*arg++;
  47. if(!cmSystemTools::FileExists(file.c_str()))
  48. { return true; }
  49. }
  50. // The source exists. Construct the cache entry for the executable's
  51. // location.
  52. std::string cmakeCFG = m_Makefile->GetDefinition("CMAKE_CFG");
  53. std::string utilityExecutable = m_Makefile->GetCurrentOutputDirectory();
  54. utilityExecutable =
  55. (utilityExecutable+"/"+relativeSource+"/"+cmakeCFG+"/"
  56. +utilityName+cmSystemTools::GetExecutableExtension());
  57. // Enter the value into the cache.
  58. cmCacheManager::GetInstance()->AddCacheEntry(cacheEntry.c_str(),
  59. utilityExecutable.c_str(),
  60. cmCacheManager::FILEPATH);
  61. // Set the definition in the makefile.
  62. m_Makefile->AddDefinition(cacheEntry.c_str(), utilityExecutable.c_str());
  63. return true;
  64. }