cmVTKWrapJavaCommand.cxx 5.0 KB

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