cmUtilitySourceCommand.cxx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*=========================================================================
  2. Program: Insight Segmentation & Registration Toolkit
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Insight Consortium. All rights reserved.
  8. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm 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& argsIn)
  16. {
  17. if(argsIn.size() < 3)
  18. {
  19. this->SetError("called with incorrect number of arguments");
  20. return false;
  21. }
  22. std::vector<std::string> args;
  23. cmSystemTools::ExpandListArguments(argsIn, args);
  24. std::vector<std::string>::const_iterator arg = args.begin();
  25. // The first argument is the cache entry name.
  26. std::string cacheEntry = *arg++;
  27. const char* cacheValue =
  28. m_Makefile->GetDefinition(cacheEntry.c_str());
  29. // If it exists already, we are done.
  30. // unless this is Major
  31. if(cacheValue &&
  32. (m_Makefile->GetCacheMajorVersion() != 0
  33. && m_Makefile->GetCacheMinorVersion() != 0 ))
  34. {
  35. return true;
  36. }
  37. // The second argument is the utility's executable name, which will be
  38. // needed later.
  39. std::string utilityName = *arg++;
  40. // The third argument specifies the relative directory of the source
  41. // of the utility.
  42. std::string relativeSource = *arg++;
  43. std::string utilitySource = m_Makefile->GetCurrentDirectory();
  44. utilitySource = utilitySource+"/"+relativeSource;
  45. // If the directory doesn't exist, the source has not been included.
  46. if(!cmSystemTools::FileExists(utilitySource.c_str()))
  47. { return true; }
  48. // Make sure all the files exist in the source directory.
  49. while(arg != args.end())
  50. {
  51. std::string file = utilitySource+"/"+*arg++;
  52. if(!cmSystemTools::FileExists(file.c_str()))
  53. { return true; }
  54. }
  55. // The source exists.
  56. std::string cmakeCFGout = m_Makefile->GetDefinition("CMAKE_CFG_INTDIR");
  57. std::string utilityDirectory = m_Makefile->GetCurrentOutputDirectory();
  58. std::string exePath;
  59. if (m_Makefile->GetDefinition("EXECUTABLE_OUTPUT_PATH"))
  60. {
  61. exePath = m_Makefile->GetDefinition("EXECUTABLE_OUTPUT_PATH");
  62. }
  63. if(exePath.size())
  64. {
  65. utilityDirectory = exePath;
  66. }
  67. else
  68. {
  69. utilityDirectory += "/"+relativeSource;
  70. }
  71. // Construct the cache entry for the executable's location.
  72. std::string utilityExecutable =
  73. utilityDirectory+"/"+cmakeCFGout+"/"
  74. +utilityName+cmSystemTools::GetExecutableExtension();
  75. // Enter the value into the cache.
  76. m_Makefile->AddCacheDefinition(cacheEntry.c_str(),
  77. utilityExecutable.c_str(),
  78. "Path to an internal program.",
  79. cmCacheManager::FILEPATH);
  80. // add a value into the cache that maps from the
  81. // full path to the name of the project
  82. cmSystemTools::ConvertToUnixSlashes(utilityExecutable);
  83. m_Makefile->AddCacheDefinition(utilityExecutable.c_str(),
  84. utilityName.c_str(),
  85. "Executable to project name.",
  86. cmCacheManager::INTERNAL);
  87. return true;
  88. }