cmUtilitySourceCommand.cxx 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*=========================================================================
  2. Program: Insight Segmentation & Registration Toolkit
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2001 Insight Consortium
  8. All rights reserved.
  9. Redistribution and use in source and binary forms, with or without
  10. modification, are permitted provided that the following conditions are met:
  11. * Redistributions of source code must retain the above copyright notice,
  12. this list of conditions and the following disclaimer.
  13. * Redistributions in binary form must reproduce the above copyright notice,
  14. this list of conditions and the following disclaimer in the documentation
  15. and/or other materials provided with the distribution.
  16. * The name of the Insight Consortium, nor the names of any consortium members,
  17. nor of any contributors, may be used to endorse or promote products derived
  18. from this software without specific prior written permission.
  19. * Modified source versions must be plainly marked as such, and must not be
  20. misrepresented as being the original software.
  21. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS ``AS IS''
  22. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  23. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  24. ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
  25. ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  26. DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  27. SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  28. CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  29. OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  30. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. =========================================================================*/
  32. #include "cmUtilitySourceCommand.h"
  33. // cmUtilitySourceCommand
  34. bool cmUtilitySourceCommand::InitialPass(std::vector<std::string> const& args)
  35. {
  36. if(args.size() < 3)
  37. {
  38. this->SetError("called with incorrect number of arguments");
  39. return false;
  40. }
  41. std::vector<std::string>::const_iterator arg = args.begin();
  42. // The first argument is the cache entry name.
  43. std::string cacheEntry = *arg++;
  44. const char* cacheValue =
  45. m_Makefile->GetDefinition(cacheEntry.c_str());
  46. // If it exists already, we are done.
  47. // unless this is Major
  48. if(cacheValue &&
  49. (m_Makefile->GetCacheMajorVersion() != 0
  50. && m_Makefile->GetCacheMinorVersion() != 0 ))
  51. {
  52. return true;
  53. }
  54. // The second argument is the utility's executable name, which will be
  55. // needed later.
  56. std::string utilityName = *arg++;
  57. // The third argument specifies the relative directory of the source
  58. // of the utility.
  59. std::string relativeSource = *arg++;
  60. std::string utilitySource = m_Makefile->GetCurrentDirectory();
  61. utilitySource = utilitySource+"/"+relativeSource;
  62. // If the directory doesn't exist, the source has not been included.
  63. if(!cmSystemTools::FileExists(utilitySource.c_str()))
  64. { return true; }
  65. // Make sure all the files exist in the source directory.
  66. while(arg != args.end())
  67. {
  68. std::string file = utilitySource+"/"+*arg++;
  69. if(!cmSystemTools::FileExists(file.c_str()))
  70. { return true; }
  71. }
  72. // The source exists.
  73. std::string cmakeCFGout = m_Makefile->GetDefinition("CMAKE_CFG_INTDIR");
  74. std::string utilityDirectory = m_Makefile->GetCurrentOutputDirectory();
  75. std::string exePath;
  76. if (m_Makefile->GetDefinition("EXECUTABLE_OUTPUT_PATH"))
  77. {
  78. exePath = m_Makefile->GetDefinition("EXECUTABLE_OUTPUT_PATH");
  79. }
  80. if(exePath.size())
  81. {
  82. utilityDirectory = exePath;
  83. }
  84. else
  85. {
  86. utilityDirectory += "/"+relativeSource;
  87. }
  88. // Construct the cache entry for the executable's location.
  89. std::string utilityExecutable =
  90. utilityDirectory+"/"+cmakeCFGout+"/"
  91. +utilityName+cmSystemTools::GetExecutableExtension();
  92. // Enter the value into the cache.
  93. m_Makefile->AddCacheDefinition(cacheEntry.c_str(),
  94. utilityExecutable.c_str(),
  95. "Path to an internal program.",
  96. cmCacheManager::FILEPATH);
  97. // add a value into the cache that maps from the
  98. // full path to the name of the project
  99. cmSystemTools::ConvertToUnixSlashes(utilityExecutable);
  100. m_Makefile->AddCacheDefinition(utilityExecutable.c_str(),
  101. utilityName.c_str(),
  102. "Executable to project name.",
  103. cmCacheManager::INTERNAL);
  104. return true;
  105. }