cmVTKWrapJavaCommand.cxx 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. cmSystemTools::ExpandListArguments(argsIn, args);
  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. cmMakefile::SourceMap &Classes = m_Makefile->GetSources();
  37. for(std::vector<std::string>::const_iterator j = (args.begin() + 2);
  38. j != args.end(); ++j)
  39. {
  40. cmMakefile::SourceMap::iterator l = Classes.find(*j);
  41. if (l == Classes.end())
  42. {
  43. this->SetError("bad source list passed to VTKWrapJavaCommand");
  44. return false;
  45. }
  46. for(std::vector<cmSourceFile*>::iterator i = l->second.begin();
  47. i != l->second.end(); i++)
  48. {
  49. cmSourceFile &curr = *(*i);
  50. // if we should wrap the class
  51. if (!curr.GetWrapExclude())
  52. {
  53. cmSourceFile file;
  54. file.SetIsAnAbstractClass(curr.IsAnAbstractClass());
  55. std::string newName = curr.GetSourceName() + "Java";
  56. file.SetName(newName.c_str(), m_Makefile->GetCurrentOutputDirectory(),
  57. "cxx",false);
  58. std::string hname = cdir + "/" + curr.GetSourceName() + ".h";
  59. m_WrapHeaders.push_back(hname);
  60. // add starting depends
  61. file.GetDepends().push_back(hname);
  62. m_WrapClasses.push_back(file);
  63. m_OriginalNames.push_back(curr.GetSourceName());
  64. }
  65. }
  66. }
  67. return true;
  68. }
  69. void cmVTKWrapJavaCommand::FinalPass()
  70. {
  71. // first we add the rules for all the .h to Java.cxx files
  72. size_t lastClass = m_WrapClasses.size();
  73. std::vector<std::string> depends;
  74. std::vector<std::string> depends2;
  75. std::vector<std::string> alldepends;
  76. std::vector<std::string> empty;
  77. std::string wjava = "${VTK_WRAP_JAVA_EXE}";
  78. std::string pjava = "${VTK_PARSE_JAVA_EXE}";
  79. std::string hints = "${VTK_WRAP_HINTS}";
  80. std::string resultDirectory = "${VTK_JAVA_HOME}";
  81. m_Makefile->ExpandVariablesInString(hints);
  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],m_SourceList.c_str());
  93. // wrap java
  94. std::string res = m_Makefile->GetCurrentOutputDirectory();
  95. res += "/";
  96. res += m_WrapClasses[classNum].GetSourceName() + ".cxx";
  97. std::string res2 = resultDirectory + "/" +
  98. m_OriginalNames[classNum] + ".java";
  99. std::vector<std::string> args;
  100. args.push_back(m_WrapHeaders[classNum]);
  101. if (strcmp("${VTK_WRAP_HINTS}",hints.c_str()))
  102. {
  103. args.push_back(hints);
  104. }
  105. args.push_back((m_WrapClasses[classNum].IsAnAbstractClass() ? "0" : "1"));
  106. args.push_back(res);
  107. m_Makefile->AddCustomCommand(m_WrapHeaders[classNum].c_str(),
  108. wjava.c_str(), args, depends,
  109. res.c_str(), m_LibraryName.c_str());
  110. std::vector<std::string> args2;
  111. args2.push_back(m_WrapHeaders[classNum]);
  112. if (strcmp("${VTK_WRAP_HINTS}",hints.c_str()))
  113. {
  114. args2.push_back(hints);
  115. }
  116. args2.push_back((m_WrapClasses[classNum].IsAnAbstractClass() ? "0" : "1"));
  117. args2.push_back(res2);
  118. m_Makefile->AddCustomCommand(m_WrapHeaders[classNum].c_str(),
  119. pjava.c_str(), args2, depends2,
  120. res2.c_str(), m_LibraryName.c_str());
  121. alldepends.push_back(res2);
  122. }
  123. m_Makefile->AddUtilityCommand((m_LibraryName+"JavaClasses").c_str(),
  124. "",
  125. "",
  126. true,
  127. alldepends,
  128. empty);
  129. }