cmVTKWrapJavaCommand.cxx 6.5 KB

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