cmVTKWrapJavaCommand.cxx 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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 "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. this->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(!this->Makefile->IsOn("VTK_WRAP_JAVA"))
  27. {
  28. return true;
  29. }
  30. // what is the current source dir
  31. std::string cdir = this->Makefile->GetCurrentDirectory();
  32. // keep the library name
  33. this->LibraryName = args[0];
  34. this->SourceList = args[1];
  35. std::string sourceListValue;
  36. // was the list already populated
  37. const char *def = this->Makefile->GetDefinition(this->SourceList.c_str());
  38. if (def)
  39. {
  40. sourceListValue = def;
  41. }
  42. // Prepare java dependency file
  43. const char* resultDirectory =
  44. this->Makefile->GetRequiredDefinition("VTK_JAVA_HOME");
  45. std::string res = this->Makefile->GetCurrentOutputDirectory();
  46. std::string depFileName = res + "/JavaDependencies.cmake";
  47. std::ofstream depFile(depFileName.c_str());
  48. depFile << "# This file is automatically generated by CMake VTK_WRAP_JAVA"
  49. << std::endl << std::endl;
  50. depFile <<
  51. "SET(VTK_JAVA_DEPENDENCIES ${VTK_JAVA_DEPENDENCIES}" << std::endl;
  52. // get the list of classes for this library
  53. for(std::vector<std::string>::const_iterator j = (args.begin() + 2);
  54. j != args.end(); ++j)
  55. {
  56. cmSourceFile *curr = this->Makefile->GetSource(j->c_str());
  57. // if we should wrap the class
  58. if (!curr || !curr->GetPropertyAsBool("WRAP_EXCLUDE"))
  59. {
  60. cmSourceFile file;
  61. if (curr)
  62. {
  63. file.SetProperty("ABSTRACT",curr->GetProperty("ABSTRACT"));
  64. }
  65. std::string srcName = cmSystemTools::GetFilenameWithoutExtension(*j);
  66. std::string newName = srcName + "Java";
  67. file.SetName(newName.c_str(),
  68. this->Makefile->GetCurrentOutputDirectory(), "cxx",false);
  69. std::string hname = cdir + "/" + srcName + ".h";
  70. this->WrapHeaders.push_back(hname);
  71. // add starting depends
  72. file.GetDepends().push_back(hname);
  73. this->WrapClasses.push_back(file);
  74. this->OriginalNames.push_back(srcName);
  75. if (sourceListValue.size() > 0)
  76. {
  77. sourceListValue += ";";
  78. }
  79. sourceListValue += newName + ".cxx";
  80. // Write file to java dependency file
  81. std::string jafaFile = resultDirectory;
  82. jafaFile += "/";
  83. jafaFile += srcName;
  84. jafaFile += ".java";
  85. depFile << " " << jafaFile << std::endl;
  86. }
  87. }
  88. // Finalize java dependency file
  89. depFile << ")" << std::endl;
  90. this->Makefile->AddDefinition(this->SourceList.c_str(),
  91. sourceListValue.c_str());
  92. return true;
  93. }
  94. void cmVTKWrapJavaCommand::FinalPass()
  95. {
  96. // first we add the rules for all the .h to Java.cxx files
  97. size_t lastClass = this->WrapClasses.size();
  98. std::vector<std::string> depends;
  99. std::vector<std::string> depends2;
  100. std::vector<std::string> alldepends;
  101. const char* wjava =
  102. this->Makefile->GetRequiredDefinition("VTK_WRAP_JAVA_EXE");
  103. const char* pjava =
  104. this->Makefile->GetRequiredDefinition("VTK_PARSE_JAVA_EXE");
  105. const char* hints = this->Makefile->GetDefinition("VTK_WRAP_HINTS");
  106. const char* resultDirectory =
  107. this->Makefile->GetRequiredDefinition("VTK_JAVA_HOME");
  108. // wrap all the .h files
  109. depends.push_back(wjava);
  110. depends2.push_back(pjava);
  111. if(hints)
  112. {
  113. depends.push_back(hints);
  114. depends2.push_back(hints);
  115. }
  116. for(size_t classNum = 0; classNum < lastClass; classNum++)
  117. {
  118. this->Makefile->AddSource(this->WrapClasses[classNum]);
  119. // wrap java
  120. std::string res = this->Makefile->GetCurrentOutputDirectory();
  121. res += "/";
  122. res += this->WrapClasses[classNum].GetSourceName() + ".cxx";
  123. std::string res2 = resultDirectory;
  124. res2 += "/";
  125. res2 += this->OriginalNames[classNum];
  126. res2 += ".java";
  127. cmCustomCommandLine commandLineW;
  128. commandLineW.push_back(wjava);
  129. commandLineW.push_back(this->WrapHeaders[classNum]);
  130. if(hints)
  131. {
  132. commandLineW.push_back(hints);
  133. }
  134. commandLineW.push_back((this->WrapClasses[classNum].
  135. GetPropertyAsBool("ABSTRACT") ? "0" : "1"));
  136. commandLineW.push_back(res);
  137. cmCustomCommandLines commandLines;
  138. commandLines.push_back(commandLineW);
  139. std::vector<std::string> outputs;
  140. outputs.push_back(res);
  141. const char* no_comment = 0;
  142. this->Makefile->AddCustomCommandOldStyle(this->LibraryName.c_str(),
  143. outputs,
  144. depends,
  145. this->WrapHeaders[classNum].c_str(),
  146. commandLines,
  147. no_comment);
  148. cmCustomCommandLine commandLineP;
  149. commandLineP.push_back(pjava);
  150. commandLineP.push_back(this->WrapHeaders[classNum]);
  151. if(hints)
  152. {
  153. commandLineP.push_back(hints);
  154. }
  155. commandLineP.push_back((this->WrapClasses[classNum].
  156. GetPropertyAsBool("ABSTRACT") ? "0" : "1"));
  157. commandLineP.push_back(res2);
  158. cmCustomCommandLines commandLines2;
  159. commandLines2.push_back(commandLineP);
  160. std::vector<std::string> outputs2;
  161. outputs2.push_back(res2);
  162. this->Makefile->AddCustomCommandOldStyle(this->LibraryName.c_str(),
  163. outputs2,
  164. depends2,
  165. this->WrapHeaders[classNum].c_str(),
  166. commandLines2,
  167. no_comment);
  168. alldepends.push_back(res2);
  169. }
  170. const char* no_output = 0;
  171. const char* no_working_directory = 0;
  172. this->Makefile->AddUtilityCommand((this->LibraryName+"JavaClasses").c_str(),
  173. true, no_output,
  174. alldepends, no_working_directory, "");
  175. }