cmITKWrapTclCommand.cxx 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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. // 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. tmp = "${CMAKE_CXX_FLAGS}";
  76. m_Makefile->ExpandVariablesInString(tmp);
  77. commandArgs.push_back("--gccxml-cxxflags");
  78. commandArgs.push_back(tmp);
  79. }
  80. #else
  81. const char* genName = m_Makefile->GetDefinition("CMAKE_GENERATOR");
  82. if (genName)
  83. {
  84. std::string gen = genName;
  85. if(gen == "Visual Studio 6")
  86. {
  87. commandArgs.push_back("--gccxml-compiler");
  88. commandArgs.push_back("msvc6");
  89. tmp = "${CMAKE_CXX_FLAGS}";
  90. m_Makefile->ExpandVariablesInString(tmp);
  91. commandArgs.push_back("--gccxml-cxxflags");
  92. commandArgs.push_back(tmp);
  93. }
  94. else if(gen == "Visual Studio 7")
  95. {
  96. commandArgs.push_back("--gccxml-compiler");
  97. commandArgs.push_back("msvc7");
  98. tmp = "${CMAKE_CXX_FLAGS}";
  99. m_Makefile->ExpandVariablesInString(tmp);
  100. commandArgs.push_back("--gccxml-cxxflags");
  101. commandArgs.push_back(tmp);
  102. }
  103. else if(gen == "NMake Makefiles")
  104. {
  105. tmp = "${CMAKE_CXX_COMPILER}";
  106. m_Makefile->ExpandVariablesInString(tmp);
  107. commandArgs.push_back("--gccxml-compiler");
  108. commandArgs.push_back(tmp);
  109. tmp = "${CMAKE_CXX_FLAGS}";
  110. m_Makefile->ExpandVariablesInString(tmp);
  111. commandArgs.push_back("--gccxml-cxxflags");
  112. commandArgs.push_back(tmp);
  113. }
  114. }
  115. #endif
  116. const char* gccxml = m_Makefile->GetDefinition("ITK_GCCXML_EXECUTABLE");
  117. if(gccxml)
  118. {
  119. commandArgs.push_back("--gccxml");
  120. commandArgs.push_back(gccxml);
  121. }
  122. tmp = "-I";
  123. tmp += m_Makefile->GetStartDirectory();
  124. commandArgs.push_back(tmp);
  125. const std::vector<std::string>& includes =
  126. m_Makefile->GetIncludeDirectories();
  127. for(std::vector<std::string>::const_iterator i = includes.begin();
  128. i != includes.end(); ++i)
  129. {
  130. tmp = "-I";
  131. tmp += i->c_str();
  132. m_Makefile->ExpandVariablesInString(tmp);
  133. commandArgs.push_back(tmp);
  134. }
  135. // Get the dependencies.
  136. const cmDependInformation* info =
  137. m_MakeDepend->FindDependencies(inFile.c_str());
  138. if (info)
  139. {
  140. for(cmDependInformation::DependencySet::const_iterator d =
  141. info->m_DependencySet.begin();
  142. d != info->m_DependencySet.end(); ++d)
  143. {
  144. // Make sure the full path is given. If not, the dependency was
  145. // not found.
  146. if((*d)->m_FullPath != "")
  147. {
  148. depends.push_back((*d)->m_FullPath);
  149. }
  150. }
  151. }
  152. std::vector<std::string> outputs;
  153. outputs.push_back(outDir+"/"+tclFile+".cxx");
  154. m_Makefile->AddCustomCommand(inFile.c_str(),
  155. command.c_str(),
  156. commandArgs, depends,
  157. outputs, m_TargetName.c_str());
  158. // Add the source to the makefile.
  159. cmSourceFile file;
  160. file.SetName(tclFile.c_str(), outDir.c_str(), "cxx", false);
  161. // Set dependency hints.
  162. file.GetDepends().push_back(inFile.c_str());
  163. file.GetDepends().push_back("CableTclFacility/ctCalls.h");
  164. m_Makefile->AddSource(file);
  165. // Add the generated source to the package's source list.
  166. std::string srcname = file.GetSourceName() + ".cxx";
  167. m_Target->GetSourceLists().push_back(srcname);
  168. return true;
  169. }
  170. /**
  171. * Get the "CABLE" cache entry value. If there is no cache entry for CABLE,
  172. * one will be created and initialized to NOTFOUND.
  173. */
  174. std::string cmITKWrapTclCommand::GetCableFromCache() const
  175. {
  176. const char* cable =
  177. m_Makefile->GetDefinition("CABLE");
  178. if(cable)
  179. { return cable; }
  180. m_Makefile->AddCacheDefinition("CABLE",
  181. "NOTFOUND",
  182. "Path to CABLE executable.",
  183. cmCacheManager::FILEPATH);
  184. return "NOTFOUND";
  185. }