You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

164 lines
4.7 KiB

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