cmVTKWrapJavaCommand.cxx 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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 "cmVTKWrapJavaCommand.h"
  14. // cmVTKWrapJavaCommand
  15. bool cmVTKWrapJavaCommand::InitialPass(std::vector<std::string> const& args)
  16. {
  17. if(args.size() < 3 )
  18. {
  19. this->SetError("called with incorrect number of arguments");
  20. return false;
  21. }
  22. // Now check and see if the value has been stored in the cache
  23. // already, if so use that value and don't look for the program
  24. if(!m_Makefile->IsOn("VTK_WRAP_JAVA"))
  25. {
  26. return true;
  27. }
  28. // what is the current source dir
  29. std::string cdir = m_Makefile->GetCurrentDirectory();
  30. // keep the library name
  31. m_LibraryName = args[0];
  32. m_SourceList = args[1];
  33. // get the list of classes for this library
  34. cmMakefile::SourceMap &Classes = m_Makefile->GetSources();
  35. for(std::vector<std::string>::const_iterator j = (args.begin() + 2);
  36. j != args.end(); ++j)
  37. {
  38. cmMakefile::SourceMap::iterator l = Classes.find(*j);
  39. if (l == Classes.end())
  40. {
  41. this->SetError("bad source list passed to VTKWrapJavaCommand");
  42. return false;
  43. }
  44. for(std::vector<cmSourceFile>::iterator i = l->second.begin();
  45. i != l->second.end(); i++)
  46. {
  47. cmSourceFile &curr = *i;
  48. // if we should wrap the class
  49. if (!curr.GetWrapExclude())
  50. {
  51. cmSourceFile file;
  52. file.SetIsAnAbstractClass(curr.IsAnAbstractClass());
  53. std::string newName = curr.GetSourceName() + "Java";
  54. file.SetName(newName.c_str(), m_Makefile->GetCurrentOutputDirectory(),
  55. "cxx",false);
  56. std::string hname = cdir + "/" + curr.GetSourceName() + ".h";
  57. m_WrapHeaders.push_back(hname);
  58. // add starting depends
  59. file.GetDepends().push_back(hname);
  60. m_WrapClasses.push_back(file);
  61. m_OriginalNames.push_back(curr.GetSourceName());
  62. }
  63. }
  64. }
  65. return true;
  66. }
  67. void cmVTKWrapJavaCommand::FinalPass()
  68. {
  69. // first we add the rules for all the .h to Java.cxx files
  70. size_t lastClass = m_WrapClasses.size();
  71. std::vector<std::string> depends;
  72. std::vector<std::string> depends2;
  73. std::vector<std::string> alldepends;
  74. std::vector<std::string> empty;
  75. std::string wjava = "${VTK_WRAP_JAVA_EXE}";
  76. std::string pjava = "${VTK_PARSE_JAVA_EXE}";
  77. std::string hints = "${VTK_WRAP_HINTS}";
  78. std::string resultDirectory = "${VTK_JAVA_HOME}";
  79. m_Makefile->ExpandVariablesInString(hints);
  80. // wrap all the .h files
  81. depends.push_back(wjava);
  82. depends2.push_back(pjava);
  83. if (strcmp("${VTK_WRAP_HINTS}",hints.c_str()))
  84. {
  85. depends.push_back(hints);
  86. depends2.push_back(hints);
  87. }
  88. for(size_t classNum = 0; classNum < lastClass; classNum++)
  89. {
  90. m_Makefile->AddSource(m_WrapClasses[classNum],m_SourceList.c_str());
  91. // wrap java
  92. std::string res = m_Makefile->GetCurrentOutputDirectory();
  93. res += "/";
  94. res += m_WrapClasses[classNum].GetSourceName() + ".cxx";
  95. std::string res2 = resultDirectory + "/" +
  96. m_OriginalNames[classNum] + ".java";
  97. std::vector<std::string> args;
  98. args.push_back(m_WrapHeaders[classNum]);
  99. if (strcmp("${VTK_WRAP_HINTS}",hints.c_str()))
  100. {
  101. args.push_back(hints);
  102. }
  103. args.push_back((m_WrapClasses[classNum].IsAnAbstractClass() ? "0" : "1"));
  104. args.push_back(res);
  105. m_Makefile->AddCustomCommand(m_WrapHeaders[classNum].c_str(),
  106. wjava.c_str(), args, depends,
  107. res.c_str(), m_LibraryName.c_str());
  108. std::vector<std::string> args2;
  109. args2.push_back(m_WrapHeaders[classNum]);
  110. if (strcmp("${VTK_WRAP_HINTS}",hints.c_str()))
  111. {
  112. args2.push_back(hints);
  113. }
  114. args2.push_back((m_WrapClasses[classNum].IsAnAbstractClass() ? "0" : "1"));
  115. args2.push_back(res2);
  116. m_Makefile->AddCustomCommand(m_WrapHeaders[classNum].c_str(),
  117. pjava.c_str(), args2, depends2,
  118. res2.c_str(), m_LibraryName.c_str());
  119. alldepends.push_back(res2);
  120. }
  121. m_Makefile->AddUtilityCommand((m_LibraryName+"JavaClasses").c_str(),
  122. "",
  123. "",
  124. true,
  125. alldepends,
  126. empty);
  127. }