cmVTKWrapJavaCommand.cxx 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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. 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. // Prepare java dependency file
  43. const char* resultDirectory =
  44. m_Makefile->GetRequiredDefinition("VTK_JAVA_HOME");
  45. std::string res = m_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 = m_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(), m_Makefile->GetCurrentOutputDirectory(),
  67. "cxx",false);
  68. std::string hname = cdir + "/" + srcName + ".h";
  69. m_WrapHeaders.push_back(hname);
  70. // add starting depends
  71. file.GetDepends().push_back(hname);
  72. m_WrapClasses.push_back(file);
  73. m_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. m_Makefile->AddDefinition(m_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 = m_WrapClasses.size();
  96. std::vector<std::string> depends;
  97. std::vector<std::string> depends2;
  98. std::vector<std::string> alldepends;
  99. const char* wjava = m_Makefile->GetRequiredDefinition("VTK_WRAP_JAVA_EXE");
  100. const char* pjava = m_Makefile->GetRequiredDefinition("VTK_PARSE_JAVA_EXE");
  101. const char* hints = m_Makefile->GetDefinition("VTK_WRAP_HINTS");
  102. const char* resultDirectory =
  103. m_Makefile->GetRequiredDefinition("VTK_JAVA_HOME");
  104. // wrap all the .h files
  105. depends.push_back(wjava);
  106. depends2.push_back(pjava);
  107. if(hints)
  108. {
  109. depends.push_back(hints);
  110. depends2.push_back(hints);
  111. }
  112. for(size_t classNum = 0; classNum < lastClass; classNum++)
  113. {
  114. m_Makefile->AddSource(m_WrapClasses[classNum]);
  115. // wrap java
  116. std::string res = m_Makefile->GetCurrentOutputDirectory();
  117. res += "/";
  118. res += m_WrapClasses[classNum].GetSourceName() + ".cxx";
  119. std::string res2 = resultDirectory;
  120. res2 += "/";
  121. res2 += m_OriginalNames[classNum];
  122. res2 += ".java";
  123. cmCustomCommandLine commandLineW;
  124. commandLineW.push_back(wjava);
  125. commandLineW.push_back(m_WrapHeaders[classNum]);
  126. if(hints)
  127. {
  128. commandLineW.push_back(hints);
  129. }
  130. commandLineW.push_back(
  131. (m_WrapClasses[classNum].GetPropertyAsBool("ABSTRACT") ? "0" : "1"));
  132. commandLineW.push_back(res);
  133. cmCustomCommandLines commandLines;
  134. commandLines.push_back(commandLineW);
  135. std::vector<std::string> outputs;
  136. outputs.push_back(res);
  137. const char* no_comment = 0;
  138. m_Makefile->AddCustomCommandOldStyle(m_LibraryName.c_str(),
  139. outputs,
  140. depends,
  141. m_WrapHeaders[classNum].c_str(),
  142. commandLines,
  143. no_comment);
  144. cmCustomCommandLine commandLineP;
  145. commandLineP.push_back(pjava);
  146. commandLineP.push_back(m_WrapHeaders[classNum]);
  147. if(hints)
  148. {
  149. commandLineP.push_back(hints);
  150. }
  151. commandLineP.push_back(
  152. (m_WrapClasses[classNum].GetPropertyAsBool("ABSTRACT") ? "0" : "1"));
  153. commandLineP.push_back(res2);
  154. cmCustomCommandLines commandLines2;
  155. commandLines2.push_back(commandLineP);
  156. std::vector<std::string> outputs2;
  157. outputs2.push_back(res2);
  158. m_Makefile->AddCustomCommandOldStyle(m_LibraryName.c_str(),
  159. outputs2,
  160. depends2,
  161. m_WrapHeaders[classNum].c_str(),
  162. commandLines2,
  163. no_comment);
  164. alldepends.push_back(res2);
  165. }
  166. const char* no_output = 0;
  167. const char* no_working_directory = 0;
  168. m_Makefile->AddUtilityCommand((m_LibraryName+"JavaClasses").c_str(),
  169. true, no_output,
  170. alldepends, no_working_directory, "");
  171. }