cmITKWrapTclCommand.cxx 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html 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. void
  24. cmITKWrapTclCommand::AddDependencies(cmDependInformation const *info,
  25. std::vector<std::string>& depends,
  26. std::set<cmDependInformation const*>& visited)
  27. {
  28. if(!info)
  29. {
  30. return;
  31. }
  32. // add info to the visited set
  33. visited.insert(info);
  34. // add this dependency and the recurse
  35. // now recurse with info's dependencies
  36. for(cmDependInformation::DependencySet::const_iterator d =
  37. info->m_DependencySet.begin();
  38. d != info->m_DependencySet.end(); ++d)
  39. {
  40. if (visited.find(*d) == visited.end())
  41. {
  42. if((*d)->m_FullPath != "")
  43. {
  44. depends.push_back((*d)->m_FullPath);
  45. }
  46. this->AddDependencies(*d,depends,visited);
  47. }
  48. }
  49. }
  50. // cmITKWrapTclCommand
  51. bool cmITKWrapTclCommand::InitialPass(std::vector<std::string> const& args)
  52. {
  53. // deprecated
  54. const char* versionValue
  55. = m_Makefile->GetDefinition("CMAKE_BACKWARDS_COMPATIBILITY");
  56. if (atof(versionValue) > 2.2)
  57. {
  58. this->SetError("The ITK_WRAP_TCL command was deprecated in CMake version 2.2 and will be removed in later versions of CMake. You should modify your CMakeLists.txt files to use the MACRO command or use CMake 2.2 or earlier for this project.\n");
  59. return false;
  60. }
  61. if (atof(versionValue) > 2.0)
  62. {
  63. cmSystemTools::Message("The ITK_WRAP_TCL command was deprecated in CMake version 2.2 and will be removed in later versions. You should modify your CMakeLists.txt files to use a MACRO or use CMake 2.2 or earlier.\n","Warning");
  64. }
  65. if(args.size() < 2 )
  66. {
  67. this->SetError("called with incorrect number of arguments");
  68. return false;
  69. }
  70. // keep the target name
  71. m_TargetName = args[0];
  72. m_Target = &m_Makefile->GetTargets()[m_TargetName.c_str()];
  73. // Prepare the dependency generator.
  74. m_MakeDepend->SetMakefile(m_Makefile);
  75. for(std::vector<std::string>::const_iterator i = (args.begin() + 1);
  76. i != args.end(); ++i)
  77. {
  78. if(!this->CreateCableRule((*i).c_str())) { return false; }
  79. }
  80. return true;
  81. }
  82. bool cmITKWrapTclCommand::CreateCableRule(const char* configFile)
  83. {
  84. std::string tclFile =
  85. cmSystemTools::GetFilenameWithoutExtension(configFile);
  86. tclFile += "_tcl";
  87. std::string inFile = m_Makefile->GetCurrentDirectory();
  88. inFile += "/";
  89. inFile += configFile;
  90. std::string outDir = m_Makefile->GetCurrentOutputDirectory();
  91. // Generate the rule to run cable to generate wrappers.
  92. std::string command = this->GetCableFromCache();
  93. std::vector<std::string> depends;
  94. // Special case for CMake's wrapping test. Don't add dependency if
  95. // it is a dummy executable.
  96. if(command != "echo")
  97. {
  98. depends.push_back(command);
  99. }
  100. cmCustomCommandLine commandLine;
  101. commandLine.push_back(command);
  102. commandLine.push_back(inFile);
  103. commandLine.push_back("-tcl");
  104. std::string tmp = tclFile+".cxx";
  105. commandLine.push_back(tmp);
  106. #if !defined(_WIN32) || defined(__CYGWIN__)
  107. tmp = "${CMAKE_CXX_COMPILER}";
  108. m_Makefile->ExpandVariablesInString(tmp);
  109. if(tmp.length() > 0)
  110. {
  111. commandLine.push_back("--gccxml-compiler");
  112. commandLine.push_back(tmp);
  113. tmp = "${CMAKE_CXX_FLAGS}";
  114. m_Makefile->ExpandVariablesInString(tmp);
  115. commandLine.push_back("--gccxml-cxxflags");
  116. commandLine.push_back(tmp);
  117. }
  118. #else
  119. const char* genName = m_Makefile->GetDefinition("CMAKE_GENERATOR");
  120. if (genName)
  121. {
  122. std::string gen = genName;
  123. if(gen == "Visual Studio 6")
  124. {
  125. commandLine.push_back("--gccxml-compiler");
  126. commandLine.push_back("msvc6");
  127. tmp = "${CMAKE_CXX_FLAGS}";
  128. m_Makefile->ExpandVariablesInString(tmp);
  129. commandLine.push_back("--gccxml-cxxflags");
  130. commandLine.push_back(tmp);
  131. }
  132. else if(gen == "Visual Studio 7")
  133. {
  134. commandLine.push_back("--gccxml-compiler");
  135. commandLine.push_back("msvc7");
  136. tmp = "${CMAKE_CXX_FLAGS}";
  137. m_Makefile->ExpandVariablesInString(tmp);
  138. commandLine.push_back("--gccxml-cxxflags");
  139. commandLine.push_back(tmp);
  140. }
  141. else if(gen == "NMake Makefiles")
  142. {
  143. tmp = "${CMAKE_CXX_COMPILER}";
  144. m_Makefile->ExpandVariablesInString(tmp);
  145. commandLine.push_back("--gccxml-compiler");
  146. commandLine.push_back(tmp);
  147. tmp = "${CMAKE_CXX_FLAGS}";
  148. m_Makefile->ExpandVariablesInString(tmp);
  149. commandLine.push_back("--gccxml-cxxflags");
  150. commandLine.push_back(tmp);
  151. }
  152. }
  153. #endif
  154. const char* gccxml = m_Makefile->GetDefinition("ITK_GCCXML_EXECUTABLE");
  155. if(gccxml)
  156. {
  157. commandLine.push_back("--gccxml");
  158. commandLine.push_back(gccxml);
  159. }
  160. tmp = "-I";
  161. tmp += m_Makefile->GetStartDirectory();
  162. commandLine.push_back(tmp);
  163. const std::vector<std::string>& includes =
  164. m_Makefile->GetIncludeDirectories();
  165. for(std::vector<std::string>::const_iterator i = includes.begin();
  166. i != includes.end(); ++i)
  167. {
  168. tmp = "-I";
  169. tmp += i->c_str();
  170. m_Makefile->ExpandVariablesInString(tmp);
  171. commandLine.push_back(tmp);
  172. }
  173. // Get the dependencies.
  174. const cmDependInformation* info =
  175. m_MakeDepend->FindDependencies(inFile.c_str());
  176. if (info)
  177. {
  178. std::set<cmDependInformation const*> visited;
  179. this->AddDependencies(info, depends, visited);
  180. }
  181. std::string output;
  182. output = outDir+"/"+tclFile+".cxx";
  183. // Add the source to the makefile.
  184. cmSourceFile file;
  185. file.SetName(tclFile.c_str(), outDir.c_str(), "cxx", false);
  186. // Set dependency hints.
  187. file.GetDepends().push_back(inFile.c_str());
  188. file.GetDepends().push_back("CableTclFacility/ctCalls.h");
  189. m_Makefile->AddSource(file);
  190. const char* no_comment = 0;
  191. cmCustomCommandLines commandLines;
  192. commandLines.push_back(commandLine);
  193. m_Makefile->AddCustomCommandToOutput(output.c_str(), depends,
  194. inFile.c_str(), commandLines,
  195. no_comment);
  196. // Add the generated source to the package's source list.
  197. m_Target->GetSourceLists().push_back(output);
  198. return true;
  199. }
  200. /**
  201. * Get the "CABLE" cache entry value. If there is no cache entry for CABLE,
  202. * one will be created and initialized to NOTFOUND.
  203. */
  204. std::string cmITKWrapTclCommand::GetCableFromCache() const
  205. {
  206. const char* cable =
  207. m_Makefile->GetDefinition("CABLE");
  208. if(cable)
  209. { return cable; }
  210. m_Makefile->AddCacheDefinition("CABLE",
  211. "CABLE-NOTFOUND",
  212. "Path to CABLE executable.",
  213. cmCacheManager::FILEPATH);
  214. return "CABLE-NOTFOUND";
  215. }