cmVTKWrapJavaCommand.cxx 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. // get the list of classes for this library
  36. for(std::vector<std::string>::const_iterator j = (args.begin() + 2);
  37. j != args.end(); ++j)
  38. {
  39. cmSourceFile *curr = m_Makefile->GetSource(j->c_str());
  40. // if we should wrap the class
  41. if (!curr || !curr->GetWrapExclude())
  42. {
  43. cmSourceFile file;
  44. if (curr)
  45. {
  46. file.SetIsAnAbstractClass(curr->IsAnAbstractClass());
  47. }
  48. std::string srcName = cmSystemTools::GetFilenameWithoutExtension(*j);
  49. std::string newName = srcName + "Java";
  50. file.SetName(newName.c_str(), m_Makefile->GetCurrentOutputDirectory(),
  51. "cxx",false);
  52. std::string hname = cdir + "/" + srcName + ".h";
  53. m_WrapHeaders.push_back(hname);
  54. // add starting depends
  55. file.GetDepends().push_back(hname);
  56. m_WrapClasses.push_back(file);
  57. m_OriginalNames.push_back(srcName);
  58. }
  59. }
  60. return true;
  61. }
  62. void cmVTKWrapJavaCommand::FinalPass()
  63. {
  64. // first we add the rules for all the .h to Java.cxx files
  65. size_t lastClass = m_WrapClasses.size();
  66. std::vector<std::string> depends;
  67. std::vector<std::string> depends2;
  68. std::vector<std::string> alldepends;
  69. std::vector<std::string> empty;
  70. std::string wjava = "${VTK_WRAP_JAVA_EXE}";
  71. std::string pjava = "${VTK_PARSE_JAVA_EXE}";
  72. std::string hints = "${VTK_WRAP_HINTS}";
  73. std::string resultDirectory = "${VTK_JAVA_HOME}";
  74. std::string sourceListValue;
  75. m_Makefile->ExpandVariablesInString(hints);
  76. // was the list already populated
  77. const char *def = m_Makefile->GetDefinition(m_SourceList.c_str());
  78. if (def)
  79. {
  80. sourceListValue = def;
  81. }
  82. // wrap all the .h files
  83. depends.push_back(wjava);
  84. depends2.push_back(pjava);
  85. if (strcmp("${VTK_WRAP_HINTS}",hints.c_str()))
  86. {
  87. depends.push_back(hints);
  88. depends2.push_back(hints);
  89. }
  90. for(size_t classNum = 0; classNum < lastClass; classNum++)
  91. {
  92. m_Makefile->AddSource(m_WrapClasses[classNum]);
  93. if (sourceListValue.size() > 0)
  94. {
  95. sourceListValue += ";";
  96. }
  97. sourceListValue += m_WrapClasses[classNum].GetSourceName() + ".cxx";
  98. // wrap java
  99. std::string res = m_Makefile->GetCurrentOutputDirectory();
  100. res += "/";
  101. res += m_WrapClasses[classNum].GetSourceName() + ".cxx";
  102. std::string res2 = resultDirectory + "/" +
  103. m_OriginalNames[classNum] + ".java";
  104. std::vector<std::string> args;
  105. args.push_back(m_WrapHeaders[classNum]);
  106. if (strcmp("${VTK_WRAP_HINTS}",hints.c_str()))
  107. {
  108. args.push_back(hints);
  109. }
  110. args.push_back((m_WrapClasses[classNum].IsAnAbstractClass() ? "0" : "1"));
  111. args.push_back(res);
  112. m_Makefile->AddCustomCommand(m_WrapHeaders[classNum].c_str(),
  113. wjava.c_str(), args, depends,
  114. res.c_str(), m_LibraryName.c_str());
  115. std::vector<std::string> args2;
  116. args2.push_back(m_WrapHeaders[classNum]);
  117. if (strcmp("${VTK_WRAP_HINTS}",hints.c_str()))
  118. {
  119. args2.push_back(hints);
  120. }
  121. args2.push_back((m_WrapClasses[classNum].IsAnAbstractClass() ? "0" : "1"));
  122. args2.push_back(res2);
  123. m_Makefile->AddCustomCommand(m_WrapHeaders[classNum].c_str(),
  124. pjava.c_str(), args2, depends2,
  125. res2.c_str(), m_LibraryName.c_str());
  126. alldepends.push_back(res2);
  127. }
  128. m_Makefile->AddUtilityCommand((m_LibraryName+"JavaClasses").c_str(),
  129. "",
  130. "",
  131. true,
  132. alldepends,
  133. empty);
  134. m_Makefile->AddDefinition(m_SourceList.c_str(), sourceListValue.c_str());
  135. }