cmITKWrapTclCommand.cxx 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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 "cmITKWrapTclCommand.h"
  14. #include "cmMakeDepend.h"
  15. cmITKWrapTclCommand::cmITKWrapTclCommand():
  16. m_MakeDepend(new cmMakeDepend)
  17. {
  18. }
  19. cmITKWrapTclCommand::~cmITKWrapTclCommand()
  20. {
  21. delete m_MakeDepend;
  22. }
  23. // cmITKWrapTclCommand
  24. bool cmITKWrapTclCommand::InitialPass(std::vector<std::string> const& argsIn)
  25. {
  26. if(argsIn.size() < 2 )
  27. {
  28. this->SetError("called with incorrect number of arguments");
  29. return false;
  30. }
  31. std::vector<std::string> args;
  32. cmSystemTools::ExpandListArguments(argsIn, args);
  33. // keep the target name
  34. m_TargetName = args[0];
  35. // Prepare the dependency generator.
  36. m_MakeDepend->SetMakefile(m_Makefile);
  37. for(std::vector<std::string>::const_iterator i = (args.begin() + 1);
  38. i != args.end(); ++i)
  39. {
  40. if(!this->CreateCableRule((*i).c_str())) { return false; }
  41. }
  42. // Add the source list to the target.
  43. m_Makefile->GetTargets()[m_TargetName.c_str()].GetSourceLists().push_back(m_TargetName);
  44. return true;
  45. }
  46. bool cmITKWrapTclCommand::CreateCableRule(const char* configFile)
  47. {
  48. std::string tclFile =
  49. cmSystemTools::GetFilenameNameWithoutExtension(configFile);
  50. tclFile += "_tcl";
  51. std::string inFile = m_Makefile->GetCurrentDirectory();
  52. inFile += "/";
  53. inFile += configFile;
  54. std::string outDir = m_Makefile->GetCurrentOutputDirectory();
  55. // Generate the rule to run cable to generate wrappers.
  56. std::string command = this->GetCableFromCache();
  57. std::vector<std::string> depends;
  58. // Special case for CMake's wrapping test. Don't add dependency if
  59. // it is a dummy executable.
  60. if(command != "echo")
  61. {
  62. depends.push_back(command);
  63. }
  64. std::vector<std::string> commandArgs;
  65. commandArgs.push_back(inFile);
  66. commandArgs.push_back("-tcl");
  67. std::string tmp = tclFile+".cxx";
  68. commandArgs.push_back(tmp);
  69. #if !defined(_WIN32) || defined(__CYGWIN__)
  70. tmp = "${CMAKE_CXX_COMPILER}";
  71. m_Makefile->ExpandVariablesInString(tmp);
  72. if(tmp.length() > 0)
  73. {
  74. commandArgs.push_back("--gccxml-compiler");
  75. commandArgs.push_back(tmp);
  76. }
  77. #endif
  78. tmp = "-I";
  79. tmp += m_Makefile->GetStartDirectory();
  80. commandArgs.push_back(tmp);
  81. const std::vector<std::string>& includes =
  82. m_Makefile->GetIncludeDirectories();
  83. for(std::vector<std::string>::const_iterator i = includes.begin();
  84. i != includes.end(); ++i)
  85. {
  86. tmp = "-I";
  87. tmp += i->c_str();
  88. m_Makefile->ExpandVariablesInString(tmp);
  89. commandArgs.push_back(tmp);
  90. }
  91. // Get the dependencies.
  92. const cmDependInformation* info =
  93. m_MakeDepend->FindDependencies(inFile.c_str());
  94. if (info)
  95. {
  96. for(cmDependInformation::DependencySet::const_iterator d =
  97. info->m_DependencySet.begin();
  98. d != info->m_DependencySet.end(); ++d)
  99. {
  100. // Make sure the full path is given. If not, the dependency was
  101. // not found.
  102. if((*d)->m_FullPath != "")
  103. {
  104. depends.push_back((*d)->m_FullPath);
  105. }
  106. }
  107. }
  108. std::vector<std::string> outputs;
  109. outputs.push_back(outDir+"/"+tclFile+".cxx");
  110. m_Makefile->AddCustomCommand(inFile.c_str(),
  111. command.c_str(),
  112. commandArgs, depends,
  113. outputs, m_TargetName.c_str());
  114. // Add the generated source to the package's source list.
  115. cmSourceFile file;
  116. file.SetName(tclFile.c_str(), outDir.c_str(), "cxx", false);
  117. // Set dependency hints.
  118. file.GetDepends().push_back(inFile.c_str());
  119. file.GetDepends().push_back("CableTclFacility/ctCalls.h");
  120. m_Makefile->AddSource(file, m_TargetName.c_str());
  121. return true;
  122. }
  123. /**
  124. * Get the "CABLE" cache entry value. If there is no cache entry for CABLE,
  125. * one will be created and initialized to NOTFOUND.
  126. */
  127. std::string cmITKWrapTclCommand::GetCableFromCache() const
  128. {
  129. const char* cable =
  130. m_Makefile->GetDefinition("CABLE");
  131. if(cable)
  132. { return cable; }
  133. m_Makefile->AddCacheDefinition("CABLE",
  134. "NOTFOUND",
  135. "Path to CABLE executable.",
  136. cmCacheManager::FILEPATH);
  137. return "NOTFOUND";
  138. }