cmVTKWrapJavaCommand.cxx 6.7 KB

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