cmUtilitySourceCommand.cxx 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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.
  51. std::string cmakeCFGout = m_Makefile->GetDefinition("CMAKE_CFG_OUTDIR");
  52. std::string utilityDirectory = m_Makefile->GetCurrentOutputDirectory();
  53. utilityDirectory += "/"+relativeSource;
  54. // Tell the makefile where to look for this utility.
  55. m_Makefile->AddUtilityDirectory(utilityDirectory.c_str());
  56. // Construct the cache entry for the executable's location.
  57. std::string utilityExecutable =
  58. utilityDirectory+"/"+cmakeCFGout+"/"
  59. +utilityName+cmSystemTools::GetExecutableExtension();
  60. // Enter the value into the cache.
  61. cmCacheManager::GetInstance()->AddCacheEntry(cacheEntry.c_str(),
  62. utilityExecutable.c_str(),
  63. cmCacheManager::FILEPATH);
  64. // Set the definition in the makefile.
  65. m_Makefile->AddDefinition(cacheEntry.c_str(), utilityExecutable.c_str());
  66. return true;
  67. }